Last active
December 22, 2015 11:09
-
-
Save ctrochalakis/6463969 to your computer and use it in GitHub Desktop.
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/bash | |
# | |
# Reject non-fastforward updates per branch | |
# Place it at hooks/update and make it executable | |
ref=$1 | |
old=$2 | |
new=$3 | |
# Debug | |
#echo $@ | |
# Only valid for master branch | |
[ $ref != "refs/heads/master" ] && exit 0 | |
# First commit, skip fast | |
[ $old = "0000000000000000000000000000000000000000" ] && exit 0 | |
# Delete operation, skip fast | |
[ $new = "0000000000000000000000000000000000000000" ] && echo "Delete master? Noop!" && exit 1 | |
# Commits that are in old and not in new (non-fastforward) | |
missing=$(git rev-list "$old" ^"$new" |wc -l) | |
# Everything is ok, proceed | |
[ $missing -eq 0 ] && exit 0 | |
echo | |
echo "[skroutz:git] Can't proceed with the push, non-fastforwared updates for $ref are prohibited ($missing commits would be lost)" | |
echo | |
echo | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment