Search code examples
gitgit-mergegerritgithookscommit-message

git commit-msg hook not triggering when recursive merge occurs on pull


We are using gerrit CI, which requires a commit-msg hook which adds a Change-ID to each commit message.

However, sometimes when pulling we get a recursive merge, this shows up in the reflog like this:

767deb5 HEAD@{0}: pull: Merge made by the 'recursive' strategy.

When this happens, we can't push to our gerrit server, and get the following message:

 ! [remote rejected] HEAD -> refs/for/master ([767deb5] missing Change-Id in commit message footer)

It is resolved easily enough by amending the last commit. But this is tedious, and it's frustrating.

How can we avoid this problem? Why does the recursive merge strategy not trigger the commit-msg hook? How can we make it trigger the hook automatically?


Solution

  • The issue is not related with the recursive merge strategy (I think it was just a coincidence). If you want to learn more about recursive merge strategy take a look at this very good text about it.

    The issue happens because Git commit-msg hook is not executed for merge commits without conflicts. You will find a very good workaround to this at: https://stackoverflow.com/a/24692818/4653675