Skip to content

Commit cc0dbd5

Browse files
committed
built-in rebase --autostash: leave the current branch alone if possible
When we converted a `git reset --hard` call in the original Unix shell script to built-in code, we asked to reset the worktree and the index and explicitly *not* to detach the HEAD. By mistake, though, we still did. Let's fix this. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent d63232a commit cc0dbd5

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

builtin/rebase.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,8 @@ static int reset_head(struct object_id *oid, const char *action,
614614
reflog_head = msg.buf;
615615
}
616616
if (!switch_to_branch)
617-
ret = update_ref(reflog_head, "HEAD", oid, orig, REF_NO_DEREF,
617+
ret = update_ref(reflog_head, "HEAD", oid, orig,
618+
detach_head ? REF_NO_DEREF : 0,
618619
UPDATE_REFS_MSG_ON_ERR);
619620
else {
620621
ret = create_symref("HEAD", switch_to_branch, msg.buf);

t/t3420-rebase-autostash.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ test_expect_success 'autostash with dirty submodules' '
361361
git rebase -i --autostash HEAD
362362
'
363363

364-
test_expect_failure 'branch is left alone when possible' '
364+
test_expect_success 'branch is left alone when possible' '
365365
git checkout -b unchanged-branch &&
366366
echo changed >file0 &&
367367
git rebase --autostash unchanged-branch &&

0 commit comments

Comments
 (0)