Skip to content

Commit 6d42ac2

Browse files
pyokagangitster
authored andcommitted
builtin-am: handle stray state directory
Should git-am terminate unexpectedly between the point where the state directory is created, but the "next" and "last" files are not written yet, a stray state directory will be left behind. As such, since b141f3c (am: handle stray $dotest directory, 2013-06-15), git-am.sh explicitly recognizes such a stray directory, and allows the user to remove it with am --abort. Re-implement this feature in builtin/am.c. Signed-off-by: Paul Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent df2760a commit 6d42ac2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

builtin/am.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,23 @@ int cmd_am(int argc, const char **argv, const char *prefix)
15301530
struct argv_array paths = ARGV_ARRAY_INIT;
15311531
int i;
15321532

1533+
/*
1534+
* Handle stray state directory in the independent-run case. In
1535+
* the --rebasing case, it is up to the caller to take care of
1536+
* stray directories.
1537+
*/
1538+
if (file_exists(state.dir) && !state.rebasing) {
1539+
if (resume == RESUME_ABORT) {
1540+
am_destroy(&state);
1541+
am_state_release(&state);
1542+
return 0;
1543+
}
1544+
1545+
die(_("Stray %s directory found.\n"
1546+
"Use \"git am --abort\" to remove it."),
1547+
state.dir);
1548+
}
1549+
15331550
if (resume)
15341551
die(_("Resolve operation not in progress, we are not resuming."));
15351552

0 commit comments

Comments
 (0)