Skip to content

Instantly share code, notes, and snippets.

@urouro-net
Created July 20, 2017 03:21
Show Gist options
  • Save urouro-net/811b9d4bdc52049a7bc6a3c7fdae0062 to your computer and use it in GitHub Desktop.
Save urouro-net/811b9d4bdc52049a7bc6a3c7fdae0062 to your computer and use it in GitHub Desktop.
.git/hooks/pre-push
#!/bin/sh
remote="$1"
url="$2"
z40=0000000000000000000000000000000000000000
while read local_ref local_sha remote_ref remote_sha
do
if [ "$local_sha" = $z40 ]
then
# Handle delete
:
else
if [ "$remote_sha" = $z40 ]
then
# New branch, examine all commits
range="$local_sha"
else
# Update to existing branch, examine new commits
range="$remote_sha..$local_sha"
fi
# Check for WIP commit
commit=`git rev-list -n 1 --grep '^WIP' "$range"`
if [ -n "$commit" ]
then
echo >&2 "Found WIP commit in $local_ref, not pushing"
exit 1
fi
fi
done
#
# via https://dev.ghost.org/prevent-master-push/
#
protected_branch='master'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $protected_branch = $current_branch ]
then
read -p "You're about to push master, is that what you intended? [y|n] " -n 1 -r < /dev/tty
echo
if echo $REPLY | grep -E '^[Yy]$' > /dev/null
then
exit 0 # push will execute
fi
exit 1 # push will not execute
else
exit 0 # push will execute
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment