]>
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" | |
145e05ac | 6 | #include "rebase-interactive.h" |
4557f1ad JS |
7 | |
8 | static const char * const builtin_rebase_helper_usage[] = { | |
9 | N_("git rebase--helper [<options>]"), | |
10 | NULL | |
11 | }; | |
12 | ||
13 | int cmd_rebase__helper(int argc, const char **argv, const char *prefix) | |
14 | { | |
15 | struct replay_opts opts = REPLAY_OPTS_INIT; | |
b97e1873 | 16 | unsigned flags = 0, keep_empty = 0, rebase_merges = 0, autosquash = 0; |
7543f6f4 | 17 | int abbreviate_commands = 0, rebase_cousins = -1; |
4557f1ad | 18 | enum { |
d80fc293 | 19 | CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS, |
0cce4a27 | 20 | CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH, |
4df66c40 | 21 | ADD_EXEC, APPEND_TODO_HELP, EDIT_TODO, PREPARE_BRANCH, |
b97e1873 | 22 | CHECKOUT_ONTO, COMPLETE_ACTION |
4557f1ad JS |
23 | } command = 0; |
24 | struct option options[] = { | |
25 | OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")), | |
62db5247 | 26 | OPT_BOOL(0, "keep-empty", &keep_empty, N_("keep empty commits")), |
a6c612b5 GS |
27 | OPT_BOOL(0, "allow-empty-message", &opts.allow_empty_message, |
28 | N_("allow commits with empty messages")), | |
1644c73c | 29 | OPT_BOOL(0, "rebase-merges", &rebase_merges, N_("rebase merge commits")), |
7543f6f4 JS |
30 | OPT_BOOL(0, "rebase-cousins", &rebase_cousins, |
31 | N_("keep original branch points of cousins")), | |
b97e1873 AG |
32 | OPT_BOOL(0, "autosquash", &autosquash, |
33 | N_("move commits that begin with squash!/fixup!")), | |
2c58483a | 34 | OPT__VERBOSE(&opts.verbose, N_("be verbose")), |
4557f1ad JS |
35 | OPT_CMDMODE(0, "continue", &command, N_("continue rebase"), |
36 | CONTINUE), | |
37 | OPT_CMDMODE(0, "abort", &command, N_("abort rebase"), | |
38 | ABORT), | |
62db5247 JS |
39 | OPT_CMDMODE(0, "make-script", &command, |
40 | N_("make rebase script"), MAKE_SCRIPT), | |
3546c8d9 | 41 | OPT_CMDMODE(0, "shorten-ids", &command, |
d80fc293 | 42 | N_("shorten commit ids in the todo list"), SHORTEN_OIDS), |
3546c8d9 | 43 | OPT_CMDMODE(0, "expand-ids", &command, |
d80fc293 | 44 | N_("expand commit ids in the todo list"), EXPAND_OIDS), |
94399949 JS |
45 | OPT_CMDMODE(0, "check-todo-list", &command, |
46 | N_("check the todo list"), CHECK_TODO_LIST), | |
cdac2b01 JS |
47 | OPT_CMDMODE(0, "skip-unnecessary-picks", &command, |
48 | N_("skip unnecessary picks"), SKIP_UNNECESSARY_PICKS), | |
c44a4c65 JS |
49 | OPT_CMDMODE(0, "rearrange-squash", &command, |
50 | N_("rearrange fixup/squash lines"), REARRANGE_SQUASH), | |
0cce4a27 LB |
51 | OPT_CMDMODE(0, "add-exec-commands", &command, |
52 | N_("insert exec commands in todo list"), ADD_EXEC), | |
145e05ac AG |
53 | OPT_CMDMODE(0, "append-todo-help", &command, |
54 | N_("insert the help in the todo list"), APPEND_TODO_HELP), | |
64a43cbd AG |
55 | OPT_CMDMODE(0, "edit-todo", &command, |
56 | N_("edit the todo list during an interactive rebase"), | |
57 | EDIT_TODO), | |
2c58483a AG |
58 | OPT_CMDMODE(0, "prepare-branch", &command, |
59 | N_("prepare the branch to be rebased"), PREPARE_BRANCH), | |
4df66c40 AG |
60 | OPT_CMDMODE(0, "checkout-onto", &command, |
61 | N_("checkout a commit"), CHECKOUT_ONTO), | |
b97e1873 AG |
62 | OPT_CMDMODE(0, "complete-action", &command, |
63 | N_("complete the action"), COMPLETE_ACTION), | |
4557f1ad JS |
64 | OPT_END() |
65 | }; | |
66 | ||
28d6daed | 67 | sequencer_init_config(&opts); |
d8ae6c84 | 68 | git_config_get_bool("rebase.abbreviatecommands", &abbreviate_commands); |
4557f1ad JS |
69 | |
70 | opts.action = REPLAY_INTERACTIVE_REBASE; | |
71 | opts.allow_ff = 1; | |
72 | opts.allow_empty = 1; | |
73 | ||
74 | argc = parse_options(argc, argv, NULL, options, | |
75 | builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0); | |
76 | ||
313a48ea | 77 | flags |= keep_empty ? TODO_LIST_KEEP_EMPTY : 0; |
d8ae6c84 | 78 | flags |= abbreviate_commands ? TODO_LIST_ABBREVIATE_CMDS : 0; |
1644c73c | 79 | flags |= rebase_merges ? TODO_LIST_REBASE_MERGES : 0; |
7543f6f4 | 80 | flags |= rebase_cousins > 0 ? TODO_LIST_REBASE_COUSINS : 0; |
313a48ea LB |
81 | flags |= command == SHORTEN_OIDS ? TODO_LIST_SHORTEN_IDS : 0; |
82 | ||
7543f6f4 JS |
83 | if (rebase_cousins >= 0 && !rebase_merges) |
84 | warning(_("--[no-]rebase-cousins has no effect without " | |
85 | "--rebase-merges")); | |
86 | ||
4557f1ad JS |
87 | if (command == CONTINUE && argc == 1) |
88 | return !!sequencer_continue(&opts); | |
89 | if (command == ABORT && argc == 1) | |
90 | return !!sequencer_remove_state(&opts); | |
62db5247 | 91 | if (command == MAKE_SCRIPT && argc > 1) |
313a48ea LB |
92 | return !!sequencer_make_script(stdout, argc, argv, flags); |
93 | if ((command == SHORTEN_OIDS || command == EXPAND_OIDS) && argc == 1) | |
94 | return !!transform_todos(flags); | |
94399949 JS |
95 | if (command == CHECK_TODO_LIST && argc == 1) |
96 | return !!check_todo_list(); | |
d4ed5d77 AG |
97 | if (command == SKIP_UNNECESSARY_PICKS && argc == 1) { |
98 | struct object_id oid; | |
99 | int ret = skip_unnecessary_picks(&oid); | |
100 | ||
101 | if (!ret) | |
102 | puts(oid_to_hex(&oid)); | |
103 | return !!ret; | |
104 | } | |
c44a4c65 JS |
105 | if (command == REARRANGE_SQUASH && argc == 1) |
106 | return !!rearrange_squash(); | |
0cce4a27 LB |
107 | if (command == ADD_EXEC && argc == 2) |
108 | return !!sequencer_add_exec_commands(argv[1]); | |
145e05ac | 109 | if (command == APPEND_TODO_HELP && argc == 1) |
a9f5476f | 110 | return !!append_todo_help_to_file(0, keep_empty); |
64a43cbd AG |
111 | if (command == EDIT_TODO && argc == 1) |
112 | return !!edit_todo_list(flags); | |
2c58483a AG |
113 | if (command == PREPARE_BRANCH && argc == 2) |
114 | return !!prepare_branch_to_be_rebased(&opts, argv[1]); | |
4df66c40 AG |
115 | if (command == CHECKOUT_ONTO && argc == 4) |
116 | return !!checkout_onto(&opts, argv[1], argv[2], argv[3]); | |
b97e1873 AG |
117 | if (command == COMPLETE_ACTION && argc == 6) |
118 | return !!complete_action(&opts, flags, argv[1], argv[2], argv[3], | |
119 | argv[4], argv[5], autosquash); | |
120 | ||
4557f1ad JS |
121 | usage_with_options(builtin_rebase_helper_usage, options); |
122 | } |