Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git merge does not trigger pre-merge-commit or post-merge hooks with option --no-commit

Tags:

git

I am currently in the process to add some automation after a user pulls or merge into the current branch (e.g. update user settings, build updated dependencies). I read the hook documentation and found out that pre-merge-commit / post-merge hooks would do that for me. So, the in the use case that we have no merge conflicts, i.e. the merge was successful, both hooks should trigger.

This works fine as long as the merge creates no changes on the working copy (as result of the merge). But if there are changes (e.g. a new file has been added) and I run the git merge command with --no-commit option, both pre-merge-commit and post-merge hooks are NOT executed.

At least with the pre-merge-commit hook I would expect to get the hook fired as the hook is triggered before the commit!

Is this by design? Is there another way to trigger a script after a merge has been successful ignoring the option if I want a commit afterall?

Thanks!

like image 840
Sven Avatar asked Feb 14 '26 11:02

Sven


1 Answers

I agree with you that the documentation is not very clear about when it should be executed, but I think that at least the commit process has to begin. Here is why:

pre-merge-commit [...] is invoked after the merge has been carried out successfully and before obtaining the proposed commit log message to make a commit

First part is clear, merge must be successful. Second part could be misunderstood, but I interpreted in this way:

  1. The commit request has been received
  2. pre-merge-commit runs
  3. commit message is prompted
  4. ...

After all, this hook, in its default implementation runs the pre-commit hook that is in turn called by git commit. Especially this last part has made me think that it is not a bug or anything like that, but a design choice.

like image 75
Marco Luzzara Avatar answered Feb 16 '26 02:02

Marco Luzzara