summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeif Lindholm <leif.lindholm@linaro.org>2017-08-31 09:26:04 +0100
committerLeif Lindholm <leif.lindholm@linaro.org>2017-08-31 09:26:04 +0100
commite960afaa7ce3474724a8548a746b97b4cd0ff500 (patch)
tree9a164bb89719b57c8523c3329f513726d8a7b180
parente9d6f5779974c1f27d1da4136ee0fea830c8aedb (diff)
add git-hooks directory and pre-push script
Simple script to verifies for each patch before commencing pushing that: - if I am the author, the patch has Reviewed-by: <someone@else> - if I am not the author, it has my Reviewed-by: (based on gitconfig name/email). - it has a valid Contributed-under entry. Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
-rwxr-xr-xgit-hooks/pre-push84
1 files changed, 84 insertions, 0 deletions
diff --git a/git-hooks/pre-push b/git-hooks/pre-push
new file mode 100755
index 0000000..c63bc45
--- /dev/null
+++ b/git-hooks/pre-push
@@ -0,0 +1,84 @@
+#!/bin/sh
+
+# Called by "git push" after it has checked the remote status, but before
+# anything has been pushed. If this script exits with a non-zero status nothing
+# will be pushed.
+#
+# This hook is called with the following parameters:
+#
+# $1 -- Name of the remote to which the push is being done
+# $2 -- URL to which the push is being done
+#
+# If pushing without using a named remote those arguments will be equal.
+#
+# Information about the commits which are being pushed is supplied as lines to
+# the standard input in the form:
+#
+# <local ref> <local sha1> <remote ref> <remote sha1>
+
+remote="$1"
+url="$2"
+
+ME="`git config --get user.name` <`git config --get user.email`>"
+STATUS=0
+
+case "$url" in
+ *github.com/tianocore/edk2*.git)
+ echo "Doing pre-push sanity checks..."
+ ;;
+ *)
+ echo "Not pushing to a \"real\" upstream - skipping push hook."
+ exit 0
+ ;;
+esac
+
+check_reviewed()
+{
+ signoff=`git rev-list -n 1 --grep "^Signed-off-by: $ME\$" "$1^..$1"`
+ if [ -z "$signoff" ]; then
+ REVIEWER="$ME"
+ else
+ signoff=`git rev-list -n 1 --grep "^Signed-off-by: .*\$" "$1^..$1"`
+ if [ -z "$signoff" ]; then
+ echo "$1 missing 'Signed-off-by:'!" >&2
+ STATUS=1
+ return
+ fi
+ REVIEWER=".*"
+ fi
+
+ reviewed=`git rev-list -n 1 --grep "^Reviewed-by: $REVIEWER\$" "$1^..$1"`
+ if [ -z "$reviewed" ]; then
+ echo "$1 missing 'Reviewed-by:'!" >&2
+ STATUS=1
+ return
+ fi
+}
+
+check_contributed()
+{
+ contributed=`git rev-list -n 1 --grep "^Contributed-under: TianoCore Contribution Agreement 1.1\$" "$1^..$1"`
+ if [ -z "$contributed" ]; then
+ echo "$1: incorrect or missing 'Contributed-under:'!" >&2
+ STATUS=1
+ contributed=`git rev-list -n 1 --grep "^Contributed-under: TianoCore Contribution Agreement 1.0\$" "$1^..$1"`
+ if [ -n "$contributed" ]; then
+ echo " Contribution Agreement version 1.0 outdated" >&2
+ fi
+ return
+ fi
+}
+
+while read local_ref local_sha remote_ref remote_sha
+do
+ git rev-list $remote_sha..$local_sha | while read rev
+ do
+ echo "Checking: $rev"
+ check_reviewed $rev
+ check_contributed $rev
+ done
+done
+
+[ $STATUS -ne 0 ] && exit 1
+
+echo "Att checks passed!"