[RFC] rebase: Handle cases where format-patch fails

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



'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

Instead of using a pipe, we separate 'format-patch' and 'am' by using an
intermediate file. This gurantees that we can invoke 'am' with the
complete input, or not invoking 'am' at all if 'format-patch' failed.

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

Signed-off-by: Andrew Wong <andrew.kw.w@xxxxxxxxx>
---
 git-rebase--am.sh | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/git-rebase--am.sh b/git-rebase--am.sh
index 392ebc9..a955b38 100644
--- a/git-rebase--am.sh
+++ b/git-rebase--am.sh
@@ -26,10 +26,32 @@ then
 	# makes this easy
 	git cherry-pick --allow-empty "$revisions"
 else
-	git format-patch -k --stdout --full-index --ignore-if-in-upstream \
+	rm -f "$GIT_DIR/format-patch"
+	if ! git format-patch -k --stdout --full-index --ignore-if-in-upstream \
 		--src-prefix=a/ --dst-prefix=b/ \
-		--no-renames $root_flag "$revisions" |
-	git am $git_am_opt --rebasing --resolvemsg="$resolvemsg"
+		--no-renames $root_flag "$revisions" > "$GIT_DIR/format-patch" && ret=$?
+	then
+		rm "$GIT_DIR/format-patch"
+		echo
+		echo "'git format-patch' seems to have failed."
+		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
+		exit $ret
+	fi
+
+	git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" < "$GIT_DIR/format-patch" || ret=$?
+	rm -f "$GIT_DIR/format-patch"
+	test 0 != ret && ( exit $ret )
 fi && move_to_original_branch
 
 ret=$?
-- 
1.8.0.rc0.19.ga19ab82.dirty

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


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]