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 <pyokagan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Paul Tan committed Aug 4, 2015 at 21:51 UTC 6d42ac2941cac80b44e318d867bae7979c1af6fe
1 file changed +17
builtin/am.c
+17
@@ -1530,6 +1530,23 @@ int cmd_am(int argc, const char **argv, const char *prefix)
1530 struct argv_array paths = ARGV_ARRAY_INIT;
1531 int i;
1532
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 +
1550 if (resume)
1551 die(_("Resolve operation not in progress, we are not resuming."));
1552