@@ -147,6 +147,11 @@ static GIT_PATH_FUNC(rebase_path_amend, "rebase-merge/amend")
147
147
* the commit object name of the corresponding patch.
148
148
*/
149
149
static GIT_PATH_FUNC (rebase_path_stopped_sha , "rebase-merge/stopped-sha" )
150
+ /*
151
+ * When we stop for the user to resolve conflicts this file contains
152
+ * the patch of the commit that is being picked.
153
+ */
154
+ static GIT_PATH_FUNC (rebase_path_patch , "rebase-merge/patch" )
150
155
/*
151
156
* For the post-rewrite hook, we make a list of rewritten commits and
152
157
* their new sha1s. The rewritten-pending list keeps the sha1s of
@@ -3401,7 +3406,8 @@ int sequencer_skip(struct repository *r, struct replay_opts *opts)
3401
3406
return -1 ;
3402
3407
}
3403
3408
3404
- static int save_todo (struct todo_list * todo_list , struct replay_opts * opts )
3409
+ static int save_todo (struct todo_list * todo_list , struct replay_opts * opts ,
3410
+ int reschedule )
3405
3411
{
3406
3412
struct lock_file todo_lock = LOCK_INIT ;
3407
3413
const char * todo_path = get_todo_path (opts );
@@ -3411,7 +3417,7 @@ static int save_todo(struct todo_list *todo_list, struct replay_opts *opts)
3411
3417
* rebase -i writes "git-rebase-todo" without the currently executing
3412
3418
* command, appending it to "done" instead.
3413
3419
*/
3414
- if (is_rebase_i (opts ))
3420
+ if (is_rebase_i (opts ) && ! reschedule )
3415
3421
next ++ ;
3416
3422
3417
3423
fd = hold_lock_file_for_update (& todo_lock , todo_path , 0 );
@@ -3424,7 +3430,7 @@ static int save_todo(struct todo_list *todo_list, struct replay_opts *opts)
3424
3430
if (commit_lock_file (& todo_lock ) < 0 )
3425
3431
return error (_ ("failed to finalize '%s'" ), todo_path );
3426
3432
3427
- if (is_rebase_i (opts ) && next > 0 ) {
3433
+ if (is_rebase_i (opts ) && ! reschedule && next > 0 ) {
3428
3434
const char * done = rebase_path_done ();
3429
3435
int fd = open (done , O_CREAT | O_WRONLY | O_APPEND , 0666 );
3430
3436
int ret = 0 ;
@@ -3505,47 +3511,46 @@ static int make_patch(struct repository *r,
3505
3511
struct commit * commit ,
3506
3512
struct replay_opts * opts )
3507
3513
{
3508
- struct strbuf buf = STRBUF_INIT ;
3509
3514
struct rev_info log_tree_opt ;
3510
3515
const char * subject ;
3511
3516
char hex [GIT_MAX_HEXSZ + 1 ];
3512
3517
int res = 0 ;
3513
3518
3519
+ if (!is_rebase_i (opts ))
3520
+ BUG ("make_patch should only be called when rebasing" );
3521
+
3514
3522
oid_to_hex_r (hex , & commit -> object .oid );
3515
3523
if (write_message (hex , strlen (hex ), rebase_path_stopped_sha (), 1 ) < 0 )
3516
3524
return -1 ;
3517
3525
res |= write_rebase_head (& commit -> object .oid );
3518
3526
3519
- strbuf_addf (& buf , "%s/patch" , get_dir (opts ));
3520
3527
memset (& log_tree_opt , 0 , sizeof (log_tree_opt ));
3521
3528
repo_init_revisions (r , & log_tree_opt , NULL );
3522
3529
log_tree_opt .abbrev = 0 ;
3523
3530
log_tree_opt .diff = 1 ;
3524
3531
log_tree_opt .diffopt .output_format = DIFF_FORMAT_PATCH ;
3525
3532
log_tree_opt .disable_stdin = 1 ;
3526
3533
log_tree_opt .no_commit_id = 1 ;
3527
- log_tree_opt .diffopt .file = fopen (buf . buf , "w" );
3534
+ log_tree_opt .diffopt .file = fopen (rebase_path_patch () , "w" );
3528
3535
log_tree_opt .diffopt .use_color = GIT_COLOR_NEVER ;
3529
3536
if (!log_tree_opt .diffopt .file )
3530
- res |= error_errno (_ ("could not open '%s'" ), buf .buf );
3537
+ res |= error_errno (_ ("could not open '%s'" ),
3538
+ rebase_path_patch ());
3531
3539
else {
3532
3540
res |= log_tree_commit (& log_tree_opt , commit );
3533
3541
fclose (log_tree_opt .diffopt .file );
3534
3542
}
3535
- strbuf_reset (& buf );
3536
3543
3537
- strbuf_addf (& buf , "%s/message" , get_dir (opts ));
3538
- if (!file_exists (buf .buf )) {
3544
+ if (!file_exists (rebase_path_message ())) {
3539
3545
const char * encoding = get_commit_output_encoding ();
3540
3546
const char * commit_buffer = repo_logmsg_reencode (r ,
3541
3547
commit , NULL ,
3542
3548
encoding );
3543
3549
find_commit_subject (commit_buffer , & subject );
3544
- res |= write_message (subject , strlen (subject ), buf . buf , 1 );
3550
+ res |= write_message (subject , strlen (subject ), rebase_path_message () , 1 );
3545
3551
repo_unuse_commit_buffer (r , commit ,
3546
3552
commit_buffer );
3547
3553
}
3548
- strbuf_release (& buf );
3549
3554
release_revisions (& log_tree_opt );
3550
3555
3551
3556
return res ;
@@ -4163,6 +4168,7 @@ static int do_merge(struct repository *r,
4163
4168
if (ret < 0 ) {
4164
4169
error (_ ("could not even attempt to merge '%.*s'" ),
4165
4170
merge_arg_len , arg );
4171
+ unlink (git_path_merge_msg (r ));
4166
4172
goto leave_merge ;
4167
4173
}
4168
4174
/*
@@ -4650,6 +4656,68 @@ N_("Could not execute the todo command\n"
4650
4656
" git rebase --edit-todo\n"
4651
4657
" git rebase --continue\n" );
4652
4658
4659
+ static int pick_one_commit (struct repository * r ,
4660
+ struct todo_list * todo_list ,
4661
+ struct replay_opts * opts ,
4662
+ int * check_todo , int * reschedule )
4663
+ {
4664
+ int res ;
4665
+ struct todo_item * item = todo_list -> items + todo_list -> current ;
4666
+ const char * arg = todo_item_get_arg (todo_list , item );
4667
+ if (is_rebase_i (opts ))
4668
+ opts -> reflog_message = reflog_message (
4669
+ opts , command_to_string (item -> command ), NULL );
4670
+
4671
+ res = do_pick_commit (r , item , opts , is_final_fixup (todo_list ),
4672
+ check_todo );
4673
+ if (is_rebase_i (opts ) && res < 0 ) {
4674
+ /* Reschedule */
4675
+ * reschedule = 1 ;
4676
+ return -1 ;
4677
+ }
4678
+ if (item -> command == TODO_EDIT ) {
4679
+ struct commit * commit = item -> commit ;
4680
+ if (!res ) {
4681
+ if (!opts -> verbose )
4682
+ term_clear_line ();
4683
+ fprintf (stderr , _ ("Stopped at %s... %.*s\n" ),
4684
+ short_commit_name (commit ), item -> arg_len , arg );
4685
+ }
4686
+ return error_with_patch (r , commit ,
4687
+ arg , item -> arg_len , opts , res , !res );
4688
+ }
4689
+ if (is_rebase_i (opts ) && !res )
4690
+ record_in_rewritten (& item -> commit -> object .oid ,
4691
+ peek_command (todo_list , 1 ));
4692
+ if (res && is_fixup (item -> command )) {
4693
+ if (res == 1 )
4694
+ intend_to_amend ();
4695
+ return error_failed_squash (r , item -> commit , opts ,
4696
+ item -> arg_len , arg );
4697
+ } else if (res && is_rebase_i (opts ) && item -> commit ) {
4698
+ int to_amend = 0 ;
4699
+ struct object_id oid ;
4700
+
4701
+ /*
4702
+ * If we are rewording and have either
4703
+ * fast-forwarded already, or are about to
4704
+ * create a new root commit, we want to amend,
4705
+ * otherwise we do not.
4706
+ */
4707
+ if (item -> command == TODO_REWORD &&
4708
+ !repo_get_oid (r , "HEAD" , & oid ) &&
4709
+ (oideq (& item -> commit -> object .oid , & oid ) ||
4710
+ (opts -> have_squash_onto &&
4711
+ oideq (& opts -> squash_onto , & oid ))))
4712
+ to_amend = 1 ;
4713
+
4714
+ return res | error_with_patch (r , item -> commit ,
4715
+ arg , item -> arg_len , opts ,
4716
+ res , to_amend );
4717
+ }
4718
+ return res ;
4719
+ }
4720
+
4653
4721
static int pick_commits (struct repository * r ,
4654
4722
struct todo_list * todo_list ,
4655
4723
struct replay_opts * opts )
@@ -4665,12 +4733,17 @@ static int pick_commits(struct repository *r,
4665
4733
if (read_and_refresh_cache (r , opts ))
4666
4734
return -1 ;
4667
4735
4736
+ unlink (rebase_path_message ());
4737
+ unlink (rebase_path_stopped_sha ());
4738
+ unlink (rebase_path_amend ());
4739
+ unlink (rebase_path_patch ());
4740
+
4668
4741
while (todo_list -> current < todo_list -> nr ) {
4669
4742
struct todo_item * item = todo_list -> items + todo_list -> current ;
4670
4743
const char * arg = todo_item_get_arg (todo_list , item );
4671
4744
int check_todo = 0 ;
4672
4745
4673
- if (save_todo (todo_list , opts ))
4746
+ if (save_todo (todo_list , opts , reschedule ))
4674
4747
return -1 ;
4675
4748
if (is_rebase_i (opts )) {
4676
4749
if (item -> command != TODO_COMMENT ) {
@@ -4688,10 +4761,7 @@ static int pick_commits(struct repository *r,
4688
4761
todo_list -> total_nr ,
4689
4762
opts -> verbose ? "\n" : "\r" );
4690
4763
}
4691
- unlink (rebase_path_message ());
4692
4764
unlink (rebase_path_author_script ());
4693
- unlink (rebase_path_stopped_sha ());
4694
- unlink (rebase_path_amend ());
4695
4765
unlink (git_path_merge_head (r ));
4696
4766
unlink (git_path_auto_merge (r ));
4697
4767
delete_ref (NULL , "REBASE_HEAD" , NULL , REF_NO_DEREF );
@@ -4703,66 +4773,10 @@ static int pick_commits(struct repository *r,
4703
4773
}
4704
4774
}
4705
4775
if (item -> command <= TODO_SQUASH ) {
4706
- if (is_rebase_i (opts ))
4707
- opts -> reflog_message = reflog_message (opts ,
4708
- command_to_string (item -> command ), NULL );
4709
-
4710
- res = do_pick_commit (r , item , opts ,
4711
- is_final_fixup (todo_list ),
4712
- & check_todo );
4713
- if (is_rebase_i (opts ) && res < 0 ) {
4714
- /* Reschedule */
4715
- advise (_ (rescheduled_advice ),
4716
- get_item_line_length (todo_list ,
4717
- todo_list -> current ),
4718
- get_item_line (todo_list ,
4719
- todo_list -> current ));
4720
- todo_list -> current -- ;
4721
- if (save_todo (todo_list , opts ))
4722
- return -1 ;
4723
- }
4724
- if (item -> command == TODO_EDIT ) {
4725
- struct commit * commit = item -> commit ;
4726
- if (!res ) {
4727
- if (!opts -> verbose )
4728
- term_clear_line ();
4729
- fprintf (stderr ,
4730
- _ ("Stopped at %s... %.*s\n" ),
4731
- short_commit_name (commit ),
4732
- item -> arg_len , arg );
4733
- }
4734
- return error_with_patch (r , commit ,
4735
- arg , item -> arg_len , opts , res , !res );
4736
- }
4737
- if (is_rebase_i (opts ) && !res )
4738
- record_in_rewritten (& item -> commit -> object .oid ,
4739
- peek_command (todo_list , 1 ));
4740
- if (res && is_fixup (item -> command )) {
4741
- if (res == 1 )
4742
- intend_to_amend ();
4743
- return error_failed_squash (r , item -> commit , opts ,
4744
- item -> arg_len , arg );
4745
- } else if (res && is_rebase_i (opts ) && item -> commit ) {
4746
- int to_amend = 0 ;
4747
- struct object_id oid ;
4748
-
4749
- /*
4750
- * If we are rewording and have either
4751
- * fast-forwarded already, or are about to
4752
- * create a new root commit, we want to amend,
4753
- * otherwise we do not.
4754
- */
4755
- if (item -> command == TODO_REWORD &&
4756
- !repo_get_oid (r , "HEAD" , & oid ) &&
4757
- (oideq (& item -> commit -> object .oid , & oid ) ||
4758
- (opts -> have_squash_onto &&
4759
- oideq (& opts -> squash_onto , & oid ))))
4760
- to_amend = 1 ;
4761
-
4762
- return res | error_with_patch (r , item -> commit ,
4763
- arg , item -> arg_len , opts ,
4764
- res , to_amend );
4765
- }
4776
+ res = pick_one_commit (r , todo_list , opts , & check_todo ,
4777
+ & reschedule );
4778
+ if (!res && item -> command == TODO_EDIT )
4779
+ return 0 ;
4766
4780
} else if (item -> command == TODO_EXEC ) {
4767
4781
char * end_of_arg = (char * )(arg + item -> arg_len );
4768
4782
int saved = * end_of_arg ;
@@ -4810,22 +4824,19 @@ static int pick_commits(struct repository *r,
4810
4824
get_item_line_length (todo_list ,
4811
4825
todo_list -> current ),
4812
4826
get_item_line (todo_list , todo_list -> current ));
4813
- todo_list -> current -- ;
4814
- if (save_todo (todo_list , opts ))
4827
+ if (save_todo (todo_list , opts , reschedule ))
4815
4828
return -1 ;
4816
4829
if (item -> commit )
4817
- return error_with_patch (r ,
4818
- item -> commit ,
4819
- arg , item -> arg_len ,
4820
- opts , res , 0 );
4830
+ write_rebase_head (& item -> commit -> object .oid );
4821
4831
} else if (is_rebase_i (opts ) && check_todo && !res &&
4822
4832
reread_todo_if_changed (r , todo_list , opts )) {
4823
4833
return -1 ;
4824
4834
}
4825
4835
4826
- todo_list -> current ++ ;
4827
4836
if (res )
4828
4837
return res ;
4838
+
4839
+ todo_list -> current ++ ;
4829
4840
}
4830
4841
4831
4842
if (is_rebase_i (opts )) {
@@ -4978,6 +4989,11 @@ static int commit_staged_changes(struct repository *r,
4978
4989
4979
4990
is_clean = !has_uncommitted_changes (r , 0 );
4980
4991
4992
+ if (!is_clean && !file_exists (rebase_path_message ())) {
4993
+ const char * gpg_opt = gpg_sign_opt_quoted (opts );
4994
+
4995
+ return error (_ (staged_changes_advice ), gpg_opt , gpg_opt );
4996
+ }
4981
4997
if (file_exists (rebase_path_amend ())) {
4982
4998
struct strbuf rev = STRBUF_INIT ;
4983
4999
struct object_id head , to_amend ;
0 commit comments