@@ -431,7 +431,8 @@ static int run_specific_rebase(struct rebase_options *opts)
431
431
#define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION"
432
432
433
433
static int reset_head (struct object_id * oid , const char * action ,
434
- const char * switch_to_branch , int detach_head )
434
+ const char * switch_to_branch , int detach_head ,
435
+ const char * reflog_orig_head , const char * reflog_head )
435
436
{
436
437
struct object_id head_oid ;
437
438
struct tree_desc desc ;
@@ -506,20 +507,26 @@ static int reset_head(struct object_id *oid, const char *action,
506
507
old_orig = & oid_old_orig ;
507
508
if (!get_oid ("HEAD" , & oid_orig )) {
508
509
orig = & oid_orig ;
509
- strbuf_addstr (& msg , "updating ORIG_HEAD" );
510
- update_ref (msg .buf , "ORIG_HEAD" , orig , old_orig , 0 ,
510
+ if (!reflog_orig_head ) {
511
+ strbuf_addstr (& msg , "updating ORIG_HEAD" );
512
+ reflog_orig_head = msg .buf ;
513
+ }
514
+ update_ref (reflog_orig_head , "ORIG_HEAD" , orig , old_orig , 0 ,
511
515
UPDATE_REFS_MSG_ON_ERR );
512
516
} else if (old_orig )
513
517
delete_ref (NULL , "ORIG_HEAD" , old_orig , 0 );
514
- strbuf_setlen (& msg , prefix_len );
515
- strbuf_addstr (& msg , "updating HEAD" );
518
+ if (!reflog_head ) {
519
+ strbuf_setlen (& msg , prefix_len );
520
+ strbuf_addstr (& msg , "updating HEAD" );
521
+ reflog_head = msg .buf ;
522
+ }
516
523
if (!switch_to_branch )
517
- ret = update_ref (msg . buf , "HEAD" , oid , orig , REF_NO_DEREF ,
524
+ ret = update_ref (reflog_head , "HEAD" , oid , orig , REF_NO_DEREF ,
518
525
UPDATE_REFS_MSG_ON_ERR );
519
526
else {
520
527
ret = create_symref ("HEAD" , switch_to_branch , msg .buf );
521
528
if (!ret )
522
- ret = update_ref (msg . buf , "HEAD" , oid , NULL , 0 ,
529
+ ret = update_ref (reflog_head , "HEAD" , oid , NULL , 0 ,
523
530
UPDATE_REFS_MSG_ON_ERR );
524
531
}
525
532
@@ -899,7 +906,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
899
906
rerere_clear (& merge_rr );
900
907
string_list_clear (& merge_rr , 1 );
901
908
902
- if (reset_head (NULL , "reset" , NULL , 0 ) < 0 )
909
+ if (reset_head (NULL , "reset" , NULL , 0 , NULL , NULL ) < 0 )
903
910
die (_ ("could not discard worktree changes" ));
904
911
if (read_basic_state (& options ))
905
912
exit (1 );
@@ -915,7 +922,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
915
922
if (read_basic_state (& options ))
916
923
exit (1 );
917
924
if (reset_head (& options .orig_head , "reset" ,
918
- options .head_name , 0 ) < 0 )
925
+ options .head_name , 0 , NULL , NULL ) < 0 )
919
926
die (_ ("could not move back to %s" ),
920
927
oid_to_hex (& options .orig_head ));
921
928
ret = finish_rebase (& options );
@@ -1235,7 +1242,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1235
1242
write_file (autostash , "%s" , buf .buf );
1236
1243
printf (_ ("Created autostash: %s\n" ), buf .buf );
1237
1244
if (reset_head (& head -> object .oid , "reset --hard" ,
1238
- NULL , 0 ) < 0 )
1245
+ NULL , 0 , NULL , NULL ) < 0 )
1239
1246
die (_ ("could not reset --hard" ));
1240
1247
printf (_ ("HEAD is now at %s" ),
1241
1248
find_unique_abbrev (& head -> object .oid ,
@@ -1289,7 +1296,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1289
1296
strbuf_addf (& buf , "rebase: checkout %s" ,
1290
1297
options .switch_to );
1291
1298
if (reset_head (& oid , "checkout" ,
1292
- options .head_name , 0 ) < 0 ) {
1299
+ options .head_name , 0 ,
1300
+ NULL , NULL ) < 0 ) {
1293
1301
ret = !!error (_ ("could not switch to "
1294
1302
"%s" ),
1295
1303
options .switch_to );
@@ -1354,7 +1362,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1354
1362
"it...\n" ));
1355
1363
1356
1364
strbuf_addf (& msg , "rebase: checkout %s" , options .onto_name );
1357
- if (reset_head (& options .onto -> object .oid , "checkout" , NULL , 1 ))
1365
+ if (reset_head (& options .onto -> object .oid , "checkout" , NULL , 1 ,
1366
+ NULL , msg .buf ))
1358
1367
die (_ ("Could not detach HEAD" ));
1359
1368
strbuf_release (& msg );
1360
1369
0 commit comments