]>
Commit | Line | Data |
---|---|---|
529fef20 NTND |
1 | #!/bin/sh |
2 | ||
f194b1ef | 3 | test_description='test git worktree add' |
529fef20 NTND |
4 | |
5 | . ./test-lib.sh | |
6 | ||
8d9fdd70 NTND |
7 | . "$TEST_DIRECTORY"/lib-rebase.sh |
8 | ||
529fef20 NTND |
9 | test_expect_success 'setup' ' |
10 | test_commit init | |
11 | ' | |
12 | ||
f194b1ef | 13 | test_expect_success '"add" an existing worktree' ' |
ee4fb843 | 14 | mkdir -p existing/subtree && |
f194b1ef | 15 | test_must_fail git worktree add --detach existing master |
529fef20 NTND |
16 | ' |
17 | ||
f194b1ef | 18 | test_expect_success '"add" an existing empty worktree' ' |
ee4fb843 | 19 | mkdir existing_empty && |
f194b1ef | 20 | git worktree add --detach existing_empty master |
ee4fb843 MK |
21 | ' |
22 | ||
1a450e2f JDG |
23 | test_expect_success '"add" using shorthand - fails when no previous branch' ' |
24 | test_must_fail git worktree add existing_short - | |
25 | ' | |
26 | ||
27 | test_expect_success '"add" using - shorthand' ' | |
28 | git checkout -b newbranch && | |
29 | echo hello >myworld && | |
30 | git add myworld && | |
31 | git commit -m myworld && | |
32 | git checkout master && | |
33 | git worktree add short-hand - && | |
34 | echo refs/heads/newbranch >expect && | |
35 | git -C short-hand rev-parse --symbolic-full-name HEAD >actual && | |
36 | test_cmp expect actual | |
37 | ' | |
38 | ||
f194b1ef ES |
39 | test_expect_success '"add" refuses to checkout locked branch' ' |
40 | test_must_fail git worktree add zere master && | |
3b8925c7 NTND |
41 | ! test -d zere && |
42 | ! test -d .git/worktrees/zere | |
43 | ' | |
44 | ||
e1c1ab9d NTND |
45 | test_expect_success 'checking out paths not complaining about linked checkouts' ' |
46 | ( | |
47 | cd existing_empty && | |
48 | echo dirty >>init.t && | |
49 | git checkout master -- init.t | |
50 | ) | |
51 | ' | |
52 | ||
f194b1ef | 53 | test_expect_success '"add" worktree' ' |
5883034c | 54 | git rev-parse HEAD >expect && |
f194b1ef | 55 | git worktree add --detach here master && |
529fef20 NTND |
56 | ( |
57 | cd here && | |
58 | test_cmp ../init.t init.t && | |
5883034c NTND |
59 | test_must_fail git symbolic-ref HEAD && |
60 | git rev-parse HEAD >actual && | |
61 | test_cmp ../expect actual && | |
529fef20 NTND |
62 | git fsck |
63 | ) | |
64 | ' | |
65 | ||
f194b1ef | 66 | test_expect_success '"add" worktree from a subdir' ' |
529fef20 NTND |
67 | ( |
68 | mkdir sub && | |
69 | cd sub && | |
f194b1ef | 70 | git worktree add --detach here master && |
529fef20 NTND |
71 | cd here && |
72 | test_cmp ../../init.t init.t | |
73 | ) | |
74 | ' | |
75 | ||
f194b1ef | 76 | test_expect_success '"add" from a linked checkout' ' |
529fef20 NTND |
77 | ( |
78 | cd here && | |
f194b1ef | 79 | git worktree add --detach nested-here master && |
529fef20 NTND |
80 | cd nested-here && |
81 | git fsck | |
82 | ) | |
83 | ' | |
84 | ||
f194b1ef ES |
85 | test_expect_success '"add" worktree creating new branch' ' |
86 | git worktree add -b newmaster there master && | |
529fef20 NTND |
87 | ( |
88 | cd there && | |
89 | test_cmp ../init.t init.t && | |
90 | git symbolic-ref HEAD >actual && | |
91 | echo refs/heads/newmaster >expect && | |
92 | test_cmp expect actual && | |
93 | git fsck | |
94 | ) | |
95 | ' | |
96 | ||
5883034c NTND |
97 | test_expect_success 'die the same branch is already checked out' ' |
98 | ( | |
99 | cd here && | |
100 | test_must_fail git checkout newmaster | |
101 | ) | |
102 | ' | |
103 | ||
746bbdc6 ES |
104 | test_expect_success SYMLINKS 'die the same branch is already checked out (symlink)' ' |
105 | head=$(git -C there rev-parse --git-path HEAD) && | |
106 | ref=$(git -C there symbolic-ref HEAD) && | |
107 | rm "$head" && | |
108 | ln -s "$ref" "$head" && | |
109 | test_must_fail git -C here checkout newmaster | |
110 | ' | |
111 | ||
1d0fa898 NTND |
112 | test_expect_success 'not die the same branch is already checked out' ' |
113 | ( | |
114 | cd here && | |
f194b1ef | 115 | git worktree add --force anothernewmaster newmaster |
1d0fa898 NTND |
116 | ) |
117 | ' | |
118 | ||
5883034c NTND |
119 | test_expect_success 'not die on re-checking out current branch' ' |
120 | ( | |
121 | cd there && | |
122 | git checkout newmaster | |
123 | ) | |
124 | ' | |
125 | ||
f194b1ef | 126 | test_expect_success '"add" from a bare repo' ' |
3473ad0c DK |
127 | ( |
128 | git clone --bare . bare && | |
129 | cd bare && | |
f194b1ef | 130 | git worktree add -b bare-master ../there2 master |
3473ad0c DK |
131 | ) |
132 | ' | |
133 | ||
f194b1ef | 134 | test_expect_success 'checkout from a bare repo without "add"' ' |
3473ad0c DK |
135 | ( |
136 | cd bare && | |
137 | test_must_fail git checkout master | |
138 | ) | |
139 | ' | |
140 | ||
ad35f615 NTND |
141 | test_expect_success 'checkout with grafts' ' |
142 | test_when_finished rm .git/info/grafts && | |
143 | test_commit abc && | |
697b90d7 | 144 | SHA1=$(git rev-parse HEAD) && |
ad35f615 NTND |
145 | test_commit def && |
146 | test_commit xyz && | |
697b90d7 | 147 | echo "$(git rev-parse HEAD) $SHA1" >.git/info/grafts && |
ad35f615 NTND |
148 | cat >expected <<-\EOF && |
149 | xyz | |
150 | abc | |
151 | EOF | |
152 | git log --format=%s -2 >actual && | |
153 | test_cmp expected actual && | |
f194b1ef | 154 | git worktree add --detach grafted master && |
ad35f615 NTND |
155 | git --git-dir=grafted/.git log --format=%s -2 >actual && |
156 | test_cmp expected actual | |
157 | ' | |
158 | ||
f194b1ef | 159 | test_expect_success '"add" from relative HEAD' ' |
c990a4c1 ES |
160 | test_commit a && |
161 | test_commit b && | |
162 | test_commit c && | |
163 | git rev-parse HEAD~1 >expected && | |
f194b1ef | 164 | git worktree add relhead HEAD~1 && |
c990a4c1 ES |
165 | git -C relhead rev-parse HEAD >actual && |
166 | test_cmp expected actual | |
167 | ' | |
168 | ||
0f4af3b9 ES |
169 | test_expect_success '"add -b" with <branch> omitted' ' |
170 | git worktree add -b burble flornk && | |
171 | test_cmp_rev HEAD burble | |
172 | ' | |
173 | ||
5c942570 ES |
174 | test_expect_success '"add --detach" with <branch> omitted' ' |
175 | git worktree add --detach fishhook && | |
176 | git rev-parse HEAD >expected && | |
177 | git -C fishhook rev-parse HEAD >actual && | |
178 | test_cmp expected actual && | |
179 | test_must_fail git -C fishhook symbolic-ref HEAD | |
180 | ' | |
181 | ||
1eb07d82 ES |
182 | test_expect_success '"add" with <branch> omitted' ' |
183 | git worktree add wiffle/bat && | |
184 | test_cmp_rev HEAD bat | |
185 | ' | |
186 | ||
187 | test_expect_success '"add" auto-vivify does not clobber existing branch' ' | |
188 | test_commit c1 && | |
189 | test_commit c2 && | |
190 | git branch precious HEAD~1 && | |
191 | test_must_fail git worktree add precious && | |
192 | test_cmp_rev HEAD~1 precious && | |
193 | test_path_is_missing precious | |
194 | ' | |
195 | ||
5c942570 ES |
196 | test_expect_success '"add" no auto-vivify with --detach and <branch> omitted' ' |
197 | git worktree add --detach mish/mash && | |
198 | test_must_fail git rev-parse mash -- && | |
199 | test_must_fail git -C mish/mash symbolic-ref HEAD | |
200 | ' | |
201 | ||
ab0b2c53 ES |
202 | test_expect_success '"add" -b/-B mutually exclusive' ' |
203 | test_must_fail git worktree add -b poodle -B poodle bamboo master | |
204 | ' | |
205 | ||
206 | test_expect_success '"add" -b/--detach mutually exclusive' ' | |
207 | test_must_fail git worktree add -b poodle --detach bamboo master | |
208 | ' | |
209 | ||
210 | test_expect_success '"add" -B/--detach mutually exclusive' ' | |
211 | test_must_fail git worktree add -B poodle --detach bamboo master | |
212 | ' | |
213 | ||
beb6f24b NTND |
214 | test_expect_success '"add -B" fails if the branch is checked out' ' |
215 | git rev-parse newmaster >before && | |
216 | test_must_fail git worktree add -B newmaster bamboo master && | |
217 | git rev-parse newmaster >after && | |
218 | test_cmp before after | |
219 | ' | |
220 | ||
0ebf4a2a NTND |
221 | test_expect_success 'add -B' ' |
222 | git worktree add -B poodle bamboo2 master^ && | |
223 | git -C bamboo2 symbolic-ref HEAD >actual && | |
224 | echo refs/heads/poodle >expected && | |
225 | test_cmp expected actual && | |
226 | test_cmp_rev master^ poodle | |
227 | ' | |
228 | ||
744e4697 NTND |
229 | test_expect_success 'local clone from linked checkout' ' |
230 | git clone --local here here-clone && | |
231 | ( cd here-clone && git fsck ) | |
232 | ' | |
233 | ||
ef2a0ac9 RZ |
234 | test_expect_success '"add" worktree with --no-checkout' ' |
235 | git worktree add --no-checkout -b swamp swamp && | |
236 | ! test -e swamp/init.t && | |
237 | git -C swamp reset --hard && | |
238 | test_cmp init.t swamp/init.t | |
239 | ' | |
240 | ||
241 | test_expect_success '"add" worktree with --checkout' ' | |
242 | git worktree add --checkout -b swmap2 swamp2 && | |
243 | test_cmp init.t swamp2/init.t | |
244 | ' | |
245 | ||
8d9fdd70 NTND |
246 | test_expect_success 'put a worktree under rebase' ' |
247 | git worktree add under-rebase && | |
248 | ( | |
249 | cd under-rebase && | |
250 | set_fake_editor && | |
251 | FAKE_LINES="edit 1" git rebase -i HEAD^ && | |
252 | git worktree list | grep "under-rebase.*detached HEAD" | |
253 | ) | |
254 | ' | |
255 | ||
256 | test_expect_success 'add a worktree, checking out a rebased branch' ' | |
257 | test_must_fail git worktree add new-rebase under-rebase && | |
258 | ! test -d new-rebase | |
259 | ' | |
260 | ||
261 | test_expect_success 'checking out a rebased branch from another worktree' ' | |
262 | git worktree add new-place && | |
263 | test_must_fail git -C new-place checkout under-rebase | |
264 | ' | |
265 | ||
266 | test_expect_success 'not allow to delete a branch under rebase' ' | |
267 | ( | |
268 | cd under-rebase && | |
269 | test_must_fail git branch -D under-rebase | |
270 | ) | |
271 | ' | |
272 | ||
14ace5b7 NTND |
273 | test_expect_success 'rename a branch under rebase not allowed' ' |
274 | test_must_fail git branch -M under-rebase rebase-with-new-name | |
275 | ' | |
276 | ||
8d9fdd70 NTND |
277 | test_expect_success 'check out from current worktree branch ok' ' |
278 | ( | |
279 | cd under-rebase && | |
280 | git checkout under-rebase && | |
281 | git checkout - && | |
282 | git rebase --abort | |
283 | ) | |
284 | ' | |
285 | ||
04a3dfb8 NTND |
286 | test_expect_success 'checkout a branch under bisect' ' |
287 | git worktree add under-bisect && | |
288 | ( | |
289 | cd under-bisect && | |
290 | git bisect start && | |
291 | git bisect bad && | |
292 | git bisect good HEAD~2 && | |
293 | git worktree list | grep "under-bisect.*detached HEAD" && | |
294 | test_must_fail git worktree add new-bisect under-bisect && | |
295 | ! test -d new-bisect | |
296 | ) | |
297 | ' | |
298 | ||
14ace5b7 NTND |
299 | test_expect_success 'rename a branch under bisect not allowed' ' |
300 | test_must_fail git branch -M under-bisect bisect-with-new-name | |
301 | ' | |
302 | ||
529fef20 | 303 | test_done |