@@ -97,6 +97,7 @@ struct rebase_options {
9797 int allow_rerere_autoupdate ;
9898 int keep_empty ;
9999 int autosquash ;
100+ char * gpg_sign_opt ;
100101};
101102
102103static int is_interactive (struct rebase_options * opts )
@@ -209,6 +210,15 @@ static int read_basic_state(struct rebase_options *opts)
209210 } else
210211 opts -> allow_rerere_autoupdate = -1 ;
211212
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+
212222 strbuf_release (& buf );
213223
214224 return 0 ;
@@ -297,6 +307,7 @@ static int run_specific_rebase(struct rebase_options *opts)
297307 "--rerere-autoupdate" : "--no-rerere-autoupdate" );
298308 add_var (& script_snippet , "keep_empty" , opts -> keep_empty ? "yes" : "" );
299309 add_var (& script_snippet , "autosquash" , opts -> autosquash ? "t" : "" );
310+ add_var (& script_snippet , "gpg_sign_opt" , opts -> gpg_sign_opt );
300311
301312 switch (opts -> type ) {
302313 case REBASE_AM :
@@ -462,6 +473,13 @@ static int rebase_config(const char *var, const char *value, void *data)
462473 return 0 ;
463474 }
464475
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+
465483 return git_default_config (var , value , data );
466484}
467485
@@ -555,6 +573,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
555573 int committer_date_is_author_date = 0 ;
556574 int ignore_date = 0 ;
557575 int ignore_whitespace = 0 ;
576+ const char * gpg_sign = NULL ;
558577 struct option builtin_rebase_options [] = {
559578 OPT_STRING (0 , "onto" , & options .onto_name ,
560579 N_ ("revision" ),
@@ -619,6 +638,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
619638 OPT_BOOL (0 , "autosquash" , & options .autosquash ,
620639 N_ ("move commits that begin with "
621640 "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 ) "" },
622644 OPT_END (),
623645 };
624646
@@ -821,6 +843,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
821843 if (options .keep_empty )
822844 imply_interactive (& options , "--keep-empty" );
823845
846+ if (gpg_sign ) {
847+ free (options .gpg_sign_opt );
848+ options .gpg_sign_opt = xstrfmt ("-S%s" , gpg_sign );
849+ }
850+
824851 switch (options .type ) {
825852 case REBASE_MERGE :
826853 case REBASE_INTERACTIVE :
@@ -1046,5 +1073,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
10461073cleanup :
10471074 strbuf_release (& revisions );
10481075 free (options .head_name );
1076+ free (options .gpg_sign_opt );
10491077 return ret ;
10501078}
0 commit comments