am: handle stray $dotest directory

The following bug has been observed: $ git am # no input file ^C $ git am --abort Resolve operation not in progress, we are not resuming. This happens because the following test fails: test -d "$dotest" && test -f "$dotest/last" && test -f "$dotest/next" and the codepath for an "am in-progress" is not executed. It falls back to the codepath that treats this as a "fresh execution". Before rr/rebase-autostash, this condition was test -d "$dotest" It would incorrectly execute the "normal" am --abort codepath: git read-tree --reset -u HEAD ORIG_HEAD git reset ORIG_HEAD by incorrectly assuming that an am is "in progress" (i.e. ORIG_HEAD etc. was written during the previous execution). Notice that $ git am ^C executes nothing of significance, is equivalent to $ mkdir .git/rebase-apply Therefore, the correct solution is to treat .git/rebase-apply as a "stray directory" and remove it on --abort in the fresh-execution codepath. Also ensure that we're not called with --rebasing from git-rebase--am.sh; in that case, it is the responsibility of the caller to handle and stray directories. While at it, tell the user to run "git am --abort" to get rid of the stray $dotest directory, if she attempts anything else. Reported-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ramkumar Ramachandra committed Jun 15, 2013 at 18:13 UTC b141f3c9d3220e1e63ca2195df85c392d475baaf
2 files changed +23
git-am.sh
+17
@@ -506,6 +506,23 @@ then
506 esac
507 rm -f "$dotest/dirtyindex"
508 else
509 + # Possible stray $dotest directory in the independent-run
510 + # case; in the --rebasing case, it is upto the caller
511 + # (git-rebase--am) to take care of stray directories.
512 + if test -d "$dotest" && test -z "$rebasing"
513 + then
514 + case "$skip,$resolved,$abort" in
515 + ,,t)
516 + rm -fr "$dotest"
517 + exit 0
518 + ;;
519 + *)
520 + die "$(eval_gettext "Stray \$dotest directory found.
521 +Use \"git am --abort\" to remove it.")"
522 + ;;
523 + esac
524 + fi
525 +
526 # Make sure we are not given --skip, --resolved, nor --abort
527 test "$skip$resolved$abort" = "" ||
528 die "$(gettext "Resolve operation not in progress, we are not resuming.")"
t/t4150-am.sh
+6
@@ -363,6 +363,12 @@ test_expect_success 'am --skip works' '
363 test_cmp expected another
364 '
365
366 +test_expect_success 'am --abort removes a stray directory' '
367 + mkdir .git/rebase-apply &&
368 + git am --abort &&
369 + test_path_is_missing .git/rebase-apply
370 +'
371 +
372 test_expect_success 'am --resolved works' '
373 echo goodbye >expected &&
374 rm -fr .git/rebase-apply &&