#!/bin/sh -eu set -eu server=git.ws.local check_commit() { commit=$1 # Check the email email="`git log $commit -1 --pretty=format:%ae`" case "$email" in *localhost.localdomain|*\(none\)) cat <&2 --- The commits you are trying to push contain the author email address '$email'. Please configure your name and email address. --- EOF exit 1 ;; esac subj="`git log $commit -1 --pretty=format:%s`" case "$subj" in *XXXXMerge\ branch*of*[gs][is][th]\:*) cat <&2 --- The commit: EOF git log $commit -1 >&2 cat <&2 Looks like it was produced by typing 'git pull' without the --rebase option when you had local changes. Running 'git pull --rebase' now will fix the problem. Then please try, 'git push' again. --- EOF exit 1 ;; esac } check_ref_update() { oldrev=$1 newrev=$2 refname=$3 change_type=update if expr $oldrev : "^0\+$" > /dev/null 2>&1; then change_type=create fi if expr $newrev : "^0\+$" > /dev/null 2>&1; then if [ x$change_type = xcreate ] ; then # Deleting an invalid ref, allow return 0 fi change_type=delete fi case $refname in refs/heads/*) range= case $change_type in create) range="$newrev" ;; update) range="$oldrev..$newrev" ;; esac if [ -n "$range" ]; then for merged in `git rev-parse --symbolic-full-name \ --not --branches | egrep -v "^/^$refname$" | \ git rev-list --reverse --stdin "$range"`; do check_commit $merged done fi ;; refs/tags/*) ;; # Remote tracking branch refs/remotes/*) cat <&2 --- You are trying to push the remote tracking branch: $refname to $server --- EOF exit 1 ;; # Something completely different *) cat <&2 --- You are trying to push the ref: $refname to $server. This isn't a branch or tag. --- EOF exit 1 ;; esac return 0 } if [ $# = 3 ] ; then check_ref_update $@ else echo "usage: check-rev-policy oldrev newrev refname" >&2 exit 2 fi exit 0