|
| 1 | +#include "builtin.h" |
| 2 | +#include "cache.h" |
| 3 | +#include "parse-options.h" |
| 4 | +#include "sequencer.h" |
| 5 | + |
| 6 | +static const char * const builtin_rebase_helper_usage[] = { |
| 7 | + N_("git rebase--helper [<options>]"), |
| 8 | + NULL |
| 9 | +}; |
| 10 | + |
| 11 | +int cmd_rebase__helper(int argc, const char **argv, const char *prefix) |
| 12 | +{ |
| 13 | + struct replay_opts opts = REPLAY_OPTS_INIT; |
| 14 | + int keep_empty = 0; |
| 15 | + enum { |
| 16 | + CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_SHA1S, EXPAND_SHA1S, |
| 17 | + CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH |
| 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-sha1s", &command, |
| 29 | + N_("shorten SHA-1s in the todo list"), SHORTEN_SHA1S), |
| 30 | + OPT_CMDMODE(0, "expand-sha1s", &command, |
| 31 | + N_("expand SHA-1s in the todo list"), EXPAND_SHA1S), |
| 32 | + OPT_CMDMODE(0, "check-todo-list", &command, |
| 33 | + N_("check the todo list"), CHECK_TODO_LIST), |
| 34 | + OPT_CMDMODE(0, "skip-unnecessary-picks", &command, |
| 35 | + N_("skip unnecessary picks"), SKIP_UNNECESSARY_PICKS), |
| 36 | + OPT_CMDMODE(0, "rearrange-squash", &command, |
| 37 | + N_("rearrange fixup/squash lines"), REARRANGE_SQUASH), |
| 38 | + OPT_END() |
| 39 | + }; |
| 40 | + |
| 41 | + git_config(git_default_config, NULL); |
| 42 | + |
| 43 | + opts.action = REPLAY_INTERACTIVE_REBASE; |
| 44 | + opts.allow_ff = 1; |
| 45 | + opts.allow_empty = 1; |
| 46 | + |
| 47 | + argc = parse_options(argc, argv, NULL, options, |
| 48 | + builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0); |
| 49 | + |
| 50 | + if (command == CONTINUE && argc == 1) |
| 51 | + return !!sequencer_continue(&opts); |
| 52 | + if (command == ABORT && argc == 1) |
| 53 | + return !!sequencer_remove_state(&opts); |
| 54 | + if (command == MAKE_SCRIPT && argc > 1) |
| 55 | + return !!sequencer_make_script(keep_empty, stdout, argc, argv); |
| 56 | + if (command == SHORTEN_SHA1S && argc == 1) |
| 57 | + return !!transform_todo_ids(1); |
| 58 | + if (command == EXPAND_SHA1S && argc == 1) |
| 59 | + return !!transform_todo_ids(0); |
| 60 | + if (command == CHECK_TODO_LIST && argc == 1) |
| 61 | + return !!check_todo_list(); |
| 62 | + if (command == SKIP_UNNECESSARY_PICKS && argc == 1) |
| 63 | + return !!skip_unnecessary_picks(); |
| 64 | + if (command == REARRANGE_SQUASH && argc == 1) |
| 65 | + return !!rearrange_squash(); |
| 66 | + usage_with_options(builtin_rebase_helper_usage, options); |
| 67 | +} |
0 commit comments