git-rebase: extend --signoff support
[git] / builtin / rebase--helper.c
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         enum {
15                 CONTINUE = 1, ABORT
16         } command = 0;
17         struct option options[] = {
18                 OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")),
19                 OPT_BOOL(0, "signoff", &opts.signoff, N_("add Signed-off-by:")),
20                 OPT_CMDMODE(0, "continue", &command, N_("continue rebase"),
21                                 CONTINUE),
22                 OPT_CMDMODE(0, "abort", &command, N_("abort rebase"),
23                                 ABORT),
24                 OPT_END()
25         };
26
27         git_config(git_default_config, NULL);
28
29         opts.action = REPLAY_INTERACTIVE_REBASE;
30         /* By default, fast-forward is allowed, unless sign-off gets requested.
31          * To differentiate between a command-line --ff and the default,
32          * we set the default to -1 */
33         opts.allow_ff = -1;
34         opts.allow_empty = 1;
35
36         argc = parse_options(argc, argv, NULL, options,
37                         builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0);
38
39         if (opts.allow_ff < 0) {
40                 opts.allow_ff = !opts.signoff;
41         }
42
43         if (command == CONTINUE && argc == 1)
44                 return !!sequencer_continue(&opts);
45         if (command == ABORT && argc == 1)
46                 return !!sequencer_remove_state(&opts);
47         usage_with_options(builtin_rebase_helper_usage, options);
48 }