From 15782758c7c9e170fccc138a0c4897a602217641 Mon Sep 17 00:00:00 2001 From: teor Date: Fri, 9 Aug 2019 14:37:38 +1000 Subject: scripts/git: Allow git-merge-forward.sh to re-use existing test branches 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. Part of 31314. --- scripts/git/git-merge-forward.sh | 46 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) (limited to 'scripts/git') diff --git a/scripts/git/git-merge-forward.sh b/scripts/git/git-merge-forward.sh index 1f4ddb85e7..a7e797eaf0 100755 --- a/scripts/git/git-merge-forward.sh +++ b/scripts/git/git-merge-forward.sh @@ -109,7 +109,12 @@ DRY_RUN=0 # _029, _035, ... , _master, and merge forward. TEST_BRANCH_PREFIX= -while getopts "nt:" opt; do +# Controlled by the -u option. The use existing option checks for existing +# branches with the , and checks them out, rather than +# creating a new branch. +USE_EXISTING=0 + +while getopts "nt:u" opt; do case "$opt" in n) DRY_RUN=1 echo " *** DRY RUN MODE ***" @@ -117,6 +122,9 @@ while getopts "nt:" opt; do t) TEST_BRANCH_PREFIX="$OPTARG" echo " *** CREATING TEST BRANCHES: ${TEST_BRANCH_PREFIX}_nnn ***" ;; + u) USE_EXISTING=1 + echo " *** USE EXISTING TEST BRANCHES MODE ***" + ;; *) exit 1 ;; @@ -230,6 +238,32 @@ function new_branch fi } +# Switch to an existing branch, or checkout a new branch with the given +# branch name. +function switch_or_new_branch +{ + local cmd="git rev-parse --verify $1" + if [ $DRY_RUN -eq 0 ]; then + # Call switch_branch if there is a branch, or new_branch if there is not + msg=$( eval "$cmd" 2>&1 ) + RET=$? + if [ $RET -eq 0 ]; then + # Branch: (commit id) + switch_branch "$1" + elif [ $RET -eq 128 ]; then + # Not a branch: "fatal: Needed a single revision" + new_branch "$1" + else + # Unexpected return value + validate_ret $RET "$msg" + fi + else + printf "\\n %s\\n" "${IWTH}$cmd${CNRM}, then depending on the result:" + switch_branch "$1" + new_branch "$1" + fi +} + # Pull the given branch name. function pull_branch { @@ -328,8 +362,14 @@ for ((i=0; i