'format-patch' could fail due to reasons such as out of memory. Such
failures are not detected or handled, which causes rebase to incorrectly
think that it completed successfully and continue with cleanup. i.e.
calling move_to_original_branch

Since only the exit status of the last command in the pipeline is
available, we rely on || to detect whether 'format-patch' has failed.

Also print messages to help user with how to recover from such failures.

Signed-off-by: Andrew Wong <andrew.k...@gmail.com>
---
 git-rebase--am.sh | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/git-rebase--am.sh b/git-rebase--am.sh
index 392ebc9..8dae804 100644
--- a/git-rebase--am.sh
+++ b/git-rebase--am.sh
@@ -26,10 +26,43 @@ then
        # makes this easy
        git cherry-pick --allow-empty "$revisions"
 else
-       git format-patch -k --stdout --full-index --ignore-if-in-upstream \
+       ( git format-patch -k --stdout --full-index --ignore-if-in-upstream \
                --src-prefix=a/ --dst-prefix=b/ \
-               --no-renames $root_flag "$revisions" |
+               --no-renames $root_flag "$revisions" ||
+               echo $? > "$GIT_DIR"/format-patch-failed ) |
        git am $git_am_opt --rebasing --resolvemsg="$resolvemsg"
+       ret=$?
+       if test -f "$GIT_DIR"/format-patch-failed
+       then
+               ret=1
+               rm -f "$GIT_DIR"/format-patch-failed
+               if test -d "$state_dir"
+               then
+                       echo
+                       echo "'git format-patch' seems to have failed in the 
middle of 'git am'."
+                       echo "If you continue rebasing, you will likely be 
losing some commits."
+                       echo "It is recommended that you abort rebasing by 
running:"
+                       echo
+                       echo "    git rebase --abort"
+                       echo
+               else
+                       echo
+                       echo "'git format-patch' seems to have failed before 
'git am' started."
+                       echo "It is impossible to continue or abort rebasing."
+                       echo "You have to use the following to return to your 
original head:"
+                       echo
+                       case "$head_name" in
+                       refs/*)
+                               echo "    git checkout $head_name"
+                               ;;
+                       *)
+                               echo "    git checkout $orig_head"
+                               ;;
+                       esac
+                       echo
+               fi
+       fi
+       test 0 != $ret && false
 fi && move_to_original_branch
 
 ret=$?
-- 
1.8.0.rc0.18.gf84667d

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to