3 test_description
='test git worktree add'
7 test_expect_success
'setup' '
11 test_expect_success
'"add" an existing worktree' '
12 mkdir -p existing/subtree &&
13 test_must_fail git worktree add --detach existing master
16 test_expect_success
'"add" an existing empty worktree' '
17 mkdir existing_empty &&
18 git worktree add --detach existing_empty master
21 test_expect_success
'"add" refuses to checkout locked branch' '
22 test_must_fail git worktree add zere master &&
24 ! test -d .git/worktrees/zere
27 test_expect_success
'checking out paths not complaining about linked checkouts' '
30 echo dirty >>init.t &&
31 git checkout master -- init.t
35 test_expect_success
'"add" worktree' '
36 git rev-parse HEAD >expect &&
37 git worktree add --detach here master &&
40 test_cmp ../init.t init.t &&
41 test_must_fail git symbolic-ref HEAD &&
42 git rev-parse HEAD >actual &&
43 test_cmp ../expect actual &&
48 test_expect_success
'"add" worktree from a subdir' '
52 git worktree add --detach here master &&
54 test_cmp ../../init.t init.t
58 test_expect_success
'"add" from a linked checkout' '
61 git worktree add --detach nested-here master &&
67 test_expect_success
'"add" worktree creating new branch' '
68 git worktree add -b newmaster there master &&
71 test_cmp ../init.t init.t &&
72 git symbolic-ref HEAD >actual &&
73 echo refs/heads/newmaster >expect &&
74 test_cmp expect actual &&
79 test_expect_success
'die the same branch is already checked out' '
82 test_must_fail git checkout newmaster
86 test_expect_success
'not die the same branch is already checked out' '
89 git worktree add --force anothernewmaster newmaster
93 test_expect_success
'not die on re-checking out current branch' '
96 git checkout newmaster
100 test_expect_success
'"add" from a bare repo' '
102 git clone --bare . bare &&
104 git worktree add -b bare-master ../there2 master
108 test_expect_success
'checkout from a bare repo without "add"' '
111 test_must_fail git checkout master
115 test_expect_success
'checkout with grafts' '
116 test_when_finished rm .git/info/grafts &&
118 SHA1=`git rev-parse HEAD` &&
121 echo "`git rev-parse HEAD` $SHA1" >.git/info/grafts &&
122 cat >expected <<-\EOF &&
126 git log --format=%s -2 >actual &&
127 test_cmp expected actual &&
128 git worktree add --detach grafted master &&
129 git --git-dir=grafted/.git log --format=%s -2 >actual &&
130 test_cmp expected actual
133 test_expect_success
'"add" from relative HEAD' '
137 git rev-parse HEAD~1 >expected &&
138 git worktree add relhead HEAD~1 &&
139 git -C relhead rev-parse HEAD >actual &&
140 test_cmp expected actual
143 test_expect_success
'"add -b" with <branch> omitted' '
144 git worktree add -b burble flornk &&
145 test_cmp_rev HEAD burble
148 test_expect_success
'"add" with <branch> omitted' '
149 git worktree add wiffle/bat &&
150 test_cmp_rev HEAD bat
153 test_expect_success
'"add" auto-vivify does not clobber existing branch' '
156 git branch precious HEAD~1 &&
157 test_must_fail git worktree add precious &&
158 test_cmp_rev HEAD~1 precious &&
159 test_path_is_missing precious