@@ -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
@@ -3412,7 +3417,8 @@ int sequencer_skip(struct repository *r, struct replay_opts *opts)
3412
3417
return -1 ;
3413
3418
}
3414
3419
3415
- static int save_todo (struct todo_list * todo_list , struct replay_opts * opts )
3420
+ static int save_todo (struct todo_list * todo_list , struct replay_opts * opts ,
3421
+ int reschedule )
3416
3422
{
3417
3423
struct lock_file todo_lock = LOCK_INIT ;
3418
3424
const char * todo_path = get_todo_path (opts );
@@ -3422,7 +3428,7 @@ static int save_todo(struct todo_list *todo_list, struct replay_opts *opts)
3422
3428
* rebase -i writes "git-rebase-todo" without the currently executing
3423
3429
* command, appending it to "done" instead.
3424
3430
*/
3425
- if (is_rebase_i (opts ))
3431
+ if (is_rebase_i (opts ) && ! reschedule )
3426
3432
next ++ ;
3427
3433
3428
3434
fd = hold_lock_file_for_update (& todo_lock , todo_path , 0 );
@@ -3435,7 +3441,7 @@ static int save_todo(struct todo_list *todo_list, struct replay_opts *opts)
3435
3441
if (commit_lock_file (& todo_lock ) < 0 )
3436
3442
return error (_ ("failed to finalize '%s'" ), todo_path );
3437
3443
3438
- if (is_rebase_i (opts ) && next > 0 ) {
3444
+ if (is_rebase_i (opts ) && ! reschedule && next > 0 ) {
3439
3445
const char * done = rebase_path_done ();
3440
3446
int fd = open (done , O_CREAT | O_WRONLY | O_APPEND , 0666 );
3441
3447
int ret = 0 ;
@@ -3516,47 +3522,46 @@ static int make_patch(struct repository *r,
3516
3522
struct commit * commit ,
3517
3523
struct replay_opts * opts )
3518
3524
{
3519
- struct strbuf buf = STRBUF_INIT ;
3520
3525
struct rev_info log_tree_opt ;
3521
3526
const char * subject ;
3522
3527
char hex [GIT_MAX_HEXSZ + 1 ];
3523
3528
int res = 0 ;
3524
3529
3530
+ if (!is_rebase_i (opts ))
3531
+ BUG ("make_patch should only be called when rebasing" );
3532
+
3525
3533
oid_to_hex_r (hex , & commit -> object .oid );
3526
3534
if (write_message (hex , strlen (hex ), rebase_path_stopped_sha (), 1 ) < 0 )
3527
3535
return -1 ;
3528
3536
res |= write_rebase_head (& commit -> object .oid );
3529
3537
3530
- strbuf_addf (& buf , "%s/patch" , get_dir (opts ));
3531
3538
memset (& log_tree_opt , 0 , sizeof (log_tree_opt ));
3532
3539
repo_init_revisions (r , & log_tree_opt , NULL );
3533
3540
log_tree_opt .abbrev = 0 ;
3534
3541
log_tree_opt .diff = 1 ;
3535
3542
log_tree_opt .diffopt .output_format = DIFF_FORMAT_PATCH ;
3536
3543
log_tree_opt .disable_stdin = 1 ;
3537
3544
log_tree_opt .no_commit_id = 1 ;
3538
- log_tree_opt .diffopt .file = fopen (buf . buf , "w" );
3545
+ log_tree_opt .diffopt .file = fopen (rebase_path_patch () , "w" );
3539
3546
log_tree_opt .diffopt .use_color = GIT_COLOR_NEVER ;
3540
3547
if (!log_tree_opt .diffopt .file )
3541
- res |= error_errno (_ ("could not open '%s'" ), buf .buf );
3548
+ res |= error_errno (_ ("could not open '%s'" ),
3549
+ rebase_path_patch ());
3542
3550
else {
3543
3551
res |= log_tree_commit (& log_tree_opt , commit );
3544
3552
fclose (log_tree_opt .diffopt .file );
3545
3553
}
3546
- strbuf_reset (& buf );
3547
3554
3548
- strbuf_addf (& buf , "%s/message" , get_dir (opts ));
3549
- if (!file_exists (buf .buf )) {
3555
+ if (!file_exists (rebase_path_message ())) {
3550
3556
const char * encoding = get_commit_output_encoding ();
3551
3557
const char * commit_buffer = repo_logmsg_reencode (r ,
3552
3558
commit , NULL ,
3553
3559
encoding );
3554
3560
find_commit_subject (commit_buffer , & subject );
3555
- res |= write_message (subject , strlen (subject ), buf . buf , 1 );
3561
+ res |= write_message (subject , strlen (subject ), rebase_path_message () , 1 );
3556
3562
repo_unuse_commit_buffer (r , commit ,
3557
3563
commit_buffer );
3558
3564
}
3559
- strbuf_release (& buf );
3560
3565
release_revisions (& log_tree_opt );
3561
3566
3562
3567
return res ;
@@ -4174,6 +4179,7 @@ static int do_merge(struct repository *r,
4174
4179
if (ret < 0 ) {
4175
4180
error (_ ("could not even attempt to merge '%.*s'" ),
4176
4181
merge_arg_len , arg );
4182
+ unlink (git_path_merge_msg (r ));
4177
4183
goto leave_merge ;
4178
4184
}
4179
4185
/*
@@ -4661,6 +4667,68 @@ N_("Could not execute the todo command\n"
4661
4667
" git rebase --edit-todo\n"
4662
4668
" git rebase --continue\n" );
4663
4669
4670
+ static int pick_one_commit (struct repository * r ,
4671
+ struct todo_list * todo_list ,
4672
+ struct replay_opts * opts ,
4673
+ int * check_todo , int * reschedule )
4674
+ {
4675
+ int res ;
4676
+ struct todo_item * item = todo_list -> items + todo_list -> current ;
4677
+ const char * arg = todo_item_get_arg (todo_list , item );
4678
+ if (is_rebase_i (opts ))
4679
+ opts -> reflog_message = reflog_message (
4680
+ opts , command_to_string (item -> command ), NULL );
4681
+
4682
+ res = do_pick_commit (r , item , opts , is_final_fixup (todo_list ),
4683
+ check_todo );
4684
+ if (is_rebase_i (opts ) && res < 0 ) {
4685
+ /* Reschedule */
4686
+ * reschedule = 1 ;
4687
+ return -1 ;
4688
+ }
4689
+ if (item -> command == TODO_EDIT ) {
4690
+ struct commit * commit = item -> commit ;
4691
+ if (!res ) {
4692
+ if (!opts -> verbose )
4693
+ term_clear_line ();
4694
+ fprintf (stderr , _ ("Stopped at %s... %.*s\n" ),
4695
+ short_commit_name (r , commit ), item -> arg_len , arg );
4696
+ }
4697
+ return error_with_patch (r , commit ,
4698
+ arg , item -> arg_len , opts , res , !res );
4699
+ }
4700
+ if (is_rebase_i (opts ) && !res )
4701
+ record_in_rewritten (& item -> commit -> object .oid ,
4702
+ peek_command (todo_list , 1 ));
4703
+ if (res && is_fixup (item -> command )) {
4704
+ if (res == 1 )
4705
+ intend_to_amend ();
4706
+ return error_failed_squash (r , item -> commit , opts ,
4707
+ item -> arg_len , arg );
4708
+ } else if (res && is_rebase_i (opts ) && item -> commit ) {
4709
+ int to_amend = 0 ;
4710
+ struct object_id oid ;
4711
+
4712
+ /*
4713
+ * If we are rewording and have either
4714
+ * fast-forwarded already, or are about to
4715
+ * create a new root commit, we want to amend,
4716
+ * otherwise we do not.
4717
+ */
4718
+ if (item -> command == TODO_REWORD &&
4719
+ !repo_get_oid (r , "HEAD" , & oid ) &&
4720
+ (oideq (& item -> commit -> object .oid , & oid ) ||
4721
+ (opts -> have_squash_onto &&
4722
+ oideq (& opts -> squash_onto , & oid ))))
4723
+ to_amend = 1 ;
4724
+
4725
+ return res | error_with_patch (r , item -> commit ,
4726
+ arg , item -> arg_len , opts ,
4727
+ res , to_amend );
4728
+ }
4729
+ return res ;
4730
+ }
4731
+
4664
4732
static int pick_commits (struct repository * r ,
4665
4733
struct todo_list * todo_list ,
4666
4734
struct replay_opts * opts )
@@ -4676,12 +4744,17 @@ static int pick_commits(struct repository *r,
4676
4744
if (read_and_refresh_cache (r , opts ))
4677
4745
return -1 ;
4678
4746
4747
+ unlink (rebase_path_message ());
4748
+ unlink (rebase_path_stopped_sha ());
4749
+ unlink (rebase_path_amend ());
4750
+ unlink (rebase_path_patch ());
4751
+
4679
4752
while (todo_list -> current < todo_list -> nr ) {
4680
4753
struct todo_item * item = todo_list -> items + todo_list -> current ;
4681
4754
const char * arg = todo_item_get_arg (todo_list , item );
4682
4755
int check_todo = 0 ;
4683
4756
4684
- if (save_todo (todo_list , opts ))
4757
+ if (save_todo (todo_list , opts , reschedule ))
4685
4758
return -1 ;
4686
4759
if (is_rebase_i (opts )) {
4687
4760
if (item -> command != TODO_COMMENT ) {
@@ -4699,10 +4772,7 @@ static int pick_commits(struct repository *r,
4699
4772
todo_list -> total_nr ,
4700
4773
opts -> verbose ? "\n" : "\r" );
4701
4774
}
4702
- unlink (rebase_path_message ());
4703
4775
unlink (rebase_path_author_script ());
4704
- unlink (rebase_path_stopped_sha ());
4705
- unlink (rebase_path_amend ());
4706
4776
unlink (git_path_merge_head (r ));
4707
4777
unlink (git_path_auto_merge (r ));
4708
4778
delete_ref (NULL , "REBASE_HEAD" , NULL , REF_NO_DEREF );
@@ -4714,66 +4784,10 @@ static int pick_commits(struct repository *r,
4714
4784
}
4715
4785
}
4716
4786
if (item -> command <= TODO_SQUASH ) {
4717
- if (is_rebase_i (opts ))
4718
- opts -> reflog_message = reflog_message (opts ,
4719
- command_to_string (item -> command ), NULL );
4720
-
4721
- res = do_pick_commit (r , item , opts ,
4722
- is_final_fixup (todo_list ),
4723
- & check_todo );
4724
- if (is_rebase_i (opts ) && res < 0 ) {
4725
- /* Reschedule */
4726
- advise (_ (rescheduled_advice ),
4727
- get_item_line_length (todo_list ,
4728
- todo_list -> current ),
4729
- get_item_line (todo_list ,
4730
- todo_list -> current ));
4731
- todo_list -> current -- ;
4732
- if (save_todo (todo_list , opts ))
4733
- return -1 ;
4734
- }
4735
- if (item -> command == TODO_EDIT ) {
4736
- struct commit * commit = item -> commit ;
4737
- if (!res ) {
4738
- if (!opts -> verbose )
4739
- term_clear_line ();
4740
- fprintf (stderr ,
4741
- _ ("Stopped at %s... %.*s\n" ),
4742
- short_commit_name (r , commit ),
4743
- item -> arg_len , arg );
4744
- }
4745
- return error_with_patch (r , commit ,
4746
- arg , item -> arg_len , opts , res , !res );
4747
- }
4748
- if (is_rebase_i (opts ) && !res )
4749
- record_in_rewritten (& item -> commit -> object .oid ,
4750
- peek_command (todo_list , 1 ));
4751
- if (res && is_fixup (item -> command )) {
4752
- if (res == 1 )
4753
- intend_to_amend ();
4754
- return error_failed_squash (r , item -> commit , opts ,
4755
- item -> arg_len , arg );
4756
- } else if (res && is_rebase_i (opts ) && item -> commit ) {
4757
- int to_amend = 0 ;
4758
- struct object_id oid ;
4759
-
4760
- /*
4761
- * If we are rewording and have either
4762
- * fast-forwarded already, or are about to
4763
- * create a new root commit, we want to amend,
4764
- * otherwise we do not.
4765
- */
4766
- if (item -> command == TODO_REWORD &&
4767
- !repo_get_oid (r , "HEAD" , & oid ) &&
4768
- (oideq (& item -> commit -> object .oid , & oid ) ||
4769
- (opts -> have_squash_onto &&
4770
- oideq (& opts -> squash_onto , & oid ))))
4771
- to_amend = 1 ;
4772
-
4773
- return res | error_with_patch (r , item -> commit ,
4774
- arg , item -> arg_len , opts ,
4775
- res , to_amend );
4776
- }
4787
+ res = pick_one_commit (r , todo_list , opts , & check_todo ,
4788
+ & reschedule );
4789
+ if (!res && item -> command == TODO_EDIT )
4790
+ return 0 ;
4777
4791
} else if (item -> command == TODO_EXEC ) {
4778
4792
char * end_of_arg = (char * )(arg + item -> arg_len );
4779
4793
int saved = * end_of_arg ;
@@ -4821,22 +4835,19 @@ static int pick_commits(struct repository *r,
4821
4835
get_item_line_length (todo_list ,
4822
4836
todo_list -> current ),
4823
4837
get_item_line (todo_list , todo_list -> current ));
4824
- todo_list -> current -- ;
4825
- if (save_todo (todo_list , opts ))
4838
+ if (save_todo (todo_list , opts , reschedule ))
4826
4839
return -1 ;
4827
4840
if (item -> commit )
4828
- return error_with_patch (r ,
4829
- item -> commit ,
4830
- arg , item -> arg_len ,
4831
- opts , res , 0 );
4841
+ write_rebase_head (& item -> commit -> object .oid );
4832
4842
} else if (is_rebase_i (opts ) && check_todo && !res &&
4833
4843
reread_todo_if_changed (r , todo_list , opts )) {
4834
4844
return -1 ;
4835
4845
}
4836
4846
4837
- todo_list -> current ++ ;
4838
4847
if (res )
4839
4848
return res ;
4849
+
4850
+ todo_list -> current ++ ;
4840
4851
}
4841
4852
4842
4853
if (is_rebase_i (opts )) {
@@ -4989,6 +5000,11 @@ static int commit_staged_changes(struct repository *r,
4989
5000
4990
5001
is_clean = !has_uncommitted_changes (r , 0 );
4991
5002
5003
+ if (!is_clean && !file_exists (rebase_path_message ())) {
5004
+ const char * gpg_opt = gpg_sign_opt_quoted (opts );
5005
+
5006
+ return error (_ (staged_changes_advice ), gpg_opt , gpg_opt );
5007
+ }
4992
5008
if (file_exists (rebase_path_amend ())) {
4993
5009
struct strbuf rev = STRBUF_INIT ;
4994
5010
struct object_id head , to_amend ;
0 commit comments