Skip to content

Instantly share code, notes, and snippets.

@ctrochalakis
Last active December 22, 2015 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctrochalakis/6463969 to your computer and use it in GitHub Desktop.
Save ctrochalakis/6463969 to your computer and use it in GitHub Desktop.
#!/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