@matheusbsbs / matheus-bagliano / commits / 7b3b7e3758
Fork 0

am --abort: keep unrelated commits since the last failure and warn

After making commits (either by pulling or doing their own work) after a failed "am", the user will be reminded by next "am" invocation that there was a failed "am" that the user needs to decide to resolve or to get rid of the old "am" attempt. The "am --abort" option was meant to help the latter. However, it rewinded the HEAD back to the beginning of the failed "am" attempt, discarding commits made (perhaps by mistake) since. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Dec 21, 2010 at 10:35 UTC 7b3b7e37581fb5266a260687c21af1571b4ade81
2 files changed +34 -2
git-am.sh
+25 -2
@@ -68,9 +68,31 @@ sq () {
68
69 stop_here () {
70 echo "$1" >"$dotest/next"
71 + git rev-parse --verify -q HEAD >"$dotest/abort-safety"
72 exit 1
73 }
74
75 +safe_to_abort () {
76 + if test -f "$dotest/dirtyindex"
77 + then
78 + return 1
79 + fi
80 +
81 + if ! test -s "$dotest/abort-safety"
82 + then
83 + return 0
84 + fi
85 +
86 + abort_safety=$(cat "$dotest/abort-safety")
87 + if test "z$(git rev-parse --verify -q HEAD)" = "z$abort_safety"
88 + then
89 + return 0
90 + fi
91 + echo >&2 "You seem to have moved HEAD since the last 'am' failure."
92 + echo >&2 "Not rewinding to ORIG_HEAD"
93 + return 1
94 +}
95 +
96 stop_here_user_resolve () {
97 if [ -n "$resolvemsg" ]; then
98 printf '%s\n' "$resolvemsg"
@@ -419,10 +441,11 @@ then
441 exec git rebase --abort
442 fi
443 git rerere clear
422 - test -f "$dotest/dirtyindex" || {
444 + if safe_to_abort
445 + then
446 git read-tree --reset -u HEAD ORIG_HEAD
447 git reset ORIG_HEAD
425 - }
448 + fi
449 rm -fr "$dotest"
450 exit ;;
451 esac
t/t4151-am-abort.sh
+9
@@ -62,4 +62,13 @@ do
62
63 done
64
65 +test_expect_success 'am --abort will keep the local commits intact' '
66 + test_must_fail git am 0004-*.patch &&
67 + test_commit unrelated &&
68 + git rev-parse HEAD >expect &&
69 + git am --abort &&
70 + git rev-parse HEAD >actual &&
71 + test_cmp expect actual
72 +'
73 +
74 test_done