3 test_description
='test git checkout --to'
7 test_expect_success
'setup' '
11 test_expect_success
'checkout --to not updating paths' '
12 test_must_fail git checkout --to -- init.t
15 test_expect_success
'checkout --to refuses to checkout locked branch' '
16 test_must_fail git checkout --to zere master &&
18 ! test -d .git/repos/zere
21 test_expect_success
'checkout --to a new worktree' '
22 git rev-parse HEAD >expect &&
23 git checkout --detach --to here master &&
26 test_cmp ../init.t init.t &&
27 test_must_fail git symbolic-ref HEAD &&
28 git rev-parse HEAD >actual &&
29 test_cmp ../expect actual &&
34 test_expect_success
'checkout --to from a linked checkout' '
37 git checkout --detach --to nested-here master
43 test_expect_success
'checkout --to a new worktree creating new branch' '
44 git checkout --to there -b newmaster master &&
47 test_cmp ../init.t init.t &&
48 git symbolic-ref HEAD >actual &&
49 echo refs/heads/newmaster >expect &&
50 test_cmp expect actual &&
55 test_expect_success
'die the same branch is already checked out' '
58 test_must_fail git checkout newmaster
62 test_expect_success
'not die on re-checking out current branch' '
65 git checkout newmaster
69 test_expect_success
'checkout --to from a bare repo' '
71 git clone --bare . bare &&
73 git checkout --to ../there2 -b bare-master master
77 test_expect_success
'checkout from a bare repo without --to' '
80 test_must_fail git checkout master
84 test_expect_success
'checkout with grafts' '
85 test_when_finished rm .git/info/grafts &&
87 SHA1=`git rev-parse HEAD` &&
90 echo "`git rev-parse HEAD` $SHA1" >.git/info/grafts &&
91 cat >expected <<-\EOF &&
95 git log --format=%s -2 >actual &&
96 test_cmp expected actual &&
97 git checkout --detach --to grafted master &&
98 git --git-dir=grafted/.git log --format=%s -2 >actual &&
99 test_cmp expected actual