summaryrefslogtreecommitdiff
path: root/reset.c
diff options
context:
space:
mode:
authorPhillip Wood <phillip.wood@dunelm.org.uk>2022-01-26 13:05:48 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-01-26 20:08:53 (GMT)
commitcd1528ef8ef9847fc27cff4016bf073f04729504 (patch)
tree54e0d712139312788ffc4929e8352d042c60944f /reset.c
parent7700ab087b82f71d19134141045b95063e407344 (diff)
downloadgit-cd1528ef8ef9847fc27cff4016bf073f04729504.zip
git-cd1528ef8ef9847fc27cff4016bf073f04729504.tar.gz
git-cd1528ef8ef9847fc27cff4016bf073f04729504.tar.bz2
rebase --apply: set ORIG_HEAD correctly
At the start of a rebase, ORIG_HEAD is updated to the tip of the branch being rebased. Unfortunately reset_head() always uses the current value of HEAD for this which is incorrect if the rebase is started with "git rebase <upstream> <branch>" as in that case ORIG_HEAD should be updated to <branch>. This only affects the "apply" backend as the "merge" backend does not yet use reset_head() for the initial checkout. Fix this by passing in orig_head when calling reset_head() and add some regression tests. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'reset.c')
-rw-r--r--reset.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/reset.c b/reset.c
index e02915c..448cb3f 100644
--- a/reset.c
+++ b/reset.c
@@ -15,6 +15,7 @@ static int update_refs(const struct reset_head_opts *opts,
unsigned detach_head = opts->flags & RESET_HEAD_DETACH;
unsigned run_hook = opts->flags & RESET_HEAD_RUN_POST_CHECKOUT_HOOK;
unsigned update_orig_head = opts->flags & RESET_ORIG_HEAD;
+ const struct object_id *orig_head = opts->orig_head;
const char *switch_to_branch = opts->branch;
const char *reflog_branch = opts->branch_msg;
const char *reflog_head = opts->head_msg;
@@ -43,7 +44,8 @@ static int update_refs(const struct reset_head_opts *opts,
strbuf_addstr(&msg, "updating ORIG_HEAD");
reflog_orig_head = msg.buf;
}
- update_ref(reflog_orig_head, "ORIG_HEAD", head,
+ update_ref(reflog_orig_head, "ORIG_HEAD",
+ orig_head ? orig_head : head,
old_orig, 0, UPDATE_REFS_MSG_ON_ERR);
} else if (old_orig)
delete_ref(NULL, "ORIG_HEAD", old_orig, 0);