File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -829,6 +829,8 @@ static int checkout_up_to_date(struct rebase_options *options)
829829 ropts .oid = & options -> orig_head ;
830830 ropts .branch = options -> head_name ;
831831 ropts .flags = RESET_HEAD_RUN_POST_CHECKOUT_HOOK ;
832+ if (!ropts .branch )
833+ ropts .flags |= RESET_HEAD_DETACH ;
832834 ropts .head_msg = buf .buf ;
833835 if (reset_head (the_repository , & ropts ) < 0 )
834836 ret = error (_ ("could not switch to %s" ), options -> switch_to );
Original file line number Diff line number Diff line change @@ -18,10 +18,7 @@ GIT_AUTHOR_EMAIL=bogus@email@address
1818export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
1919
2020test_expect_success ' prepare repository with topic branches' '
21- git config core.logAllRefUpdates true &&
22- echo First >A &&
23- git update-index --add A &&
24- git commit -m "Add A." &&
21+ test_commit "Add A." A First First &&
2522 git checkout -b force-3way &&
2623 echo Dummy >Y &&
2724 git update-index --add Y &&
@@ -32,9 +29,7 @@ test_expect_success 'prepare repository with topic branches' '
3229 git mv A D/A &&
3330 git commit -m "Move A." &&
3431 git checkout -b my-topic-branch main &&
35- echo Second >B &&
36- git update-index --add B &&
37- git commit -m "Add B." &&
32+ test_commit "Add B." B Second Second &&
3833 git checkout -f main &&
3934 echo Third >>A &&
4035 git update-index A &&
@@ -399,6 +394,15 @@ test_expect_success 'switch to branch not checked out' '
399394 git rebase main other
400395'
401396
397+ test_expect_success ' switch to non-branch detaches HEAD' '
398+ git checkout main &&
399+ old_main=$(git rev-parse HEAD) &&
400+ git rebase First Second^0 &&
401+ test_cmp_rev HEAD Second &&
402+ test_cmp_rev main $old_main &&
403+ test_must_fail git symbolic-ref HEAD
404+ '
405+
402406test_expect_success ' refuse to switch to branch checked out elsewhere' '
403407 git checkout main &&
404408 git worktree add wt &&
You can’t perform that action at this time.
0 commit comments