rebase -i: also expand/collapse the SHA-1s via the rebase--helper
[git.git] / builtin / rebase--helper.c
blob791b62901c31bdf5a36c2342b5a88e7af36665bc
1 #include "builtin.h"
2 #include "cache.h"
3 #include "config.h"
4 #include "parse-options.h"
5 #include "sequencer.h"
7 static const char * const builtin_rebase_helper_usage[] = {
8 N_("git rebase--helper [<options>]"),
9 NULL
12 int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
14 struct replay_opts opts = REPLAY_OPTS_INIT;
15 int keep_empty = 0;
16 enum {
17 CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_SHA1S, EXPAND_SHA1S
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_CMDMODE(0, "shorten-ids", &command,
29 N_("shorten SHA-1s in the todo list"), SHORTEN_SHA1S),
30 OPT_CMDMODE(0, "expand-ids", &command,
31 N_("expand SHA-1s in the todo list"), EXPAND_SHA1S),
32 OPT_END()
35 git_config(git_default_config, NULL);
37 opts.action = REPLAY_INTERACTIVE_REBASE;
38 opts.allow_ff = 1;
39 opts.allow_empty = 1;
41 argc = parse_options(argc, argv, NULL, options,
42 builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0);
44 if (command == CONTINUE && argc == 1)
45 return !!sequencer_continue(&opts);
46 if (command == ABORT && argc == 1)
47 return !!sequencer_remove_state(&opts);
48 if (command == MAKE_SCRIPT && argc > 1)
49 return !!sequencer_make_script(keep_empty, stdout, argc, argv);
50 if (command == SHORTEN_SHA1S && argc == 1)
51 return !!transform_todo_ids(1);
52 if (command == EXPAND_SHA1S && argc == 1)
53 return !!transform_todo_ids(0);
54 usage_with_options(builtin_rebase_helper_usage, options);