@@ -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
@@ -900,7 +907,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
900
907
rerere_clear (& merge_rr );
901
908
string_list_clear (& merge_rr , 1 );
902
909
903
- if (reset_head (NULL , "reset" , NULL , 0 ) < 0 )
910
+ if (reset_head (NULL , "reset" , NULL , 0 , NULL , NULL ) < 0 )
904
911
die (_ ("could not discard worktree changes" ));
905
912
if (read_basic_state (& options ))
906
913
exit (1 );
@@ -916,7 +923,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
916
923
if (read_basic_state (& options ))
917
924
exit (1 );
918
925
if (reset_head (& options .orig_head , "reset" ,
919
- options .head_name , 0 ) < 0 )
926
+ options .head_name , 0 , NULL , NULL ) < 0 )
920
927
die (_ ("could not move back to %s" ),
921
928
oid_to_hex (& options .orig_head ));
922
929
ret = finish_rebase (& options );
@@ -1236,7 +1243,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1236
1243
write_file (autostash , "%s" , buf .buf );
1237
1244
printf (_ ("Created autostash: %s\n" ), buf .buf );
1238
1245
if (reset_head (& head -> object .oid , "reset --hard" ,
1239
- NULL , 0 ) < 0 )
1246
+ NULL , 0 , NULL , NULL ) < 0 )
1240
1247
die (_ ("could not reset --hard" ));
1241
1248
printf (_ ("HEAD is now at %s" ),
1242
1249
find_unique_abbrev (& head -> object .oid ,
@@ -1290,7 +1297,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1290
1297
strbuf_addf (& buf , "rebase: checkout %s" ,
1291
1298
options .switch_to );
1292
1299
if (reset_head (& oid , "checkout" ,
1293
- options .head_name , 0 ) < 0 ) {
1300
+ options .head_name , 0 ,
1301
+ NULL , NULL ) < 0 ) {
1294
1302
ret = !!error (_ ("could not switch to "
1295
1303
"%s" ),
1296
1304
options .switch_to );
@@ -1355,7 +1363,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1355
1363
"it...\n" ));
1356
1364
1357
1365
strbuf_addf (& msg , "rebase: checkout %s" , options .onto_name );
1358
- if (reset_head (& options .onto -> object .oid , "checkout" , NULL , 1 ))
1366
+ if (reset_head (& options .onto -> object .oid , "checkout" , NULL , 1 ,
1367
+ NULL , msg .buf ))
1359
1368
die (_ ("Could not detach HEAD" ));
1360
1369
strbuf_release (& msg );
1361
1370
0 commit comments