[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] scripts/git: Make the git push command and args configurable



commit 70387054b9011b8d430a53db5406954f157afa06
Author: teor <teor@xxxxxxxxxxxxxx>
Date:   Mon Aug 12 11:10:12 2019 +1000

    scripts/git: Make the git push command and args configurable
    
    TOR_GIT_PUSH provides the git push command and default arguments.
    
    Also fix handling of git-push-all.sh script arguments and arguments that
    are passed through to $TOR_GIT_PUSH, using a "--" argument as a separator.
    
    Fix on 29879.
---
 changes/ticket31314         |  5 +++++
 scripts/git/git-push-all.sh | 27 +++++++++++++++++++++------
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/changes/ticket31314 b/changes/ticket31314
index 293223117..8b5f5da8f 100644
--- a/changes/ticket31314
+++ b/changes/ticket31314
@@ -7,3 +7,8 @@
     - Add a -u argument to git-merge-forward.sh, so that the script can re-use
       existing test branches after a merge failure and fix.
       Closes ticket 31314.
+    - Add a TOR_GIT_PUSH env var, which sets the default git push command and
+      arguments for git-push-all.sh. Closes ticket 31314.
+    - Add a "--" command-line argument, to
+      separate git-push-all.sh script arguments from arguments that are passed
+      through to git push. Closes ticket 31314.
diff --git a/scripts/git/git-push-all.sh b/scripts/git/git-push-all.sh
index f3bbe8b77..2d6e77a8c 100755
--- a/scripts/git/git-push-all.sh
+++ b/scripts/git/git-push-all.sh
@@ -1,6 +1,7 @@
 #!/usr/bin/env bash
 
-# Usage: git-push-all.sh -t <test-branch-prefix> -r <remote-name> <git-opts>
+# Usage: git-push-all.sh -t <test-branch-prefix> -r <remote-name>
+#                        -- <git-opts>
 #        env vars: TOR_UPSTREAM_REMOTE_NAME=upstream TOR_PUSH_DELAY=0
 #        git-opts: --no-atomic --dry-run (any other git push option)
 #
@@ -16,6 +17,8 @@ set -e
 
 # Don't change this configuration - set the env vars in your .profile
 #
+# git push command and default arguments
+GIT_PUSH=${TOR_GIT_PUSH:-"git push --atomic"}
 # The upstream remote which git.torproject.org/tor.git points to.
 # In test branch mode, override this setting with -r <remote-name>
 UPSTREAM_REMOTE=${TOR_UPSTREAM_REMOTE_NAME:-"upstream"}
@@ -46,11 +49,21 @@ while getopts ":r:t:" opt; do
        OPTIND=$[$OPTIND - 2]
        ;;
     *)
-       # Assume git push will handle the option
+       # Assume we're done with script arguments,
+       # and git push will handle the option
+       break
        ;;
   esac
 done
 
+# getopts doesn't allow "-" as an option character,
+# so we have to handle -- manually
+if [ "$1" = "--" ]; then
+  shift
+fi
+
+echo "Calling git push --atomic $@ <branches>"
+
 if [ "$TEST_BRANCH_PREFIX" ]; then
   if [ "$UPSTREAM_REMOTE" = ${TOR_UPSTREAM_REMOTE_NAME:-"upstream"} ]; then
     echo "Pushing test branches ${TEST_BRANCH_PREFIX}_nnn to " \
@@ -108,9 +121,11 @@ if [ "$PUSH_DELAY" -le 0 ]; then
   # it is safe to use it unquoted.  (This also applies to the other shellcheck
   # exceptions below.)
   #
+  # Push all the branches at the same time
   # shellcheck disable=SC2086
-  git push --atomic "$@" "$UPSTREAM_REMOTE" $PUSH_BRANCHES
+  $GIT_PUSH "$@" "$UPSTREAM_REMOTE" $PUSH_BRANCHES
 else
+  # Push the branches in optimal CI order, with a delay between each push
   PUSH_BRANCHES=$(echo "$PUSH_BRANCHES" | tr " " "\n" | sort -V)
   MASTER_BRANCH=$(echo "$PUSH_BRANCHES" | tr " " "\n" | grep master)
   if [ -z "$TEST_BRANCH_PREFIX" ]; then
@@ -127,15 +142,15 @@ else
     # No release branches
     RELEASE_BRANCHES=
   fi
-  git push "$@" "$UPSTREAM_REMOTE" "$MASTER_BRANCH"
+  $GIT_PUSH "$@" "$UPSTREAM_REMOTE" "$MASTER_BRANCH"
   sleep "$PUSH_DELAY"
   # shellcheck disable=SC2086
   for b in $MAINT_BRANCHES; do
-    git push "$@" "$UPSTREAM_REMOTE" "$b"
+    $GIT_PUSH "$@" "$UPSTREAM_REMOTE" "$b"
     sleep "$PUSH_DELAY"
   done
   if [ "$RELEASE_BRANCHES" ]; then
     # shellcheck disable=SC2086
-    git push --atomic "$@" "$UPSTREAM_REMOTE" $RELEASE_BRANCHES
+    $GIT_PUSH "$@" "$UPSTREAM_REMOTE" $RELEASE_BRANCHES
   fi
 fi



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits