@@ -369,6 +369,7 @@ static void add_var(struct strbuf *buf, const char *name, const char *value)
369369#define RESET_HEAD_HARD (1<<1)
370370#define RESET_HEAD_RUN_POST_CHECKOUT_HOOK (1<<2)
371371#define RESET_HEAD_REFS_ONLY (1<<3)
372+ #define RESET_ORIG_HEAD (1<<4)
372373
373374static int reset_head (struct object_id * oid , const char * action ,
374375 const char * switch_to_branch , unsigned flags ,
@@ -378,6 +379,7 @@ static int reset_head(struct object_id *oid, const char *action,
378379 unsigned reset_hard = flags & RESET_HEAD_HARD ;
379380 unsigned run_hook = flags & RESET_HEAD_RUN_POST_CHECKOUT_HOOK ;
380381 unsigned refs_only = flags & RESET_HEAD_REFS_ONLY ;
382+ unsigned update_orig_head = flags & RESET_ORIG_HEAD ;
381383 struct object_id head_oid ;
382384 struct tree_desc desc [2 ] = { { NULL }, { NULL } };
383385 struct lock_file lock = LOCK_INIT ;
@@ -454,18 +456,21 @@ static int reset_head(struct object_id *oid, const char *action,
454456 strbuf_addf (& msg , "%s: " , reflog_action ? reflog_action : "rebase" );
455457 prefix_len = msg .len ;
456458
457- if (!get_oid ("ORIG_HEAD" , & oid_old_orig ))
458- old_orig = & oid_old_orig ;
459- if (!get_oid ("HEAD" , & oid_orig )) {
460- orig = & oid_orig ;
461- if (!reflog_orig_head ) {
462- strbuf_addstr (& msg , "updating ORIG_HEAD" );
463- reflog_orig_head = msg .buf ;
464- }
465- update_ref (reflog_orig_head , "ORIG_HEAD" , orig , old_orig , 0 ,
466- UPDATE_REFS_MSG_ON_ERR );
467- } else if (old_orig )
468- delete_ref (NULL , "ORIG_HEAD" , old_orig , 0 );
459+ if (update_orig_head ) {
460+ if (!get_oid ("ORIG_HEAD" , & oid_old_orig ))
461+ old_orig = & oid_old_orig ;
462+ if (!get_oid ("HEAD" , & oid_orig )) {
463+ orig = & oid_orig ;
464+ if (!reflog_orig_head ) {
465+ strbuf_addstr (& msg , "updating ORIG_HEAD" );
466+ reflog_orig_head = msg .buf ;
467+ }
468+ update_ref (reflog_orig_head , "ORIG_HEAD" , orig ,
469+ old_orig , 0 , UPDATE_REFS_MSG_ON_ERR );
470+ } else if (old_orig )
471+ delete_ref (NULL , "ORIG_HEAD" , old_orig , 0 );
472+ }
473+
469474 if (!reflog_head ) {
470475 strbuf_setlen (& msg , prefix_len );
471476 strbuf_addstr (& msg , "updating HEAD" );
@@ -476,7 +481,7 @@ static int reset_head(struct object_id *oid, const char *action,
476481 detach_head ? REF_NO_DEREF : 0 ,
477482 UPDATE_REFS_MSG_ON_ERR );
478483 else {
479- ret = update_ref (reflog_orig_head , switch_to_branch , oid ,
484+ ret = update_ref (reflog_head , switch_to_branch , oid ,
480485 NULL , 0 , UPDATE_REFS_MSG_ON_ERR );
481486 if (!ret )
482487 ret = create_symref ("HEAD" , switch_to_branch ,
@@ -1760,8 +1765,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
17601765 strbuf_addf (& msg , "%s: checkout %s" ,
17611766 getenv (GIT_REFLOG_ACTION_ENVIRONMENT ), options .onto_name );
17621767 if (reset_head (& options .onto -> object .oid , "checkout" , NULL ,
1763- RESET_HEAD_DETACH | RESET_HEAD_RUN_POST_CHECKOUT_HOOK ,
1764- NULL , msg .buf ))
1768+ RESET_HEAD_DETACH | RESET_HEAD_RUN_POST_CHECKOUT_HOOK |
1769+ RESET_ORIG_HEAD , NULL , msg .buf ))
17651770 die (_ ("Could not detach HEAD" ));
17661771 strbuf_release (& msg );
17671772
@@ -1776,8 +1781,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
17761781 strbuf_addf (& msg , "rebase finished: %s onto %s" ,
17771782 options .head_name ? options .head_name : "detached HEAD" ,
17781783 oid_to_hex (& options .onto -> object .oid ));
1779- reset_head (NULL , "Fast-forwarded" , options .head_name , 0 ,
1780- "HEAD" , msg .buf );
1784+ reset_head (NULL , "Fast-forwarded" , options .head_name ,
1785+ RESET_HEAD_REFS_ONLY , "HEAD" , msg .buf );
17811786 strbuf_release (& msg );
17821787 ret = !!finish_rebase (& options );
17831788 goto cleanup ;
0 commit comments