builtin rebase: support --abort

This commit teaches the builtin rebase the "abort" action, which a user can call to roll back a rebase that is in progress. Signed-off-by: Pratik Karki <predatoramigo@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pratik Karki committed Aug 8, 2018 at 20:51 UTC 5e5d96197ca1bac0037a9cc91369624eb9ec5202
1 file changed +20
builtin/rebase.c
+20
@@ -470,6 +470,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
470 NO_ACTION,
471 ACTION_CONTINUE,
472 ACTION_SKIP,
473 + ACTION_ABORT,
474 } action = NO_ACTION;
475 struct option builtin_rebase_options[] = {
476 OPT_STRING(0, "onto", &options.onto_name,
@@ -496,6 +497,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
497 ACTION_CONTINUE),
498 OPT_CMDMODE(0, "skip", &action,
499 N_("skip current patch and continue"), ACTION_SKIP),
500 + OPT_CMDMODE(0, "abort", &action,
501 + N_("abort and check out the original branch"),
502 + ACTION_ABORT),
503 OPT_END(),
504 };
505
@@ -608,6 +612,22 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
612 exit(1);
613 goto run_rebase;
614 }
615 + case ACTION_ABORT: {
616 + struct string_list merge_rr = STRING_LIST_INIT_DUP;
617 + options.action = "abort";
618 +
619 + rerere_clear(&merge_rr);
620 + string_list_clear(&merge_rr, 1);
621 +
622 + if (read_basic_state(&options))
623 + exit(1);
624 + if (reset_head(&options.orig_head, "reset",
625 + options.head_name, 0) < 0)
626 + die(_("could not move back to %s"),
627 + oid_to_hex(&options.orig_head));
628 + ret = finish_rebase(&options);
629 + goto cleanup;
630 + }
631 default:
632 die("TODO");
633 }