builtin rebase: support `--gpg-sign` option

This commit introduces support for `--gpg-sign` option which is used to GPG-sign commits. 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 15:00 UTC 12026a412c8a98f7d7050ac6473e1aa4193c4800
1 file changed +28
builtin/rebase.c
+28
@@ -97,6 +97,7 @@ struct rebase_options {
97 int allow_rerere_autoupdate;
98 int keep_empty;
99 int autosquash;
100 + char *gpg_sign_opt;
101 };
102
103 static int is_interactive(struct rebase_options *opts)
@@ -209,6 +210,15 @@ static int read_basic_state(struct rebase_options *opts)
210 } else
211 opts->allow_rerere_autoupdate = -1;
212
213 + if (file_exists(state_dir_path("gpg_sign_opt", opts))) {
214 + strbuf_reset(&buf);
215 + if (read_one(state_dir_path("gpg_sign_opt", opts),
216 + &buf))
217 + return -1;
218 + free(opts->gpg_sign_opt);
219 + opts->gpg_sign_opt = xstrdup(buf.buf);
220 + }
221 +
222 strbuf_release(&buf);
223
224 return 0;
@@ -297,6 +307,7 @@ static int run_specific_rebase(struct rebase_options *opts)
307 "--rerere-autoupdate" : "--no-rerere-autoupdate");
308 add_var(&script_snippet, "keep_empty", opts->keep_empty ? "yes" : "");
309 add_var(&script_snippet, "autosquash", opts->autosquash ? "t" : "");
310 + add_var(&script_snippet, "gpg_sign_opt", opts->gpg_sign_opt);
311
312 switch (opts->type) {
313 case REBASE_AM:
@@ -462,6 +473,13 @@ static int rebase_config(const char *var, const char *value, void *data)
473 return 0;
474 }
475
476 + if (!strcmp(var, "commit.gpgsign")) {
477 + free(opts->gpg_sign_opt);
478 + opts->gpg_sign_opt = git_config_bool(var, value) ?
479 + xstrdup("-S") : NULL;
480 + return 0;
481 + }
482 +
483 return git_default_config(var, value, data);
484 }
485
@@ -555,6 +573,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
573 int committer_date_is_author_date = 0;
574 int ignore_date = 0;
575 int ignore_whitespace = 0;
576 + const char *gpg_sign = NULL;
577 struct option builtin_rebase_options[] = {
578 OPT_STRING(0, "onto", &options.onto_name,
579 N_("revision"),
@@ -619,6 +638,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
638 OPT_BOOL(0, "autosquash", &options.autosquash,
639 N_("move commits that begin with "
640 "squash!/fixup! under -i")),
641 + { OPTION_STRING, 'S', "gpg-sign", &gpg_sign, N_("key-id"),
642 + N_("GPG-sign commits"),
643 + PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
644 OPT_END(),
645 };
646
@@ -821,6 +843,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
843 if (options.keep_empty)
844 imply_interactive(&options, "--keep-empty");
845
846 + if (gpg_sign) {
847 + free(options.gpg_sign_opt);
848 + options.gpg_sign_opt = xstrfmt("-S%s", gpg_sign);
849 + }
850 +
851 switch (options.type) {
852 case REBASE_MERGE:
853 case REBASE_INTERACTIVE:
@@ -1046,5 +1073,6 @@ run_rebase:
1073 cleanup:
1074 strbuf_release(&revisions);
1075 free(options.head_name);
1076 + free(options.gpg_sign_opt);
1077 return ret;
1078 }