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?