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)
829
829
ropts .oid = & options -> orig_head ;
830
830
ropts .branch = options -> head_name ;
831
831
ropts .flags = RESET_HEAD_RUN_POST_CHECKOUT_HOOK ;
832
+ if (!ropts .branch )
833
+ ropts .flags |= RESET_HEAD_DETACH ;
832
834
ropts .head_msg = buf .buf ;
833
835
if (reset_head (the_repository , & ropts ) < 0 )
834
836
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
18
18
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
19
19
20
20
test_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 &&
25
22
git checkout -b force-3way &&
26
23
echo Dummy >Y &&
27
24
git update-index --add Y &&
@@ -32,9 +29,7 @@ test_expect_success 'prepare repository with topic branches' '
32
29
git mv A D/A &&
33
30
git commit -m "Move A." &&
34
31
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 &&
38
33
git checkout -f main &&
39
34
echo Third >>A &&
40
35
git update-index A &&
@@ -399,6 +394,15 @@ test_expect_success 'switch to branch not checked out' '
399
394
git rebase main other
400
395
'
401
396
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
+
402
406
test_expect_success ' refuse to switch to branch checked out elsewhere' '
403
407
git checkout main &&
404
408
git worktree add wt &&
You can’t perform that action at this time.
0 commit comments