builtin rebase: support --signoff

This commit adds support for `--signoff` which is used to add a `Signed-off-by` trailer to all the rebased commits. The actual handling is left to the rebase backends. Signed-off-by: Pratik Karki <predatoramigo@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pratik Karki committed Sep 4, 2018 at 14:59 UTC 73d51ed0a59f561e55ab1b649eb073e7dddf8b88
1 file changed +17
builtin/rebase.c
+17
@@ -93,6 +93,7 @@ struct rebase_options {
93 } flags;
94 struct strbuf git_am_opt;
95 const char *action;
96 + int signoff;
97 };
98
99 static int is_interactive(struct rebase_options *opts)
@@ -168,6 +169,11 @@ static int read_basic_state(struct rebase_options *opts)
169 if (file_exists(state_dir_path("verbose", opts)))
170 opts->flags |= REBASE_VERBOSE;
171
172 + if (file_exists(state_dir_path("signoff", opts))) {
173 + opts->signoff = 1;
174 + opts->flags |= REBASE_FORCE;
175 + }
176 +
177 strbuf_release(&buf);
178
179 return 0;
@@ -249,6 +255,7 @@ static int run_specific_rebase(struct rebase_options *opts)
255 if (opts->switch_to)
256 add_var(&script_snippet, "switch_to", opts->switch_to);
257 add_var(&script_snippet, "action", opts->action ? opts->action : "");
258 + add_var(&script_snippet, "signoff", opts->signoff ? "--signoff" : "");
259
260 switch (opts->type) {
261 case REBASE_AM:
@@ -513,6 +520,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
520 {OPTION_NEGBIT, 'n', "no-stat", &options.flags, NULL,
521 N_("do not show diffstat of what changed upstream"),
522 PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },
523 + OPT_BOOL(0, "signoff", &options.signoff,
524 + N_("add a Signed-off-by: line to each commit")),
525 OPT_BIT('f', "force-rebase", &options.flags,
526 N_("cherry-pick all commits, even if unchanged"),
527 REBASE_FORCE),
@@ -745,6 +754,14 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
754 break;
755 }
756
757 + if (options.signoff) {
758 + if (options.type == REBASE_PRESERVE_MERGES)
759 + die("cannot combine '--signoff' with "
760 + "'--preserve-merges'");
761 + strbuf_addstr(&options.git_am_opt, " --signoff");
762 + options.flags |= REBASE_FORCE;
763 + }
764 +
765 if (!options.root) {
766 if (argc < 1)
767 die("TODO: handle @{upstream}");