Created
May 31, 2013 17:51
-
-
Save tgr/5686675 to your computer and use it in GitHub Desktop.
git pre-push hook to make sure local commits cannot be pushed
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 | |
# new branch | |
range=$local_sha | |
else | |
range="$remote_sha..$local_sha" | |
fi | |
local_commits=`git rev-list --perl-regexp --grep '^(LOCAL|STASH)\b' "$range"` | |
if [[ -n $local_commits ]]; then | |
echo "Found forbidden commit in $local_ref, aborting" | |
exit 1 | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment