[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Add pre-push git hook to prevent fixup and squash commits from ending up in master
commit ffee0a6384e751486bb4ca2752b6a00527b923ca
Author: rl1987 <rl1987@xxxxxxxxxxxxxxxx>
Date: Tue Nov 20 15:40:52 2018 +0200
Add pre-push git hook to prevent fixup and squash commits from ending up in master
---
changes/ticket27993 | 3 +++
scripts/maint/pre-push | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+)
diff --git a/changes/ticket27993 b/changes/ticket27993
new file mode 100644
index 000000000..78ee7c205
--- /dev/null
+++ b/changes/ticket27993
@@ -0,0 +1,3 @@
+ o Minor features (developer tooling):
+ - Provide git hook script to prevent "fixup!" and "squash!" commits from
+ ending up in master. Closes ticket 27993.
diff --git a/scripts/maint/pre-push b/scripts/maint/pre-push
new file mode 100755
index 000000000..2cf1837b8
--- /dev/null
+++ b/scripts/maint/pre-push
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+# git pre-push hook script to prevent "fixup!" and "squash!" commit
+# from ending up in master, or in any branch if CUR_BRANCH check is removed.
+# It is meant to be placed in .git/hooks directory.
+#
+# The following sample script was used as starting point:
+# https://github.com/git/git/blob/master/templates/hooks--pre-push.sample
+
+z40=0000000000000000000000000000000000000000
+
+CUR_BRANCH=$(git rev-parse --abbrev-ref HEAD)
+if [ "$CUR_BRANCH" != "master" ]
+then
+ exit 0
+fi
+
+echo "Running pre-push hook"
+
+# shellcheck disable=SC2034
+while read -r 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
+
+ # Check for fixup! commit
+ commit=$(git rev-list -n 1 --grep '^fixup!' "$range")
+ if [ -n "$commit" ]
+ then
+ echo >&2 "Found fixup! commit in $local_ref, not pushing"
+ exit 1
+ fi
+
+ # Check for squash! commit
+ commit=$(git rev-list -n 1 --grep '^squash!' "$range")
+ if [ -n "$commit" ]
+ then
+ echo >&2 "Found squash! commit in $local_ref, not pushing"
+ exit 1
+ fi
+ fi
+done
+
+exit 0
+
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits