e1460136f549d4b5640ed5e081bc55509f91fdd5
1#include "builtin.h"
2#include "cache.h"
3#include "config.h"
4#include "parse-options.h"
5#include "sequencer.h"
6#include "rebase-interactive.h"
7
8static const char * const builtin_rebase_helper_usage[] = {
9 N_("git rebase--helper [<options>]"),
10 NULL
11};
12
13int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
14{
15 struct replay_opts opts = REPLAY_OPTS_INIT;
16 unsigned flags = 0, keep_empty = 0, rebase_merges = 0, autosquash = 0;
17 int abbreviate_commands = 0, rebase_cousins = -1;
18 enum {
19 CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
20 CHECK_TODO_LIST, REARRANGE_SQUASH, ADD_EXEC, EDIT_TODO, PREPARE_BRANCH,
21 COMPLETE_ACTION
22 } command = 0;
23 struct option options[] = {
24 OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")),
25 OPT_BOOL(0, "keep-empty", &keep_empty, N_("keep empty commits")),
26 OPT_BOOL(0, "allow-empty-message", &opts.allow_empty_message,
27 N_("allow commits with empty messages")),
28 OPT_BOOL(0, "rebase-merges", &rebase_merges, N_("rebase merge commits")),
29 OPT_BOOL(0, "rebase-cousins", &rebase_cousins,
30 N_("keep original branch points of cousins")),
31 OPT_BOOL(0, "autosquash", &autosquash,
32 N_("move commits that begin with squash!/fixup!")),
33 OPT__VERBOSE(&opts.verbose, N_("be verbose")),
34 OPT_CMDMODE(0, "continue", &command, N_("continue rebase"),
35 CONTINUE),
36 OPT_CMDMODE(0, "abort", &command, N_("abort rebase"),
37 ABORT),
38 OPT_CMDMODE(0, "make-script", &command,
39 N_("make rebase script"), MAKE_SCRIPT),
40 OPT_CMDMODE(0, "shorten-ids", &command,
41 N_("shorten commit ids in the todo list"), SHORTEN_OIDS),
42 OPT_CMDMODE(0, "expand-ids", &command,
43 N_("expand commit ids in the todo list"), EXPAND_OIDS),
44 OPT_CMDMODE(0, "check-todo-list", &command,
45 N_("check the todo list"), CHECK_TODO_LIST),
46 OPT_CMDMODE(0, "rearrange-squash", &command,
47 N_("rearrange fixup/squash lines"), REARRANGE_SQUASH),
48 OPT_CMDMODE(0, "add-exec-commands", &command,
49 N_("insert exec commands in todo list"), ADD_EXEC),
50 OPT_CMDMODE(0, "edit-todo", &command,
51 N_("edit the todo list during an interactive rebase"),
52 EDIT_TODO),
53 OPT_CMDMODE(0, "prepare-branch", &command,
54 N_("prepare the branch to be rebased"), PREPARE_BRANCH),
55 OPT_CMDMODE(0, "complete-action", &command,
56 N_("complete the action"), COMPLETE_ACTION),
57 OPT_END()
58 };
59
60 sequencer_init_config(&opts);
61 git_config_get_bool("rebase.abbreviatecommands", &abbreviate_commands);
62
63 opts.action = REPLAY_INTERACTIVE_REBASE;
64 opts.allow_ff = 1;
65 opts.allow_empty = 1;
66
67 argc = parse_options(argc, argv, NULL, options,
68 builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0);
69
70 flags |= keep_empty ? TODO_LIST_KEEP_EMPTY : 0;
71 flags |= abbreviate_commands ? TODO_LIST_ABBREVIATE_CMDS : 0;
72 flags |= rebase_merges ? TODO_LIST_REBASE_MERGES : 0;
73 flags |= rebase_cousins > 0 ? TODO_LIST_REBASE_COUSINS : 0;
74 flags |= command == SHORTEN_OIDS ? TODO_LIST_SHORTEN_IDS : 0;
75
76 if (rebase_cousins >= 0 && !rebase_merges)
77 warning(_("--[no-]rebase-cousins has no effect without "
78 "--rebase-merges"));
79
80 if (command == CONTINUE && argc == 1)
81 return !!sequencer_continue(&opts);
82 if (command == ABORT && argc == 1)
83 return !!sequencer_remove_state(&opts);
84 if (command == MAKE_SCRIPT && argc > 1)
85 return !!sequencer_make_script(stdout, argc, argv, flags);
86 if ((command == SHORTEN_OIDS || command == EXPAND_OIDS) && argc == 1)
87 return !!transform_todos(flags);
88 if (command == CHECK_TODO_LIST && argc == 1)
89 return !!check_todo_list();
90 if (command == REARRANGE_SQUASH && argc == 1)
91 return !!rearrange_squash();
92 if (command == ADD_EXEC && argc == 2)
93 return !!sequencer_add_exec_commands(argv[1]);
94 if (command == EDIT_TODO && argc == 1)
95 return !!edit_todo_list(flags);
96 if (command == PREPARE_BRANCH && argc == 2)
97 return !!prepare_branch_to_be_rebased(&opts, argv[1]);
98 if (command == COMPLETE_ACTION && argc == 6)
99 return !!complete_action(&opts, flags, argv[1], argv[2], argv[3],
100 argv[4], argv[5], autosquash);
101
102 usage_with_options(builtin_rebase_helper_usage, options);
103}