From 783ff95ab8c2ccc42901200bdc25a426377a3886 Mon Sep 17 00:00:00 2001 From: Charlie Date: Wed, 28 Oct 2009 13:58:26 -0600 Subject: Add policy checks --- check-rev-policy | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100755 check-rev-policy (limited to 'check-rev-policy') 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 <&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 <&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 + ;; + + ref/tags/*) + ;; + + # Remote tracking branch + ref/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 + -- cgit v1.2.3