Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git submodule commit hooks

I'm using a git submodule (let's call it SubmoduleRepo) so that I can include my module in couple of projects.

I can commit to SubmoduleRepo from any project that uses it.

I can update, commit and push to SubmoduleRepo pretty hassle-free.

I need to execute a commit hook whenever I commit something while working in a directory in a project that contains the SubmoduleRepo (when I work in SubmoduleRepo, the commit hook executes as expected)

There is no .git folder in submodule's dir (only .git file that specifies path to current directory).

like image 961
Mladen Avatar asked Jun 01 '12 09:06

Mladen


People also ask

Can you commit to submodule?

You can also change the commit that is checked out in each submodule by performing a checkout in the submodule repository and then committing the change in the parent repository. You add a submodule to a Git repository via the git submodule add command.

Are git hooks committed?

It's important to note that Git hooks aren't committed to a Git repository themselves. They're local, untracked files. When you write an important hook that you want to keep around, copy it into a directory managed by Git! Git hooks are an important aspect of Git that is too often forgotten for being hidden away.

What are Git Pre-commit hooks?

The pre-commit hook is run first, before you even type in a commit message. It's used to inspect the snapshot that's about to be committed, to see if you've forgotten something, to make sure tests run, or to examine whatever you need to inspect in the code.

Can a submodule point to a branch?

You can set the submodule to track a particular branch (requires git 1.8. 2+), which is what we are doing with Komodo, or you can reference a particular repository commit (the later requires updating the main repository whenever you want to pull in new changes from the module – i.e. updating the commit hash reference).


2 Answers

If you have Git 2.10+ you can get the hooks directory by running:

`git rev-parse --git-path hooks` 

Note: by default it is .git/hooks but if you are in a submodule it will be different.

Pre Git 2.10+ you would want something like:

`git rev-parse --git-dir`/hooks 

More info at: Find path to git hooks directory on the shell

like image 142
Jason Axelson Avatar answered Oct 12 '22 11:10

Jason Axelson


I've found solution couple of moments after posting this...

You can put hooks in .git/modules//hooks/ - eg. .git/modules/web/js/modules/rate if your submodule is located in /web/js/modules/rate directory.

like image 38
Mladen Avatar answered Oct 12 '22 13:10

Mladen