@@ -983,7 +983,8 @@ static int run_git_commit(const char *defmsg,
983
983
984
984
cmd .git_cmd = 1 ;
985
985
986
- if (is_rebase_i (opts ) && read_env_script (& cmd .env_array )) {
986
+ if (is_rebase_i (opts ) && !(!defmsg && (flags & AMEND_MSG )) &&
987
+ read_env_script (& cmd .env_array )) {
987
988
const char * gpg_opt = gpg_sign_opt_quoted (opts );
988
989
989
990
return error (_ (staged_changes_advice ),
@@ -3739,10 +3740,9 @@ static struct commit *lookup_label(const char *label, int len,
3739
3740
static int do_merge (struct repository * r ,
3740
3741
struct commit * commit ,
3741
3742
const char * arg , int arg_len ,
3742
- int flags , struct replay_opts * opts )
3743
+ int flags , int * check_todo , struct replay_opts * opts )
3743
3744
{
3744
- int run_commit_flags = (flags & TODO_EDIT_MERGE_MSG ) ?
3745
- EDIT_MSG | VERIFY_MSG : 0 ;
3745
+ int run_commit_flags = 0 ;
3746
3746
struct strbuf ref_name = STRBUF_INIT ;
3747
3747
struct commit * head_commit , * merge_commit , * i ;
3748
3748
struct commit_list * bases , * j , * reversed = NULL ;
@@ -3816,6 +3816,45 @@ static int do_merge(struct repository *r,
3816
3816
goto leave_merge ;
3817
3817
}
3818
3818
3819
+ /*
3820
+ * If HEAD is not identical to the first parent of the original merge
3821
+ * commit, we cannot fast-forward.
3822
+ */
3823
+ can_fast_forward = opts -> allow_ff && commit && commit -> parents &&
3824
+ oideq (& commit -> parents -> item -> object .oid ,
3825
+ & head_commit -> object .oid );
3826
+
3827
+ /*
3828
+ * If any merge head is different from the original one, we cannot
3829
+ * fast-forward.
3830
+ */
3831
+ if (can_fast_forward ) {
3832
+ struct commit_list * p = commit -> parents -> next ;
3833
+
3834
+ for (j = to_merge ; j && p ; j = j -> next , p = p -> next )
3835
+ if (!oideq (& j -> item -> object .oid ,
3836
+ & p -> item -> object .oid )) {
3837
+ can_fast_forward = 0 ;
3838
+ break ;
3839
+ }
3840
+ /*
3841
+ * If the number of merge heads differs from the original merge
3842
+ * commit, we cannot fast-forward.
3843
+ */
3844
+ if (j || p )
3845
+ can_fast_forward = 0 ;
3846
+ }
3847
+
3848
+ if (can_fast_forward ) {
3849
+ rollback_lock_file (& lock );
3850
+ ret = fast_forward_to (r , & commit -> object .oid ,
3851
+ & head_commit -> object .oid , 0 , opts );
3852
+ if (flags & TODO_EDIT_MERGE_MSG )
3853
+ goto fast_forward_edit ;
3854
+
3855
+ goto leave_merge ;
3856
+ }
3857
+
3819
3858
if (commit ) {
3820
3859
const char * encoding = get_commit_output_encoding ();
3821
3860
const char * message = logmsg_reencode (commit , NULL , encoding );
@@ -3865,46 +3904,6 @@ static int do_merge(struct repository *r,
3865
3904
}
3866
3905
}
3867
3906
3868
- /*
3869
- * If HEAD is not identical to the first parent of the original merge
3870
- * commit, we cannot fast-forward.
3871
- */
3872
- can_fast_forward = opts -> allow_ff && commit && commit -> parents &&
3873
- oideq (& commit -> parents -> item -> object .oid ,
3874
- & head_commit -> object .oid );
3875
-
3876
- /*
3877
- * If any merge head is different from the original one, we cannot
3878
- * fast-forward.
3879
- */
3880
- if (can_fast_forward ) {
3881
- struct commit_list * p = commit -> parents -> next ;
3882
-
3883
- for (j = to_merge ; j && p ; j = j -> next , p = p -> next )
3884
- if (!oideq (& j -> item -> object .oid ,
3885
- & p -> item -> object .oid )) {
3886
- can_fast_forward = 0 ;
3887
- break ;
3888
- }
3889
- /*
3890
- * If the number of merge heads differs from the original merge
3891
- * commit, we cannot fast-forward.
3892
- */
3893
- if (j || p )
3894
- can_fast_forward = 0 ;
3895
- }
3896
-
3897
- if (can_fast_forward ) {
3898
- rollback_lock_file (& lock );
3899
- ret = fast_forward_to (r , & commit -> object .oid ,
3900
- & head_commit -> object .oid , 0 , opts );
3901
- if (flags & TODO_EDIT_MERGE_MSG ) {
3902
- run_commit_flags |= AMEND_MSG ;
3903
- goto fast_forward_edit ;
3904
- }
3905
- goto leave_merge ;
3906
- }
3907
-
3908
3907
if (strategy || to_merge -> next ) {
3909
3908
/* Octopus merge */
3910
3909
struct child_process cmd = CHILD_PROCESS_INIT ;
@@ -3935,7 +3934,10 @@ static int do_merge(struct repository *r,
3935
3934
strvec_pushf (& cmd .args ,
3936
3935
"-X%s" , opts -> xopts [k ]);
3937
3936
}
3938
- strvec_push (& cmd .args , "--no-edit" );
3937
+ if (!(flags & TODO_EDIT_MERGE_MSG ))
3938
+ strvec_push (& cmd .args , "--no-edit" );
3939
+ else
3940
+ strvec_push (& cmd .args , "--edit" );
3939
3941
strvec_push (& cmd .args , "--no-ff" );
3940
3942
strvec_push (& cmd .args , "--no-log" );
3941
3943
strvec_push (& cmd .args , "--no-stat" );
@@ -4035,10 +4037,17 @@ static int do_merge(struct repository *r,
4035
4037
* value (a negative one would indicate that the `merge`
4036
4038
* command needs to be rescheduled).
4037
4039
*/
4038
- fast_forward_edit :
4039
4040
ret = !!run_git_commit (git_path_merge_msg (r ), opts ,
4040
4041
run_commit_flags );
4041
4042
4043
+ if (!ret && flags & TODO_EDIT_MERGE_MSG ) {
4044
+ fast_forward_edit :
4045
+ * check_todo = 1 ;
4046
+ run_commit_flags |= AMEND_MSG | EDIT_MSG | VERIFY_MSG ;
4047
+ ret = !!run_git_commit (NULL , opts , run_commit_flags );
4048
+ }
4049
+
4050
+
4042
4051
leave_merge :
4043
4052
strbuf_release (& ref_name );
4044
4053
rollback_lock_file (& lock );
@@ -4405,9 +4414,8 @@ static int pick_commits(struct repository *r,
4405
4414
if ((res = do_reset (r , arg , item -> arg_len , opts )))
4406
4415
reschedule = 1 ;
4407
4416
} else if (item -> command == TODO_MERGE ) {
4408
- if ((res = do_merge (r , item -> commit ,
4409
- arg , item -> arg_len ,
4410
- item -> flags , opts )) < 0 )
4417
+ if ((res = do_merge (r , item -> commit , arg , item -> arg_len ,
4418
+ item -> flags , & check_todo , opts )) < 0 )
4411
4419
reschedule = 1 ;
4412
4420
else if (item -> commit )
4413
4421
record_in_rewritten (& item -> commit -> object .oid ,
0 commit comments