summaryrefslogtreecommitdiff
path: root/check-rev-policy
diff options
context:
space:
mode:
Diffstat (limited to 'check-rev-policy')
-rwxr-xr-xcheck-rev-policy129
1 files changed, 129 insertions, 0 deletions
diff --git a/check-rev-policy b/check-rev-policy
new file mode 100755
index 0000000..c7f6c4e
--- /dev/null
+++ b/check-rev-policy
@@ -0,0 +1,129 @@
+#!/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 <<EOF >&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
+ *Merge\ branch*of*[gs][is][th]\:*)
+ cat <<EOF >&2
+---
+The commit:
+
+EOF
+ git log $commit -1 >&2
+ cat <<EOF >&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
+ ;;
+
+ ref/tags/*)
+ ;;
+
+ # Remote tracking branch
+ ref/remotes/*)
+ cat <<EOF >&2
+---
+You are trying to push the remote tracking branch:
+
+ $refname
+
+to $server
+---
+EOF
+ exit 1
+ ;;
+
+ # Something completely different
+ *)
+ cat <<EOF >&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
+