]> git.ipfire.org Git - thirdparty/git.git/blob - builtin/rebase--helper.c
rebase -i -x: add exec commands via the rebase--helper
[thirdparty/git.git] / builtin / rebase--helper.c
1 #include "builtin.h"
2 #include "cache.h"
3 #include "config.h"
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;
15 unsigned flags = 0, keep_empty = 0;
16 enum {
17 CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
18 CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH,
19 ADD_EXEC
20 } command = 0;
21 struct option options[] = {
22 OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")),
23 OPT_BOOL(0, "keep-empty", &keep_empty, N_("keep empty commits")),
24 OPT_CMDMODE(0, "continue", &command, N_("continue rebase"),
25 CONTINUE),
26 OPT_CMDMODE(0, "abort", &command, N_("abort rebase"),
27 ABORT),
28 OPT_CMDMODE(0, "make-script", &command,
29 N_("make rebase script"), MAKE_SCRIPT),
30 OPT_CMDMODE(0, "shorten-ids", &command,
31 N_("shorten commit ids in the todo list"), SHORTEN_OIDS),
32 OPT_CMDMODE(0, "expand-ids", &command,
33 N_("expand commit ids in the todo list"), EXPAND_OIDS),
34 OPT_CMDMODE(0, "check-todo-list", &command,
35 N_("check the todo list"), CHECK_TODO_LIST),
36 OPT_CMDMODE(0, "skip-unnecessary-picks", &command,
37 N_("skip unnecessary picks"), SKIP_UNNECESSARY_PICKS),
38 OPT_CMDMODE(0, "rearrange-squash", &command,
39 N_("rearrange fixup/squash lines"), REARRANGE_SQUASH),
40 OPT_CMDMODE(0, "add-exec-commands", &command,
41 N_("insert exec commands in todo list"), ADD_EXEC),
42 OPT_END()
43 };
44
45 git_config(git_default_config, NULL);
46
47 opts.action = REPLAY_INTERACTIVE_REBASE;
48 opts.allow_ff = 1;
49 opts.allow_empty = 1;
50
51 argc = parse_options(argc, argv, NULL, options,
52 builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0);
53
54 flags |= keep_empty ? TODO_LIST_KEEP_EMPTY : 0;
55 flags |= command == SHORTEN_OIDS ? TODO_LIST_SHORTEN_IDS : 0;
56
57 if (command == CONTINUE && argc == 1)
58 return !!sequencer_continue(&opts);
59 if (command == ABORT && argc == 1)
60 return !!sequencer_remove_state(&opts);
61 if (command == MAKE_SCRIPT && argc > 1)
62 return !!sequencer_make_script(stdout, argc, argv, flags);
63 if ((command == SHORTEN_OIDS || command == EXPAND_OIDS) && argc == 1)
64 return !!transform_todos(flags);
65 if (command == CHECK_TODO_LIST && argc == 1)
66 return !!check_todo_list();
67 if (command == SKIP_UNNECESSARY_PICKS && argc == 1)
68 return !!skip_unnecessary_picks();
69 if (command == REARRANGE_SQUASH && argc == 1)
70 return !!rearrange_squash();
71 if (command == ADD_EXEC && argc == 2)
72 return !!sequencer_add_exec_commands(argv[1]);
73 usage_with_options(builtin_rebase_helper_usage, options);
74 }