Skip to content

Commit 9aefd35

Browse files
committed
Merge branch 'js/rebase-autostash-detach-fix'
"git rebase --autostash" did not correctly re-attach the HEAD at times. * js/rebase-autostash-detach-fix: built-in rebase --autostash: leave the current branch alone if possible built-in rebase: demonstrate regression with --autostash
2 parents a517079 + 176f5d9 commit 9aefd35

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

builtin/rebase.c

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

t/t3420-rebase-autostash.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,4 +361,12 @@ test_expect_success 'autostash with dirty submodules' '
361361
git rebase -i --autostash HEAD
362362
'
363363

364+
test_expect_success 'branch is left alone when possible' '
365+
git checkout -b unchanged-branch &&
366+
echo changed >file0 &&
367+
git rebase --autostash unchanged-branch &&
368+
test changed = "$(cat file0)" &&
369+
test unchanged-branch = "$(git rev-parse --abbrev-ref HEAD)"
370+
'
371+
364372
test_done

0 commit comments

Comments
 (0)