[tor-commits] [tor/master] Update git pre-push hook so that only upstream branches can get pushed to origin

dgoulet at torproject.org dgoulet at torproject.org
Tue Mar 5 19:30:57 UTC 2019


commit ae5a0f39cd3d0098ca684c7dfb83ebfe3acca8b6
Author: rl1987 <rl1987 at sdf.lonestar.org>
Date:   Wed Feb 20 09:35:27 2019 +0200

    Update git pre-push hook so that only upstream branches can get pushed to origin
---
 changes/feature29532            |  4 ++++
 scripts/maint/pre-push.git-hook | 21 ++++++++++++++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/changes/feature29532 b/changes/feature29532
new file mode 100644
index 000000000..4d95e6bca
--- /dev/null
+++ b/changes/feature29532
@@ -0,0 +1,4 @@
+  o Minor features (developer tooling):
+    - Modify git pre-push hook script to disallow pushing branches other than
+      master, release-* and maint-* to origin remote. Implements feature
+      29532.
diff --git a/scripts/maint/pre-push.git-hook b/scripts/maint/pre-push.git-hook
index 26296023f..78d62527e 100755
--- a/scripts/maint/pre-push.git-hook
+++ b/scripts/maint/pre-push.git-hook
@@ -1,17 +1,32 @@
 #!/bin/bash
 
+# 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.
+# Furthermore, it disallows pushing branches other than master, release-*
+# and maint-* to origin (e.g. gitweb.torproject.org).
+#
 # To install this script, copy it into .git/hooks/pre-push path in your
 # local copy of git repository. Make sure it has permission to execute.
 #
-# This is git pre-push hook script to prevent "fixup!" and "squash!" commits
-# from ending up in upstream branches (master, release-* or maint-*).
-#
 # The following sample script was used as starting point:
 # https://github.com/git/git/blob/master/templates/hooks--pre-push.sample
 
 z40=0000000000000000000000000000000000000000
 
+remote="$1"
 CUR_BRANCH=$(git rev-parse --abbrev-ref HEAD)
+
+# Only allow pushing master, release-* and maint-* branches to origin.
+if [ "$remote" == "origin" ]
+then
+        if  [ "$CUR_BRANCH" != "master" ] && [[ $CUR_BRANCH != release-* ]] &&
+             [[ $CUR_BRANCH != maint-* ]]
+        then
+                echo >&2 "Not pushing $CUR_BRANCH to origin"
+                exit 1
+        fi
+fi
+
 if [ "$CUR_BRANCH" != "master" ] && [[ $CUR_BRANCH != release-* ]] &&
         [[ $CUR_BRANCH != maint-* ]]
 then





More information about the tor-commits mailing list