I setup some git hooks to run some gulp commands on pre-commit. I basically run jshint/plato. I basically want to bypass these for two c
So I just found a command that I think i can use to detect the "merge_head"
git rev-parse -q --verify MERGE_HEAD
If rev-parse returns a hash that means we are currently in a merge state. I can use that to bypass this logic. But will wait for some better advice from more experienced individuals.
As mentioned in this related answer you could test for the existence of $GIT_DIR/MERGE_HEAD to detect a merge commit:
Here's what you do get:
If you're using
git commit --amendto amend a merge commit, the pre-commit hook is run as usual, but it can't really detect that this is happening. The new commit will be a merge, but you can't tell.If you're using regular old
git committo create a non-merge commit, the fileMERGE_HEADwill not exist in the git directory, and you can tell that this is not going to create a merge commit.If you're using
git committo finish off a conflicted merge, the fileMERGE_HEADwill exist, and you can tell that this is going to create a merge commit.If you're running
git mergeand it succeeds on its own, it makes a new commit without using the pre-commit hook, so you don't even get invoked here.Hence, if you're willing to allow
git commit --amendon merges to misfire, you can get close to what you want: just test for the existence of$GIT_DIR/MERGE_HEADto see if this is agit committhat is finishing off a conflicted merge. (The use of$GIT_DIRis a trick to make this work even if the commands are run outside the git tree. Git sets$GIT_DIRso that in-hook git commands will work right.)