@@ -15,7 +15,7 @@ use crate::core::formatting::Pluralize;
1515use crate :: core:: repo_ext:: RepoExt ;
1616use crate :: git:: {
1717 BranchType , CategorizedReferenceName , GitRunInfo , MaybeZeroOid , NonZeroOid , ReferenceName ,
18- Repo , ResolvedReferenceInfo ,
18+ Repo , ResolvedReferenceInfo , SignOption ,
1919} ;
2020use crate :: util:: { ExitCode , EyreExitOr } ;
2121
@@ -436,8 +436,8 @@ mod in_memory {
436436 use crate :: core:: rewrite:: move_branches;
437437 use crate :: core:: rewrite:: plan:: { OidOrLabel , RebaseCommand , RebasePlan } ;
438438 use crate :: git:: {
439- AmendFastOptions , CherryPickFastOptions , CreateCommitFastError , GitRunInfo , MaybeZeroOid ,
440- NonZeroOid , Repo ,
439+ self , AmendFastOptions , CherryPickFastOptions , CreateCommitFastError , GitRunInfo ,
440+ MaybeZeroOid , NonZeroOid , Repo ,
441441 } ;
442442 use crate :: util:: EyreExitOr ;
443443
@@ -500,6 +500,7 @@ mod in_memory {
500500 force_on_disk : _,
501501 resolve_merge_conflicts : _, // May be needed once we can resolve merge conflicts in memory.
502502 check_out_commit_options : _, // Caller is responsible for checking out to new HEAD.
503+ sign_option,
503504 } = options;
504505
505506 let mut current_oid = rebase_plan. first_dest_oid ;
@@ -537,6 +538,8 @@ mod in_memory {
537538 . count ( ) ;
538539 let ( effects, progress) = effects. start_operation ( OperationType :: RebaseCommits ) ;
539540
541+ let signer = git:: get_signer ( repo, sign_option) ?;
542+
540543 for command in rebase_plan. commands . iter ( ) {
541544 match command {
542545 RebaseCommand :: CreateLabel { label_name } => {
@@ -670,12 +673,12 @@ mod in_memory {
670673 ) ;
671674 rebased_commit_oid = Some (
672675 repo. create_commit (
673- None ,
674676 & commit_author,
675677 & committer_signature,
676678 commit_message,
677679 & commit_tree,
678680 vec ! [ & current_commit] ,
681+ signer. as_deref ( ) ,
679682 )
680683 . wrap_err ( "Applying rebased commit" ) ?,
681684 ) ;
@@ -802,12 +805,12 @@ mod in_memory {
802805 } ;
803806 let rebased_commit_oid = repo
804807 . create_commit (
805- None ,
806808 & replacement_commit. get_author ( ) ,
807809 & committer_signature,
808810 replacement_commit_message,
809811 & replacement_tree,
810812 parents. iter ( ) . collect ( ) ,
813+ signer. as_deref ( ) ,
811814 )
812815 . wrap_err ( "Applying rebased commit" ) ?;
813816
@@ -911,6 +914,7 @@ mod in_memory {
911914 force_on_disk : _,
912915 resolve_merge_conflicts : _,
913916 check_out_commit_options,
917+ sign_option : _,
914918 } = options;
915919
916920 for new_oid in rewritten_oids. values ( ) {
@@ -996,6 +1000,7 @@ mod on_disk {
9961000 force_on_disk : _,
9971001 resolve_merge_conflicts : _,
9981002 check_out_commit_options : _, // Checkout happens after rebase has concluded.
1003+ sign_option,
9991004 } = options;
10001005
10011006 let ( effects, _progress) = effects. start_operation ( OperationType :: InitializeRebase ) ;
@@ -1113,6 +1118,16 @@ mod on_disk {
11131118 )
11141119 } ) ?;
11151120
1121+ let gpg_sign_opt_path = rebase_state_dir. join ( "gpg_sign_opt" ) ;
1122+ if let Some ( sign_flag) = sign_option. as_rebase_flag ( repo) ? {
1123+ std:: fs:: write ( & gpg_sign_opt_path, sign_flag) . wrap_err_with ( || {
1124+ format ! (
1125+ "Writing `gpg_sign_opt` to: {:?}" ,
1126+ gpg_sign_opt_path. as_path( )
1127+ )
1128+ } ) ?;
1129+ }
1130+
11161131 let end_file_path = rebase_state_dir. join ( "end" ) ;
11171132 std:: fs:: write (
11181133 end_file_path. as_path ( ) ,
@@ -1172,6 +1187,7 @@ mod on_disk {
11721187 force_on_disk : _,
11731188 resolve_merge_conflicts : _,
11741189 check_out_commit_options : _, // Checkout happens after rebase has concluded.
1190+ sign_option : _,
11751191 } = options;
11761192
11771193 match write_rebase_state_to_disk ( effects, git_run_info, repo, rebase_plan, options) ? {
@@ -1216,6 +1232,9 @@ pub struct ExecuteRebasePlanOptions {
12161232
12171233 /// If `HEAD` was moved, the options for checking out the new `HEAD` commit.
12181234 pub check_out_commit_options : CheckOutCommitOptions ,
1235+
1236+ /// GPG-sign commits.
1237+ pub sign_option : SignOption ,
12191238}
12201239
12211240/// The result of executing a rebase plan.
@@ -1261,6 +1280,7 @@ pub fn execute_rebase_plan(
12611280 force_on_disk,
12621281 resolve_merge_conflicts,
12631282 check_out_commit_options : _,
1283+ sign_option : _,
12641284 } = options;
12651285
12661286 if !force_on_disk {
0 commit comments