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' '
16 mkdir -p existing/subtree &&
17 test_must_fail git checkout --detach --to existing master
20 test_expect_success
'checkout --to an existing empty worktree' '
21 mkdir existing_empty &&
22 git checkout --detach --to existing_empty master
25 test_expect_success
'checkout --to refuses to checkout locked branch' '
26 test_must_fail git checkout --to zere master &&
28 ! test -d .git/worktrees/zere
31 test_expect_success
'checkout --to a new worktree' '
32 git rev-parse HEAD >expect &&
33 git checkout --detach --to here master &&
36 test_cmp ../init.t init.t &&
37 test_must_fail git symbolic-ref HEAD &&
38 git rev-parse HEAD >actual &&
39 test_cmp ../expect actual &&
44 test_expect_success
'checkout --to a new worktree from a subdir' '
48 git checkout --detach --to here master &&
50 test_cmp ../../init.t init.t
54 test_expect_success
'checkout --to from a linked checkout' '
57 git checkout --detach --to nested-here master &&
63 test_expect_success
'checkout --to a new worktree creating new branch' '
64 git checkout --to there -b newmaster master &&
67 test_cmp ../init.t init.t &&
68 git symbolic-ref HEAD >actual &&
69 echo refs/heads/newmaster >expect &&
70 test_cmp expect actual &&
75 test_expect_success
'die the same branch is already checked out' '
78 test_must_fail git checkout newmaster
82 test_expect_success
'not die the same branch is already checked out' '
85 git checkout --ignore-other-worktrees --to anothernewmaster newmaster
89 test_expect_success
'not die on re-checking out current branch' '
92 git checkout newmaster
96 test_expect_success
'checkout --to from a bare repo' '
98 git clone --bare . bare &&
100 git checkout --to ../there2 -b bare-master master
104 test_expect_success
'checkout from a bare repo without --to' '
107 test_must_fail git checkout master
111 test_expect_success
'checkout with grafts' '
112 test_when_finished rm .git/info/grafts &&
114 SHA1=`git rev-parse HEAD` &&
117 echo "`git rev-parse HEAD` $SHA1" >.git/info/grafts &&
118 cat >expected <<-\EOF &&
122 git log --format=%s -2 >actual &&
123 test_cmp expected actual &&
124 git checkout --detach --to grafted master &&
125 git --git-dir=grafted/.git log --format=%s -2 >actual &&
126 test_cmp expected actual