Skip to content

Instantly share code, notes, and snippets.

@ptsneves
Created August 12, 2018 19:23
Show Gist options
  • Save ptsneves/4d807d84c1c96b620bf5a80bd21b9847 to your computer and use it in GitHub Desktop.
Save ptsneves/4d807d84c1c96b620bf5a80bd21b9847 to your computer and use it in GitHub Desktop.
pre-receive hook
#!/bin/bash -e
# <oldrev> <newrev> <refname>
#Adapted from
#https://github.com/olshanov/git-hooks/blob/master/pre-receive.deny-force-push-to-branches
while read oldrev newrev ref
do
if [[ "$oldrev" == "0000000000000000000000000000000000000000" ]]; then
#create new branch
continue;
fi
base=`git merge-base $oldrev $newrev`
if [[ "${base}" != "${oldrev}" ]]; then
#non fast-forward, mean force
new_tag="FORCEPUSH-FROM-${oldrev}-TO-${newrev}"
echo "Force update of $ref means a $new_tag tag will be created."
#GIT_QUARANTINE_PATH is unset so that git does not complain of changing refs
#when in a pre-receive hook. It is unlikely we fail here.
env -u GIT_QUARANTINE_PATH git tag $new_tag
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment