Created
September 27, 2018 10:31
-
-
Save jan-g/5517d3773967718e0abf7d3790f1d76d to your computer and use it in GitHub Desktop.
pre-push hook
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/sh | |
# This is based on the sample git pre-push hook script. | |
remote="$1" | |
url="$2" | |
z40=0000000000000000000000000000000000000000 | |
while read local_ref local_sha remote_ref remote_sha | |
do | |
if [ "$remote_ref" = "refs/heads/master" -a "$PUSH_MASTER" != yes ] | |
then | |
echo 2>&1 "Not pushing directly onto master - local ref: $local_ref remote: $remote_ref" | |
echo 2>&1 "Set PUSH_MASTER=yes to override" | |
exit 1 | |
fi | |
if [ "$local_sha" = $z40 ] | |
then | |
# Handle delete | |
: | |
else | |
if [ "${PERMIT_WIP:-no}" = "no" ] | |
then | |
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 | |
if ! fgrep -qx "$commit" $(dirname "$0")/pre-push.whitelist | |
then | |
echo >&2 "Found WIP commit in $local_ref, not pushing: $commit" | |
echo >&2 "Set PERMIT_WIP=yes to avoid" | |
exit 1 | |
fi | |
fi | |
fi | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment