@@ -2032,13 +2032,24 @@ static void record_in_rewritten(struct object_id *oid,
2032
2032
flush_rewritten_pending ();
2033
2033
}
2034
2034
2035
+ static int should_edit (struct replay_opts * opts ) {
2036
+ if (opts -> edit < 0 )
2037
+ /*
2038
+ * Note that we only handle the case of non-conflicted
2039
+ * commits; continue_single_pick() handles the conflicted
2040
+ * commits itself instead of calling this function.
2041
+ */
2042
+ return (opts -> action == REPLAY_REVERT && isatty (0 )) ? 1 : 0 ;
2043
+ return opts -> edit ;
2044
+ }
2045
+
2035
2046
static int do_pick_commit (struct repository * r ,
2036
2047
struct todo_item * item ,
2037
2048
struct replay_opts * opts ,
2038
2049
int final_fixup , int * check_todo )
2039
2050
{
2040
- unsigned int flags = opts -> edit ? EDIT_MSG : 0 ;
2041
- const char * msg_file = opts -> edit ? NULL : git_path_merge_msg (r );
2051
+ unsigned int flags = should_edit ( opts ) ? EDIT_MSG : 0 ;
2052
+ const char * msg_file = should_edit ( opts ) ? NULL : git_path_merge_msg (r );
2042
2053
struct object_id head ;
2043
2054
struct commit * base , * next , * parent ;
2044
2055
const char * base_label , * next_label ;
@@ -3283,9 +3294,9 @@ static int save_opts(struct replay_opts *opts)
3283
3294
if (opts -> no_commit )
3284
3295
res |= git_config_set_in_file_gently (opts_file ,
3285
3296
"options.no-commit" , "true" );
3286
- if (opts -> edit )
3287
- res |= git_config_set_in_file_gently (opts_file ,
3288
- "options. edit" , "true" );
3297
+ if (opts -> edit >= 0 )
3298
+ res |= git_config_set_in_file_gently (opts_file , "options.edit" ,
3299
+ opts -> edit ? "true" : "false " );
3289
3300
if (opts -> allow_empty )
3290
3301
res |= git_config_set_in_file_gently (opts_file ,
3291
3302
"options.allow-empty" , "true" );
@@ -4259,7 +4270,7 @@ static int pick_commits(struct repository *r,
4259
4270
prev_reflog_action = xstrdup (getenv (GIT_REFLOG_ACTION ));
4260
4271
if (opts -> allow_ff )
4261
4272
assert (!(opts -> signoff || opts -> no_commit ||
4262
- opts -> record_origin || opts -> edit ||
4273
+ opts -> record_origin || should_edit ( opts ) ||
4263
4274
opts -> committer_date_is_author_date ||
4264
4275
opts -> ignore_date ));
4265
4276
if (read_and_refresh_cache (r , opts ))
@@ -4552,14 +4563,33 @@ static int pick_commits(struct repository *r,
4552
4563
return sequencer_remove_state (opts );
4553
4564
}
4554
4565
4555
- static int continue_single_pick (struct repository * r )
4566
+ static int continue_single_pick (struct repository * r , struct replay_opts * opts )
4556
4567
{
4557
- const char * argv [] = { "commit" , NULL };
4568
+ struct strvec argv = STRVEC_INIT ;
4569
+ int ret ;
4558
4570
4559
4571
if (!refs_ref_exists (get_main_ref_store (r ), "CHERRY_PICK_HEAD" ) &&
4560
4572
!refs_ref_exists (get_main_ref_store (r ), "REVERT_HEAD" ))
4561
4573
return error (_ ("no cherry-pick or revert in progress" ));
4562
- return run_command_v_opt (argv , RUN_GIT_CMD );
4574
+
4575
+ strvec_push (& argv , "commit" );
4576
+
4577
+ /*
4578
+ * continue_single_pick() handles the case of recovering from a
4579
+ * conflict. should_edit() doesn't handle that case; for a conflict,
4580
+ * we want to edit if the user asked for it, or if they didn't specify
4581
+ * and stdin is a tty.
4582
+ */
4583
+ if (!opts -> edit || (opts -> edit < 0 && !isatty (0 )))
4584
+ /*
4585
+ * Include --cleanup=strip as well because we don't want the
4586
+ * "# Conflicts:" messages.
4587
+ */
4588
+ strvec_pushl (& argv , "--no-edit" , "--cleanup=strip" , NULL );
4589
+
4590
+ ret = run_command_v_opt (argv .v , RUN_GIT_CMD );
4591
+ strvec_clear (& argv );
4592
+ return ret ;
4563
4593
}
4564
4594
4565
4595
static int commit_staged_changes (struct repository * r ,
@@ -4729,7 +4759,7 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
4729
4759
goto release_todo_list ;
4730
4760
}
4731
4761
} else if (!file_exists (get_todo_path (opts )))
4732
- return continue_single_pick (r );
4762
+ return continue_single_pick (r , opts );
4733
4763
else if ((res = read_populate_todo (r , & todo_list , opts )))
4734
4764
goto release_todo_list ;
4735
4765
@@ -4738,7 +4768,7 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
4738
4768
if (refs_ref_exists (get_main_ref_store (r ),
4739
4769
"CHERRY_PICK_HEAD" ) ||
4740
4770
refs_ref_exists (get_main_ref_store (r ), "REVERT_HEAD" )) {
4741
- res = continue_single_pick (r );
4771
+ res = continue_single_pick (r , opts );
4742
4772
if (res )
4743
4773
goto release_todo_list ;
4744
4774
}
0 commit comments