]>
Commit | Line | Data |
---|---|---|
4557f1ad JS |
1 | #include "builtin.h" |
2 | #include "cache.h" | |
b2141fc1 | 3 | #include "config.h" |
4557f1ad JS |
4 | #include "parse-options.h" |
5 | #include "sequencer.h" | |
6 | ||
7 | static const char * const builtin_rebase_helper_usage[] = { | |
8 | N_("git rebase--helper [<options>]"), | |
9 | NULL | |
10 | }; | |
11 | ||
12 | int cmd_rebase__helper(int argc, const char **argv, const char *prefix) | |
13 | { | |
14 | struct replay_opts opts = REPLAY_OPTS_INIT; | |
1644c73c | 15 | unsigned flags = 0, keep_empty = 0, rebase_merges = 0; |
7543f6f4 | 16 | int abbreviate_commands = 0, rebase_cousins = -1; |
4557f1ad | 17 | enum { |
d80fc293 | 18 | CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS, |
0cce4a27 LB |
19 | CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH, |
20 | ADD_EXEC | |
4557f1ad JS |
21 | } command = 0; |
22 | struct option options[] = { | |
23 | OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")), | |
62db5247 | 24 | OPT_BOOL(0, "keep-empty", &keep_empty, N_("keep empty commits")), |
a6c612b5 GS |
25 | OPT_BOOL(0, "allow-empty-message", &opts.allow_empty_message, |
26 | N_("allow commits with empty messages")), | |
1644c73c | 27 | OPT_BOOL(0, "rebase-merges", &rebase_merges, N_("rebase merge commits")), |
7543f6f4 JS |
28 | OPT_BOOL(0, "rebase-cousins", &rebase_cousins, |
29 | N_("keep original branch points of cousins")), | |
4557f1ad JS |
30 | OPT_CMDMODE(0, "continue", &command, N_("continue rebase"), |
31 | CONTINUE), | |
32 | OPT_CMDMODE(0, "abort", &command, N_("abort rebase"), | |
33 | ABORT), | |
62db5247 JS |
34 | OPT_CMDMODE(0, "make-script", &command, |
35 | N_("make rebase script"), MAKE_SCRIPT), | |
3546c8d9 | 36 | OPT_CMDMODE(0, "shorten-ids", &command, |
d80fc293 | 37 | N_("shorten commit ids in the todo list"), SHORTEN_OIDS), |
3546c8d9 | 38 | OPT_CMDMODE(0, "expand-ids", &command, |
d80fc293 | 39 | N_("expand commit ids in the todo list"), EXPAND_OIDS), |
94399949 JS |
40 | OPT_CMDMODE(0, "check-todo-list", &command, |
41 | N_("check the todo list"), CHECK_TODO_LIST), | |
cdac2b01 JS |
42 | OPT_CMDMODE(0, "skip-unnecessary-picks", &command, |
43 | N_("skip unnecessary picks"), SKIP_UNNECESSARY_PICKS), | |
c44a4c65 JS |
44 | OPT_CMDMODE(0, "rearrange-squash", &command, |
45 | N_("rearrange fixup/squash lines"), REARRANGE_SQUASH), | |
0cce4a27 LB |
46 | OPT_CMDMODE(0, "add-exec-commands", &command, |
47 | N_("insert exec commands in todo list"), ADD_EXEC), | |
4557f1ad JS |
48 | OPT_END() |
49 | }; | |
50 | ||
28d6daed | 51 | sequencer_init_config(&opts); |
d8ae6c84 | 52 | git_config_get_bool("rebase.abbreviatecommands", &abbreviate_commands); |
4557f1ad JS |
53 | |
54 | opts.action = REPLAY_INTERACTIVE_REBASE; | |
55 | opts.allow_ff = 1; | |
56 | opts.allow_empty = 1; | |
57 | ||
58 | argc = parse_options(argc, argv, NULL, options, | |
59 | builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0); | |
60 | ||
313a48ea | 61 | flags |= keep_empty ? TODO_LIST_KEEP_EMPTY : 0; |
d8ae6c84 | 62 | flags |= abbreviate_commands ? TODO_LIST_ABBREVIATE_CMDS : 0; |
1644c73c | 63 | flags |= rebase_merges ? TODO_LIST_REBASE_MERGES : 0; |
7543f6f4 | 64 | flags |= rebase_cousins > 0 ? TODO_LIST_REBASE_COUSINS : 0; |
313a48ea LB |
65 | flags |= command == SHORTEN_OIDS ? TODO_LIST_SHORTEN_IDS : 0; |
66 | ||
7543f6f4 JS |
67 | if (rebase_cousins >= 0 && !rebase_merges) |
68 | warning(_("--[no-]rebase-cousins has no effect without " | |
69 | "--rebase-merges")); | |
70 | ||
4557f1ad JS |
71 | if (command == CONTINUE && argc == 1) |
72 | return !!sequencer_continue(&opts); | |
73 | if (command == ABORT && argc == 1) | |
74 | return !!sequencer_remove_state(&opts); | |
62db5247 | 75 | if (command == MAKE_SCRIPT && argc > 1) |
313a48ea LB |
76 | return !!sequencer_make_script(stdout, argc, argv, flags); |
77 | if ((command == SHORTEN_OIDS || command == EXPAND_OIDS) && argc == 1) | |
78 | return !!transform_todos(flags); | |
94399949 JS |
79 | if (command == CHECK_TODO_LIST && argc == 1) |
80 | return !!check_todo_list(); | |
cdac2b01 JS |
81 | if (command == SKIP_UNNECESSARY_PICKS && argc == 1) |
82 | return !!skip_unnecessary_picks(); | |
c44a4c65 JS |
83 | if (command == REARRANGE_SQUASH && argc == 1) |
84 | return !!rearrange_squash(); | |
0cce4a27 LB |
85 | if (command == ADD_EXEC && argc == 2) |
86 | return !!sequencer_add_exec_commands(argv[1]); | |
4557f1ad JS |
87 | usage_with_options(builtin_rebase_helper_usage, options); |
88 | } |