[PATCH 2/2] Introduce git am --abort

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

 



Currently, aborting a git-am process during a conflict is done by
resetting to the HEAD before applying the patches and removing the
.git/rebase directory manually.

This patch introduces an --abort option for git-am to make this as
easy as in git-rebase.

Mentored-by: Christian Couder <chriscool@xxxxxxxxxxxxx>
Mentored-by: Daniel Barkalow <barkalow@xxxxxxxxxxxx>
Signed-off-by: Stephan Beyer <s-beyer@xxxxxxx>
---
 Documentation/git-am.txt               |    5 ++++-
 Documentation/git-rerere.txt           |    2 +-
 contrib/completion/git-completion.bash |    2 +-
 git-am.sh                              |   19 ++++++++++++-------
 git-rebase.sh                          |    8 +++-----
 t/t4150-am.sh                          |   21 +++++++++++++++++----
 6 files changed, 38 insertions(+), 19 deletions(-)

diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt
index 2d7f162..df35cee 100644
--- a/Documentation/git-am.txt
+++ b/Documentation/git-am.txt
@@ -13,7 +13,7 @@ SYNOPSIS
          [--3way] [--interactive] [--binary]
          [--whitespace=<option>] [-C<n>] [-p<n>]
 	 [<mbox> | <Maildir>...]
-'git am' (--skip | --resolved)
+'git am' (--abort | --skip | --resolved)
 
 DESCRIPTION
 -----------
@@ -79,6 +79,9 @@ default.   You could use `--no-utf8` to override this.
 --interactive::
 	Run interactively.
 
+--abort::
+	Abort applying and rewind applied patches.
+
 --skip::
 	Skip the current patch.  This is only meaningful when
 	restarting an aborted patch.
diff --git a/Documentation/git-rerere.txt b/Documentation/git-rerere.txt
index 678bfd3..ad81dbc 100644
--- a/Documentation/git-rerere.txt
+++ b/Documentation/git-rerere.txt
@@ -37,7 +37,7 @@ its working state.
 'clear'::
 
 This resets the metadata used by rerere if a merge resolution is to be
-is aborted.  Calling 'git-am --skip' or 'git-rebase [--skip|--abort]'
+is aborted.  Calling 'git-am [--skip|--abort]' or 'git-rebase [--skip|--abort]'
 will automatically invoke this command.
 
 'diff'::
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 29f6cd4..d271ba0 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -489,7 +489,7 @@ _git_am ()
 {
 	local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
 	if [ -d "$dir"/rebase ]; then
-		__gitcomp "--skip --resolved"
+		__gitcomp "--skip --resolved --abort"
 		return
 	fi
 	case "$cur" in
diff --git a/git-am.sh b/git-am.sh
index e36f22c..7301314 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -8,6 +8,7 @@ OPTIONS_SPEC="\
 git-am [options] [<mbox>|<Maildir>...]
 git-am [options] --resolved
 git-am [options] --skip
+git-am [options] --abort
 --
 d,dotest=       (removed -- do not use)
 i,interactive   run interactively
@@ -22,6 +23,7 @@ p=              pass it through git-apply
 resolvemsg=     override error message when patch failure occurs
 r,resolved      to be used after a patch failure
 skip            skip the current patch
+abort           abort patching and reset done patches
 rebasing        (internal use for git-rebase)"
 
 . git-sh-setup
@@ -108,7 +110,7 @@ print_continue_info () {
 }
 
 run_sequencer () {
-	git sequencer $noadvice --caller='git am||--resolved|--skip' "$@"
+	git sequencer $noadvice --caller='git am|--abort|--resolved|--skip' "$@"
 	case "$?" in
 	0)
 		cleanup
@@ -130,7 +132,7 @@ run_sequencer_i () {
 	while true
 	do
 		output=$(git sequencer $noadvice \
-			--caller='git am -i||--resolved|--skip' \
+			--caller='git am -i|--abort|--resolved|--skip' \
 			$command 2>&1 >/dev/null)
 		noadvice=
 		case "$?" in
@@ -170,6 +172,8 @@ do
 	case "$1" in
 	-i|--interactive)
 		interactive=_i ;;
+	--abort)
+		abort=t ;;
 	-b|--binary)
 		binary=t ;;
 	-3|--3way)
@@ -219,17 +223,18 @@ then
 	# unreliable -- stdin could be /dev/null for example
 	# and the caller did not intend to feed us a patch but
 	# wanted to continue unattended.
-	test -z "$resolved$skip" && tty -s
+	test -z "$abort$resolved$skip" && tty -s
 
+	test -n "$abort" && run_sequencer$interactive --abort
 	test -n "$resolved" && run_sequencer$interactive --continue
 	test -n "$skip" && run_sequencer$interactive --skip
 
-	die "$dotest still exists. Use git am --skip/--resolved."
+	die "$dotest still exists. Use git am --abort/--skip/--resolved."
 fi
 
-# Make sure we are not given --skip nor --resolved
-test -z "$resolved$skip" ||
-	die 'git-am is not in progress. You cannot use --skip/--resolved then.'
+# Make sure we are not given --skip nor --resolved nor --abort
+test -z "$abort$resolved$skip" ||
+	die 'git-am is not in progress. You cannot use --abort/--skip/--resolved then.'
 
 # sequencer running?
 git sequencer --status >/dev/null 2>&1 &&
diff --git a/git-rebase.sh b/git-rebase.sh
index 231c486..a83933b 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -216,13 +216,11 @@ do
 		if test -d "$dotest"
 		then
 			move_to_original_branch
+			git reset --hard $(cat "$dotest/orig-head")
+			rm -r "$dotest"
 		else
-			dotest="$GIT_DIR"/rebase
-			move_to_original_branch
+			git am --abort
 		fi
-		rm -rf "$GIT_DIR/sequencer"
-		git reset --hard $(cat "$dotest/orig-head")
-		rm -r "$dotest"
 		exit
 		;;
 	--onto)
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index e771806..152e2d9 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -83,6 +83,10 @@ test_expect_success setup '
 	git commit -m third &&
 	git format-patch --stdout first >patch2	&&
 	git checkout -b lorem &&
+	echo new >another &&
+	git add another &&
+	test_tick &&
+	git commit -m "added another file" &&
 	sed -n -e "11,\$p" msg >file &&
 	head -n 9 msg >>file &&
 	test_tick &&
@@ -181,8 +185,8 @@ test_expect_success 'am -3 falls back to 3-way merge' '
 '
 
 test_expect_success 'am pauses on conflict' '
-	git checkout lorem2^^ &&
-	! git am lorem-move.patch &&
+	git checkout lorem2~3 &&
+	test_must_fail git am lorem-move.patch &&
 	test -d .git/rebase
 '
 
@@ -193,9 +197,18 @@ test_expect_success 'am --skip works' '
 	test goodbye = "$(cat another)"
 '
 
+test_expect_success 'am --abort works' '
+	git checkout lorem2~3 &&
+	test_must_fail git am lorem-move.patch &&
+	test -d .git/rebase &&
+	git am --abort &&
+	test "$(git rev-parse HEAD)" = "$(git rev-parse lorem2~3)" &&
+	! test -f another
+'
+
 test_expect_success 'am --resolved works' '
-	git checkout lorem2^^ &&
-	! git am lorem-move.patch &&
+	git checkout lorem2~3 &&
+	test_must_fail git am lorem-move.patch &&
 	test -d .git/rebase &&
 	echo resolved >>file &&
 	git add file &&
-- 
1.5.6.3.391.g7ab7e

--
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]

  Powered by Linux