The following bug has been observed:

  $ git am  # no input file
  $ 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

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; 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 <>
Signed-off-by: Ramkumar Ramachandra <>
---     | 17 +++++++++++++++++
 t/ |  6 ++++++
 2 files changed, 23 insertions(+)

diff --git a/ b/
index 1cf3d1d..91a2bcc 100755
--- a/
+++ b/
@@ -506,6 +506,23 @@ then
        rm -f "$dotest/dirtyindex"
+       # Possible stray $dotest directory in the independent-run
+       # case; in the --rebasing case, it is upto the caller
+       # (git-rebase--am) to take care of stray directories.
+       if test -d "$dotest" && test -z "$rebasing"
+       then
+       case "$skip,$resolved,$abort" in
+       ,,t)
+               rm -fr "$dotest"
+               exit 0
+               ;;
+       *)
+               die "$(eval_gettext "Stray \$dotest directory found.
+Use \"git am --abort\" to remove it.")"
+               ;;
+       esac
+       fi
        # Make sure we are not given --skip, --resolved, nor --abort
        test "$skip$resolved$abort" = "" ||
                die "$(gettext "Resolve operation not in progress, we are not 
diff --git a/t/ b/t/
index 12f6b02..6c2cc3e 100755
--- a/t/
+++ b/t/
@@ -363,6 +363,12 @@ test_expect_success 'am --skip works' '
        test_cmp expected another
+test_expect_success 'am --abort removes a stray directory' '
+       mkdir .git/rebase-apply &&
+       git am --abort &&
+       test_path_is_missing .git/rebase-apply
 test_expect_success 'am --resolved works' '
        echo goodbye >expected &&
        rm -fr .git/rebase-apply &&

To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to
More majordomo info at

Reply via email to