#!/bin/sh

# Check for WIP commit
# -- This block is based upon the git pre-push example --
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 --regexp-ignore-case --grep '^WIP' "$range"`
		if [ -n "$commit" ]; then
			echo  "Found WIP commit in $local_ref, not pushing"
			exit 1
		fi
	fi
done
# -- End code based upon the git pre-push example --

# Disallow pushing code that doesn't pass distTest
make prePush || exit 1
exit 0
