Skip to content

Instantly share code, notes, and snippets.

@tgr
Created May 31, 2013 17:51
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 tgr/5686675 to your computer and use it in GitHub Desktop.
Save tgr/5686675 to your computer and use it in GitHub Desktop.
git pre-push hook to make sure local commits cannot be pushed
#! /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