Last active
December 23, 2019 14:58
-
-
Save refactorsaurusrex/2259e14c981e2b353df1f8b6066769dc to your computer and use it in GitHub Desktop.
git 'prepare commit msg' hook that rejects merge commits when the source branch is behind the target branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ "$2" = "merge" ]; then | |
githead=$(env | grep GITHEAD) | |
source="${githead##*=}" | |
target=$(git symbolic-ref HEAD) | |
behind=$(git rev-list --left-only --count $target...$source) | |
if [ $behind -gt 0 ]; then | |
echo "Aborting: The source branch is $behind commits behind the target branch." | |
exit 1 | |
fi | |
fi | |
#ref https://superuser.com/a/926038/51794 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment