4 #include "parse-options.h"
7 static const char * const builtin_rebase_helper_usage
[] = {
8 N_("git rebase--helper [<options>]"),
12 int cmd_rebase__helper(int argc
, const char **argv
, const char *prefix
)
14 struct replay_opts opts
= REPLAY_OPTS_INIT
;
15 unsigned flags
= 0, keep_empty
= 0, rebase_merges
= 0;
16 int abbreviate_commands
= 0;
18 CONTINUE
= 1, ABORT
, MAKE_SCRIPT
, SHORTEN_OIDS
, EXPAND_OIDS
,
19 CHECK_TODO_LIST
, SKIP_UNNECESSARY_PICKS
, REARRANGE_SQUASH
,
22 struct option options
[] = {
23 OPT_BOOL(0, "ff", &opts
.allow_ff
, N_("allow fast-forward")),
24 OPT_BOOL(0, "keep-empty", &keep_empty
, N_("keep empty commits")),
25 OPT_BOOL(0, "allow-empty-message", &opts
.allow_empty_message
,
26 N_("allow commits with empty messages")),
27 OPT_BOOL(0, "rebase-merges", &rebase_merges
, N_("rebase merge commits")),
28 OPT_CMDMODE(0, "continue", &command
, N_("continue rebase"),
30 OPT_CMDMODE(0, "abort", &command
, N_("abort rebase"),
32 OPT_CMDMODE(0, "make-script", &command
,
33 N_("make rebase script"), MAKE_SCRIPT
),
34 OPT_CMDMODE(0, "shorten-ids", &command
,
35 N_("shorten commit ids in the todo list"), SHORTEN_OIDS
),
36 OPT_CMDMODE(0, "expand-ids", &command
,
37 N_("expand commit ids in the todo list"), EXPAND_OIDS
),
38 OPT_CMDMODE(0, "check-todo-list", &command
,
39 N_("check the todo list"), CHECK_TODO_LIST
),
40 OPT_CMDMODE(0, "skip-unnecessary-picks", &command
,
41 N_("skip unnecessary picks"), SKIP_UNNECESSARY_PICKS
),
42 OPT_CMDMODE(0, "rearrange-squash", &command
,
43 N_("rearrange fixup/squash lines"), REARRANGE_SQUASH
),
44 OPT_CMDMODE(0, "add-exec-commands", &command
,
45 N_("insert exec commands in todo list"), ADD_EXEC
),
49 sequencer_init_config(&opts
);
50 git_config_get_bool("rebase.abbreviatecommands", &abbreviate_commands
);
52 opts
.action
= REPLAY_INTERACTIVE_REBASE
;
56 argc
= parse_options(argc
, argv
, NULL
, options
,
57 builtin_rebase_helper_usage
, PARSE_OPT_KEEP_ARGV0
);
59 flags
|= keep_empty
? TODO_LIST_KEEP_EMPTY
: 0;
60 flags
|= abbreviate_commands
? TODO_LIST_ABBREVIATE_CMDS
: 0;
61 flags
|= rebase_merges
? TODO_LIST_REBASE_MERGES
: 0;
62 flags
|= command
== SHORTEN_OIDS
? TODO_LIST_SHORTEN_IDS
: 0;
64 if (command
== CONTINUE
&& argc
== 1)
65 return !!sequencer_continue(&opts
);
66 if (command
== ABORT
&& argc
== 1)
67 return !!sequencer_remove_state(&opts
);
68 if (command
== MAKE_SCRIPT
&& argc
> 1)
69 return !!sequencer_make_script(stdout
, argc
, argv
, flags
);
70 if ((command
== SHORTEN_OIDS
|| command
== EXPAND_OIDS
) && argc
== 1)
71 return !!transform_todos(flags
);
72 if (command
== CHECK_TODO_LIST
&& argc
== 1)
73 return !!check_todo_list();
74 if (command
== SKIP_UNNECESSARY_PICKS
&& argc
== 1)
75 return !!skip_unnecessary_picks();
76 if (command
== REARRANGE_SQUASH
&& argc
== 1)
77 return !!rearrange_squash();
78 if (command
== ADD_EXEC
&& argc
== 2)
79 return !!sequencer_add_exec_commands(argv
[1]);
80 usage_with_options(builtin_rebase_helper_usage
, options
);