@@ -431,7 +431,8 @@ static int run_specific_rebase(struct rebase_options *opts)
431431#define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION"
432432
433433static 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 )
435436{
436437 struct object_id head_oid ;
437438 struct tree_desc desc ;
@@ -506,20 +507,26 @@ static int reset_head(struct object_id *oid, const char *action,
506507 old_orig = & oid_old_orig ;
507508 if (!get_oid ("HEAD" , & oid_orig )) {
508509 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 ,
511515 UPDATE_REFS_MSG_ON_ERR );
512516 } else if (old_orig )
513517 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+ }
516523 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 ,
518525 UPDATE_REFS_MSG_ON_ERR );
519526 else {
520527 ret = create_symref ("HEAD" , switch_to_branch , msg .buf );
521528 if (!ret )
522- ret = update_ref (msg . buf , "HEAD" , oid , NULL , 0 ,
529+ ret = update_ref (reflog_head , "HEAD" , oid , NULL , 0 ,
523530 UPDATE_REFS_MSG_ON_ERR );
524531 }
525532
@@ -900,7 +907,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
900907 rerere_clear (& merge_rr );
901908 string_list_clear (& merge_rr , 1 );
902909
903- if (reset_head (NULL , "reset" , NULL , 0 ) < 0 )
910+ if (reset_head (NULL , "reset" , NULL , 0 , NULL , NULL ) < 0 )
904911 die (_ ("could not discard worktree changes" ));
905912 if (read_basic_state (& options ))
906913 exit (1 );
@@ -916,7 +923,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
916923 if (read_basic_state (& options ))
917924 exit (1 );
918925 if (reset_head (& options .orig_head , "reset" ,
919- options .head_name , 0 ) < 0 )
926+ options .head_name , 0 , NULL , NULL ) < 0 )
920927 die (_ ("could not move back to %s" ),
921928 oid_to_hex (& options .orig_head ));
922929 ret = finish_rebase (& options );
@@ -1236,7 +1243,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12361243 write_file (autostash , "%s" , buf .buf );
12371244 printf (_ ("Created autostash: %s\n" ), buf .buf );
12381245 if (reset_head (& head -> object .oid , "reset --hard" ,
1239- NULL , 0 ) < 0 )
1246+ NULL , 0 , NULL , NULL ) < 0 )
12401247 die (_ ("could not reset --hard" ));
12411248 printf (_ ("HEAD is now at %s" ),
12421249 find_unique_abbrev (& head -> object .oid ,
@@ -1290,7 +1297,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12901297 strbuf_addf (& buf , "rebase: checkout %s" ,
12911298 options .switch_to );
12921299 if (reset_head (& oid , "checkout" ,
1293- options .head_name , 0 ) < 0 ) {
1300+ options .head_name , 0 ,
1301+ NULL , NULL ) < 0 ) {
12941302 ret = !!error (_ ("could not switch to "
12951303 "%s" ),
12961304 options .switch_to );
@@ -1355,7 +1363,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
13551363 "it...\n" ));
13561364
13571365 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 ))
13591368 die (_ ("Could not detach HEAD" ));
13601369 strbuf_release (& msg );
13611370
0 commit comments