0

I would like to implement a custom check which has the option to abort a merge before it's begun, preventing git merge from touching the working tree or repository in any way. The pre-merge-commit hook runs too late for this; the man page entry says:

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

I couldn't see any other hook or config parameter usable for this. prepare-commit-msg doesn't even get run when I do a test of git merge. It feels like there should be a pre-merge hook which runs at the very beginning of the merge process.

Can anyone suggest a solution or workaround? I guess I could write a git-merge wrapper which performs the check before invoking the real git-merge, and then alter $PATH to find that only when I want this check active. But that feels pretty ugly, and I'm not even sure it would work. EDIT: it doesn't work, because git doesn't allow aliasing of built-in subcommands, as explained in Is it possible to override git command by git alias?

Adam Spiers
  • 17,397
  • 5
  • 46
  • 65
  • 2
    Looking at [the code](https://github.com/git/git/blob/9748a6820043d5815bee770ffa51647e0adc2cf0/builtin/merge.c#L864), there's no call to any function that runs hooks (there are multiple versions) in any of the functions that run earlier in the merge process. Might be worth asking on the mailing list if a change request would be welcome. – Zac Anger Jul 01 '23 at 18:56

0 Answers0