I have post-merge
hook that check a few things after a merge/pull.
However, these check are unnecessary after a fast-forward merge and they just wasting several seconds for no good reason.
This is rather annoying.
How can I detect that the post-merge
script was called for a fast-forward merge, in order to skip it?
According to the documentation the only parameter passed to the script informs whether it was a squash merge. I don't see anything about fast-forwarding there.
(Someone will probably point out that post-merge
is not the best place to put checks because it it too late to stop the merge. I know that but specifics of my project cause that running them earlier is not possible.)
CodePudding user response:
I thought just counting parents would do it, but OP pointed out that fast-forwarding to an existing merge would fail that test.
So:
if [[ `git reflog -1` = *Fast-forward ]]
then this is a fast-forward
fi