Created
April 14, 2014 12:28
-
-
Save lhotari/10643365 to your computer and use it in GitHub Desktop.
git pre-push hook script to prevent unintentional force pushs
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 | |
remote="$1" | |
url="$2" | |
z40=0000000000000000000000000000000000000000 | |
IFS=' ' | |
while read local_ref local_sha remote_ref remote_sha | |
do | |
if [ "$local_sha" = $z40 ] | |
then | |
echo "Delete of $remote $remote_ref forbidden. Pass --no-verify to ignore check." | |
exit 1 | |
else | |
if [ "$remote_sha" != $z40 ] | |
then | |
base=`git merge-base $remote_sha $local_sha` | |
if [[ "${base}" != "${remote_sha}" ]]; then | |
echo "Force update of $remote $remote_ref forbidden. Pass --no-verify to ignore check." | |
exit 1 | |
fi | |
fi | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment