pick-to-branch: restore to original commit HEAD of target on error/abort
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>
Fri, 26 Nov 2021 13:34:01 +0000 (14:34 +0100)
committerTomas Mraz <tomas@openssl.org>
Fri, 3 Dec 2021 11:44:27 +0000 (12:44 +0100)
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/tools/pull/101)

review-tools/pick-to-branch

index 0d64df4c76eb4bf089f6dc5513469f7983f0c641..ef8dc7a10bee3bc861a7ccc3af00da0115147220 100755 (executable)
@@ -88,6 +88,10 @@ function cleanup {
         echo "cherry-picking failed - maybe did not provide a suitable <num> argument?"
         git cherry-pick --abort 2>/dev/null || true
     fi
+    if [ "$ORIG_TARGET_HEAD" != "" ]; then
+        echo Restoring original commit HEAD of $TARGET
+        git reset --merge "$ORIG_TARGET_HEAD"
+    fi
     if [ "$target" != "$ORIG_REF" ]; then
         echo Returning to previous branch $ORIG_REF
         git checkout -q $ORIG_REF
@@ -101,13 +105,13 @@ trap 'cleanup' EXIT
 
 git checkout --quiet master
 git checkout $target
+ORIG_TARGET_HEAD=`git show -s --format="%H"`
 git pull --ff-only
 CHERRYPICKING=1
 git cherry-pick -e -x $id~$num..$id || (git cherry-pick --abort; exit 1)
 CHERRYPICKING=
 
-while true
-do
+while true ; do
     echo -n "Enter 'y'/'yes' to push or 'n'/'no' to abort: "
     read x
     x="`echo $x | tr A-Z a-z`"
@@ -117,9 +121,7 @@ do
     fi
 done
 
-if [ "$x" = "y" -o "$x" = "yes" ]
-then
+if [ "$x" = "y" -o "$x" = "yes" ] ; then
     git push
-else
-    git reset --hard @~1
+    ORIG_TARGET_HEAD=
 fi