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
'checking out paths not complaining about linked checkouts' '
34 echo dirty >>init.t &&
35 git checkout master -- init.t
39 test_expect_success
'checkout --to a new worktree' '
40 git rev-parse HEAD >expect &&
41 git checkout --detach --to here master &&
44 test_cmp ../init.t init.t &&
45 test_must_fail git symbolic-ref HEAD &&
46 git rev-parse HEAD >actual &&
47 test_cmp ../expect actual &&
52 test_expect_success
'checkout --to a new worktree from a subdir' '
56 git checkout --detach --to here master &&
58 test_cmp ../../init.t init.t
62 test_expect_success
'checkout --to from a linked checkout' '
65 git checkout --detach --to nested-here master &&
71 test_expect_success
'checkout --to a new worktree creating new branch' '
72 git checkout --to there -b newmaster master &&
75 test_cmp ../init.t init.t &&
76 git symbolic-ref HEAD >actual &&
77 echo refs/heads/newmaster >expect &&
78 test_cmp expect actual &&
83 test_expect_success
'die the same branch is already checked out' '
86 test_must_fail git checkout newmaster
90 test_expect_success
'not die the same branch is already checked out' '
93 git checkout --ignore-other-worktrees --to anothernewmaster newmaster
97 test_expect_success
'not die on re-checking out current branch' '
100 git checkout newmaster
104 test_expect_success
'checkout --to from a bare repo' '
106 git clone --bare . bare &&
108 git checkout --to ../there2 -b bare-master master
112 test_expect_success
'checkout from a bare repo without --to' '
115 test_must_fail git checkout master
119 test_expect_success
'checkout with grafts' '
120 test_when_finished rm .git/info/grafts &&
122 SHA1=`git rev-parse HEAD` &&
125 echo "`git rev-parse HEAD` $SHA1" >.git/info/grafts &&
126 cat >expected <<-\EOF &&
130 git log --format=%s -2 >actual &&
131 test_cmp expected actual &&
132 git checkout --detach --to grafted master &&
133 git --git-dir=grafted/.git log --format=%s -2 >actual &&
134 test_cmp expected actual
137 test_expect_success
'checkout --to from relative HEAD' '
141 git rev-parse HEAD~1 >expected &&
142 git checkout --to relhead HEAD~1 &&
143 git -C relhead rev-parse HEAD >actual &&
144 test_cmp expected actual