ghmerge: Fix behavior on failed cherry-pick, rebase, and pull
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>
Mon, 25 Oct 2021 12:45:17 +0000 (14:45 +0200)
committerTomas Mraz <tomas@openssl.org>
Mon, 22 Nov 2021 13:52:01 +0000 (14:52 +0100)
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/tools/pull/97)

review-tools/ghmerge

index 7d1fc257ccd5f0481e19a6554875735bbd2540f8..00de102dacc255b40ea6dd098ba5832ee76a0aae 100755 (executable)
@@ -165,6 +165,13 @@ function cleanup {
     rv=$?
     echo # make sure to enter new line, needed, e.g., after Ctrl-C
     [ $rv -ne 0 ] && echo -e "\nghmerge failed"
+    if [ "$REBASING" == 1 ] ; then
+        git rebase --abort 2>/dev/null || true
+    fi
+    if [ "$CHERRYPICKING" == 1 ] ; then
+        echo "Hint: maybe --cherry-pick was not given a suitable <n> parameter."
+        git cherry-pick --abort 2>/dev/null || true
+    fi
     if [ "$REF" != "$ORIG_REF" ] || [ "$WORK_USED" != "" ]; then
         echo Returning to previous branch $ORIG_REF
         git checkout -q $ORIG_REF
@@ -185,7 +192,9 @@ if [ "$REF" != "$ORIG_REF" ]; then
 fi
 
 echo -n "Press Enter to pull the latest $REMOTE/$REF: "; read foo
-git pull $REMOTE $REF || (git rebase --abort; exit 1)
+REBASING=1
+git pull $REMOTE $REF || exit 1
+REBASING=
 
 WORK_USED=$WORK
 # append new commits from $REPO/$BRANCH
@@ -193,12 +202,16 @@ if [ "$PICK" != "yes" ]; then
     echo Rebasing $REPO/$BRANCH on $REF...
     git fetch $REPO $BRANCH && git checkout -b $WORK FETCH_HEAD
     WORK_USED=$WORK
-    git rebase $REF || (echo 'Fix or Ctrl-d to abort' ; read || (git rebase --abort; exit 1))
+    REBASING=1
+    git rebase $REF || (echo 'Fix or Ctrl-d to abort' ; read || exit 1)
+    REBASING=
 else
     echo Cherry-picking $REPO/$BRANCH to $REF...
     git checkout -b $WORK $REF
     WORK_USED=$WORK
-    git fetch $REPO $BRANCH && git cherry-pick FETCH_HEAD
+    CHERRYPICKING=1
+    git fetch $REPO $BRANCH && (git cherry-pick FETCH_HEAD || exit 1)
+    CHERRYPICKING=
 fi
 
 echo Diff against $REMOTE/$REF
@@ -206,7 +219,9 @@ git diff $REMOTE/$REF
 
 if [ "$INTERACTIVE" == "yes" ] ; then
     echo -n "Press Enter to interactively rebase $AUTOSQUASH on $REMOTE/$REF: "; read foo
-    git rebase -i $AUTOSQUASH $REMOTE/$REF || (git rebase --abort; exit 1)
+    REBASING=1
+    git rebase -i $AUTOSQUASH $REMOTE/$REF || exit 1
+    REBASING=
     echo "Calling addrev $ADDREVOPTS --prnum=$PRNUM $TEAM $REMOTE/$REF.."
     addrev $ADDREVOPTS --prnum=$PRNUM $TEAM $REMOTE/$REF..
 fi