@@ -369,6 +369,7 @@ static void add_var(struct strbuf *buf, const char *name, const char *value)
369
369
#define RESET_HEAD_HARD (1<<1)
370
370
#define RESET_HEAD_RUN_POST_CHECKOUT_HOOK (1<<2)
371
371
#define RESET_HEAD_REFS_ONLY (1<<3)
372
+ #define RESET_ORIG_HEAD (1<<4)
372
373
373
374
static int reset_head (struct object_id * oid , const char * action ,
374
375
const char * switch_to_branch , unsigned flags ,
@@ -378,6 +379,7 @@ static int reset_head(struct object_id *oid, const char *action,
378
379
unsigned reset_hard = flags & RESET_HEAD_HARD ;
379
380
unsigned run_hook = flags & RESET_HEAD_RUN_POST_CHECKOUT_HOOK ;
380
381
unsigned refs_only = flags & RESET_HEAD_REFS_ONLY ;
382
+ unsigned update_orig_head = flags & RESET_ORIG_HEAD ;
381
383
struct object_id head_oid ;
382
384
struct tree_desc desc [2 ] = { { NULL }, { NULL } };
383
385
struct lock_file lock = LOCK_INIT ;
@@ -454,18 +456,21 @@ static int reset_head(struct object_id *oid, const char *action,
454
456
strbuf_addf (& msg , "%s: " , reflog_action ? reflog_action : "rebase" );
455
457
prefix_len = msg .len ;
456
458
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
+
469
474
if (!reflog_head ) {
470
475
strbuf_setlen (& msg , prefix_len );
471
476
strbuf_addstr (& msg , "updating HEAD" );
@@ -476,7 +481,7 @@ static int reset_head(struct object_id *oid, const char *action,
476
481
detach_head ? REF_NO_DEREF : 0 ,
477
482
UPDATE_REFS_MSG_ON_ERR );
478
483
else {
479
- ret = update_ref (reflog_orig_head , switch_to_branch , oid ,
484
+ ret = update_ref (reflog_head , switch_to_branch , oid ,
480
485
NULL , 0 , UPDATE_REFS_MSG_ON_ERR );
481
486
if (!ret )
482
487
ret = create_symref ("HEAD" , switch_to_branch ,
@@ -1760,8 +1765,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1760
1765
strbuf_addf (& msg , "%s: checkout %s" ,
1761
1766
getenv (GIT_REFLOG_ACTION_ENVIRONMENT ), options .onto_name );
1762
1767
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 ))
1765
1770
die (_ ("Could not detach HEAD" ));
1766
1771
strbuf_release (& msg );
1767
1772
@@ -1776,8 +1781,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1776
1781
strbuf_addf (& msg , "rebase finished: %s onto %s" ,
1777
1782
options .head_name ? options .head_name : "detached HEAD" ,
1778
1783
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 );
1781
1786
strbuf_release (& msg );
1782
1787
ret = !!finish_rebase (& options );
1783
1788
goto cleanup ;
0 commit comments