poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Add pre-push git hook to perform syntax check


From: Tim Rühsen
Subject: [PATCH] Add pre-push git hook to perform syntax check
Date: Wed, 1 Apr 2020 12:40:53 +0200

* HACKING: Mention pre-push git hook in Maintenance section.
* etc/hooks/pre-push: New file, pre-push git hook.

If applied, this hook will perform a syntax-check and a naive
check for existance of ChangeLog changes.
---
 HACKING            |  5 ++++
 etc/hooks/pre-push | 73 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+)
 create mode 100755 etc/hooks/pre-push

diff --git a/HACKING b/HACKING
index 95186a29..8554170e 100644
--- a/HACKING
+++ b/HACKING
@@ -627,6 +627,11 @@ syntax-check
   applied to, say, an AWK file.  In these cases, consider adding a
   ``.x-sc_*`` fine-tuning file.  But please ask in poke-devel first.

+  We provide a pre-push git hook that performs the syntax check right
+  before pushing. If the check fails, the push is aborted. You should
+  consider enabling this check by coping ``etc/hooks/pre-push`` to
+  ``.git/hooks/``.
+
 coverage
   This target builds *poke* with code coverage support, runs the
   testsuite, and generates a nice html report under
diff --git a/etc/hooks/pre-push b/etc/hooks/pre-push
new file mode 100755
index 00000000..1a07abce
--- /dev/null
+++ b/etc/hooks/pre-push
@@ -0,0 +1,73 @@
+#!/bin/sh
+
+# An example hook script to verify what is about to be pushed.  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>
+#
+# This sample shows how to prevent push of commits where the log message starts
+# with "WIP" (work in progress).
+
+remote="$1"
+url="$2"
+
+echo "Checking syntax... "
+out=`make syntax-check`
+if test $? != 0; then
+  (
+  echo "$out" | grep ':'
+  echo
+  echo "*** Syntax check needs to succeed before pushing is allowed."
+  ) >&2
+  exit 1
+fi
+
+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
+
+               echo $range
+
+               # Check for ChangeLog being in each commits
+               changelog=`git diff-tree --no-commit-id --name-only -r "$range" 
| grep '^ChangeLog$'`
+               if [ -z "$changelog" ]; then
+                       echo >&2 "ChangeLog is missing."
+                       exit 1
+               fi
+
+               # Check for WIP commit
+               commit=`git rev-list -n 1 --grep '^WIP' "$range"`
+               if [ -n "$commit" ]
+               then
+                       echo >&2 "Found WIP commit in $local_ref, not pushing"
+                       exit 1
+               fi
+       fi
+done
+
+exit 0
--
2.26.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]