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 an existing worktree' '
17 test_must_fail git checkout --detach --to existing master
20 test_expect_success
'checkout --to refuses to checkout locked branch' '
21 test_must_fail git checkout --to zere master &&
23 ! test -d .git/worktrees/zere
26 test_expect_success
'checkout --to a new worktree' '
27 git rev-parse HEAD >expect &&
28 git checkout --detach --to here master &&
31 test_cmp ../init.t init.t &&
32 test_must_fail git symbolic-ref HEAD &&
33 git rev-parse HEAD >actual &&
34 test_cmp ../expect actual &&
39 test_expect_success
'checkout --to a new worktree from a subdir' '
43 git checkout --detach --to here master &&
45 test_cmp ../../init.t init.t
49 test_expect_success
'checkout --to from a linked checkout' '
52 git checkout --detach --to nested-here master &&
58 test_expect_success
'checkout --to a new worktree creating new branch' '
59 git checkout --to there -b newmaster master &&
62 test_cmp ../init.t init.t &&
63 git symbolic-ref HEAD >actual &&
64 echo refs/heads/newmaster >expect &&
65 test_cmp expect actual &&
70 test_expect_success
'die the same branch is already checked out' '
73 test_must_fail git checkout newmaster
77 test_expect_success
'not die on re-checking out current branch' '
80 git checkout newmaster
84 test_expect_success
'checkout --to from a bare repo' '
86 git clone --bare . bare &&
88 git checkout --to ../there2 -b bare-master master
92 test_expect_success
'checkout from a bare repo without --to' '
95 test_must_fail git checkout master
99 test_expect_success
'checkout with grafts' '
100 test_when_finished rm .git/info/grafts &&
102 SHA1=`git rev-parse HEAD` &&
105 echo "`git rev-parse HEAD` $SHA1" >.git/info/grafts &&
106 cat >expected <<-\EOF &&
110 git log --format=%s -2 >actual &&
111 test_cmp expected actual &&
112 git checkout --detach --to grafted master &&
113 git --git-dir=grafted/.git log --format=%s -2 >actual &&
114 test_cmp expected actual