1#include "builtin.h"
2#include "cache.h"
3#include "config.h"
4#include "parse-options.h"
5#include "sequencer.h"
6
7static const char * const builtin_rebase_helper_usage[] = {
8 N_("git rebase--helper [<options>]"),
9 NULL
10};
11
12int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
13{
14 struct replay_opts opts = REPLAY_OPTS_INIT;
15 int keep_empty = 0;
16 enum {
17 CONTINUE = 1, ABORT, MAKE_SCRIPT
18 } command = 0;
19 struct option options[] = {
20 OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")),
21 OPT_BOOL(0, "keep-empty", &keep_empty, N_("keep empty commits")),
22 OPT_CMDMODE(0, "continue", &command, N_("continue rebase"),
23 CONTINUE),
24 OPT_CMDMODE(0, "abort", &command, N_("abort rebase"),
25 ABORT),
26 OPT_CMDMODE(0, "make-script", &command,
27 N_("make rebase script"), MAKE_SCRIPT),
28 OPT_END()
29 };
30
31 git_config(git_default_config, NULL);
32
33 opts.action = REPLAY_INTERACTIVE_REBASE;
34 opts.allow_ff = 1;
35 opts.allow_empty = 1;
36
37 argc = parse_options(argc, argv, NULL, options,
38 builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0);
39
40 if (command == CONTINUE && argc == 1)
41 return !!sequencer_continue(&opts);
42 if (command == ABORT && argc == 1)
43 return !!sequencer_remove_state(&opts);
44 if (command == MAKE_SCRIPT && argc > 1)
45 return !!sequencer_make_script(keep_empty, stdout, argc, argv);
46 usage_with_options(builtin_rebase_helper_usage, options);
47}