]> git.ipfire.org Git - thirdparty/git.git/blame - t/t2400-worktree-add.sh
Sync with 2.35.8
[thirdparty/git.git] / t / t2400-worktree-add.sh
CommitLineData
529fef20
NTND
1#!/bin/sh
2
f194b1ef 3test_description='test git worktree add'
529fef20 4
883b98ef 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
529fef20
NTND
8. ./test-lib.sh
9
8d9fdd70
NTND
10. "$TEST_DIRECTORY"/lib-rebase.sh
11
529fef20
NTND
12test_expect_success 'setup' '
13 test_commit init
14'
15
f194b1ef 16test_expect_success '"add" an existing worktree' '
ee4fb843 17 mkdir -p existing/subtree &&
883b98ef 18 test_must_fail git worktree add --detach existing main
529fef20
NTND
19'
20
f194b1ef 21test_expect_success '"add" an existing empty worktree' '
ee4fb843 22 mkdir existing_empty &&
883b98ef 23 git worktree add --detach existing_empty main
ee4fb843
MK
24'
25
1a450e2f
JDG
26test_expect_success '"add" using shorthand - fails when no previous branch' '
27 test_must_fail git worktree add existing_short -
28'
29
30test_expect_success '"add" using - shorthand' '
31 git checkout -b newbranch &&
32 echo hello >myworld &&
33 git add myworld &&
34 git commit -m myworld &&
883b98ef 35 git checkout main &&
1a450e2f
JDG
36 git worktree add short-hand - &&
37 echo refs/heads/newbranch >expect &&
38 git -C short-hand rev-parse --symbolic-full-name HEAD >actual &&
39 test_cmp expect actual
40'
41
f194b1ef 42test_expect_success '"add" refuses to checkout locked branch' '
883b98ef 43 test_must_fail git worktree add zere main &&
3b8925c7
NTND
44 ! test -d zere &&
45 ! test -d .git/worktrees/zere
46'
47
e1c1ab9d
NTND
48test_expect_success 'checking out paths not complaining about linked checkouts' '
49 (
50 cd existing_empty &&
51 echo dirty >>init.t &&
883b98ef 52 git checkout main -- init.t
e1c1ab9d
NTND
53 )
54'
55
f194b1ef 56test_expect_success '"add" worktree' '
5883034c 57 git rev-parse HEAD >expect &&
883b98ef 58 git worktree add --detach here main &&
529fef20
NTND
59 (
60 cd here &&
61 test_cmp ../init.t init.t &&
5883034c
NTND
62 test_must_fail git symbolic-ref HEAD &&
63 git rev-parse HEAD >actual &&
64 test_cmp ../expect actual &&
529fef20
NTND
65 git fsck
66 )
67'
68
507e6e9e 69test_expect_success '"add" worktree with lock' '
883b98ef 70 git worktree add --detach --lock here-with-lock main &&
f9365c0a 71 test_when_finished "git worktree unlock here-with-lock || :" &&
507e6e9e
NTND
72 test -f .git/worktrees/here-with-lock/locked
73'
74
0db4961c
SM
75test_expect_success '"add" worktree with lock and reason' '
76 lock_reason="why not" &&
77 git worktree add --detach --lock --reason "$lock_reason" here-with-lock-reason main &&
78 test_when_finished "git worktree unlock here-with-lock-reason || :" &&
79 test -f .git/worktrees/here-with-lock-reason/locked &&
80 echo "$lock_reason" >expect &&
81 test_cmp expect .git/worktrees/here-with-lock-reason/locked
82'
83
84test_expect_success '"add" worktree with reason but no lock' '
85 test_must_fail git worktree add --detach --reason "why not" here-with-reason-only main &&
86 test_path_is_missing .git/worktrees/here-with-reason-only/locked
87'
88
f194b1ef 89test_expect_success '"add" worktree from a subdir' '
529fef20
NTND
90 (
91 mkdir sub &&
92 cd sub &&
883b98ef 93 git worktree add --detach here main &&
529fef20
NTND
94 cd here &&
95 test_cmp ../../init.t init.t
96 )
97'
98
f194b1ef 99test_expect_success '"add" from a linked checkout' '
529fef20
NTND
100 (
101 cd here &&
883b98ef 102 git worktree add --detach nested-here main &&
529fef20
NTND
103 cd nested-here &&
104 git fsck
105 )
106'
107
f194b1ef 108test_expect_success '"add" worktree creating new branch' '
883b98ef 109 git worktree add -b newmain there main &&
529fef20
NTND
110 (
111 cd there &&
112 test_cmp ../init.t init.t &&
113 git symbolic-ref HEAD >actual &&
883b98ef 114 echo refs/heads/newmain >expect &&
529fef20
NTND
115 test_cmp expect actual &&
116 git fsck
117 )
118'
119
5883034c
NTND
120test_expect_success 'die the same branch is already checked out' '
121 (
122 cd here &&
883b98ef 123 test_must_fail git checkout newmain
5883034c
NTND
124 )
125'
126
746bbdc6
ES
127test_expect_success SYMLINKS 'die the same branch is already checked out (symlink)' '
128 head=$(git -C there rev-parse --git-path HEAD) &&
129 ref=$(git -C there symbolic-ref HEAD) &&
130 rm "$head" &&
131 ln -s "$ref" "$head" &&
883b98ef 132 test_must_fail git -C here checkout newmain
746bbdc6
ES
133'
134
1d0fa898
NTND
135test_expect_success 'not die the same branch is already checked out' '
136 (
137 cd here &&
883b98ef 138 git worktree add --force anothernewmain newmain
1d0fa898
NTND
139 )
140'
141
5883034c
NTND
142test_expect_success 'not die on re-checking out current branch' '
143 (
144 cd there &&
883b98ef 145 git checkout newmain
5883034c
NTND
146 )
147'
148
f194b1ef 149test_expect_success '"add" from a bare repo' '
3473ad0c
DK
150 (
151 git clone --bare . bare &&
152 cd bare &&
883b98ef 153 git worktree add -b bare-main ../there2 main
3473ad0c
DK
154 )
155'
156
f194b1ef 157test_expect_success 'checkout from a bare repo without "add"' '
3473ad0c
DK
158 (
159 cd bare &&
883b98ef 160 test_must_fail git checkout main
3473ad0c
DK
161 )
162'
163
171c646f
DK
164test_expect_success '"add" default branch of a bare repo' '
165 (
166 git clone --bare . bare2 &&
167 cd bare2 &&
53255916
DS
168 git worktree add ../there3 main &&
169 cd ../there3 &&
170 # Simple check that a Git command does not
171 # immediately fail with the current setup
172 git status
173 ) &&
174 cat >expect <<-EOF &&
175 init.t
176 EOF
177 ls there3 >actual &&
178 test_cmp expect actual
179'
180
181test_expect_success '"add" to bare repo with worktree config' '
182 (
183 git clone --bare . bare3 &&
184 cd bare3 &&
185 git config extensions.worktreeconfig true &&
186
187 # Add config values that are erroneous to have in
188 # a config.worktree file outside of the main
189 # working tree, to check that Git filters them out
190 # when copying config during "git worktree add".
191 git config --worktree core.bare true &&
192 git config --worktree core.worktree "$(pwd)" &&
193
194 # We want to check that bogus.key is copied
195 git config --worktree bogus.key value &&
196 git config --unset core.bare &&
197 git worktree add ../there4 main &&
198 cd ../there4 &&
199
200 # Simple check that a Git command does not
201 # immediately fail with the current setup
202 git status &&
203 git worktree add --detach ../there5 &&
204 cd ../there5 &&
205 git status
206 ) &&
207
208 # the worktree has the arbitrary value copied.
209 test_cmp_config -C there4 value bogus.key &&
210 test_cmp_config -C there5 value bogus.key &&
211
212 # however, core.bare and core.worktree were removed.
213 test_must_fail git -C there4 config core.bare &&
214 test_must_fail git -C there4 config core.worktree &&
215
216 cat >expect <<-EOF &&
217 init.t
218 EOF
219
220 ls there4 >actual &&
221 test_cmp expect actual &&
222 ls there5 >actual &&
223 test_cmp expect actual
171c646f
DK
224'
225
ad35f615
NTND
226test_expect_success 'checkout with grafts' '
227 test_when_finished rm .git/info/grafts &&
228 test_commit abc &&
697b90d7 229 SHA1=$(git rev-parse HEAD) &&
ad35f615
NTND
230 test_commit def &&
231 test_commit xyz &&
697b90d7 232 echo "$(git rev-parse HEAD) $SHA1" >.git/info/grafts &&
ad35f615
NTND
233 cat >expected <<-\EOF &&
234 xyz
235 abc
236 EOF
237 git log --format=%s -2 >actual &&
238 test_cmp expected actual &&
883b98ef 239 git worktree add --detach grafted main &&
ad35f615
NTND
240 git --git-dir=grafted/.git log --format=%s -2 >actual &&
241 test_cmp expected actual
242'
243
f194b1ef 244test_expect_success '"add" from relative HEAD' '
c990a4c1
ES
245 test_commit a &&
246 test_commit b &&
247 test_commit c &&
248 git rev-parse HEAD~1 >expected &&
f194b1ef 249 git worktree add relhead HEAD~1 &&
c990a4c1
ES
250 git -C relhead rev-parse HEAD >actual &&
251 test_cmp expected actual
252'
253
0f4af3b9
ES
254test_expect_success '"add -b" with <branch> omitted' '
255 git worktree add -b burble flornk &&
256 test_cmp_rev HEAD burble
257'
258
5c942570
ES
259test_expect_success '"add --detach" with <branch> omitted' '
260 git worktree add --detach fishhook &&
261 git rev-parse HEAD >expected &&
262 git -C fishhook rev-parse HEAD >actual &&
263 test_cmp expected actual &&
264 test_must_fail git -C fishhook symbolic-ref HEAD
265'
266
1eb07d82
ES
267test_expect_success '"add" with <branch> omitted' '
268 git worktree add wiffle/bat &&
269 test_cmp_rev HEAD bat
270'
271
f60a7b76
TG
272test_expect_success '"add" checks out existing branch of dwimd name' '
273 git branch dwim HEAD~1 &&
274 git worktree add dwim &&
275 test_cmp_rev HEAD~1 dwim &&
276 (
277 cd dwim &&
278 test_cmp_rev HEAD dwim
279 )
280'
281
282test_expect_success '"add <path>" dwim fails with checked out branch' '
283 git checkout -b test-branch &&
284 test_must_fail git worktree add test-branch &&
285 test_path_is_missing test-branch
286'
287
288test_expect_success '"add --force" with existing dwimd name doesnt die' '
289 git checkout test-branch &&
290 git worktree add --force test-branch
1eb07d82
ES
291'
292
5c942570
ES
293test_expect_success '"add" no auto-vivify with --detach and <branch> omitted' '
294 git worktree add --detach mish/mash &&
295 test_must_fail git rev-parse mash -- &&
296 test_must_fail git -C mish/mash symbolic-ref HEAD
297'
298
ab0b2c53 299test_expect_success '"add" -b/-B mutually exclusive' '
883b98ef 300 test_must_fail git worktree add -b poodle -B poodle bamboo main
ab0b2c53
ES
301'
302
303test_expect_success '"add" -b/--detach mutually exclusive' '
883b98ef 304 test_must_fail git worktree add -b poodle --detach bamboo main
ab0b2c53
ES
305'
306
307test_expect_success '"add" -B/--detach mutually exclusive' '
883b98ef 308 test_must_fail git worktree add -B poodle --detach bamboo main
ab0b2c53
ES
309'
310
beb6f24b 311test_expect_success '"add -B" fails if the branch is checked out' '
883b98ef
JS
312 git rev-parse newmain >before &&
313 test_must_fail git worktree add -B newmain bamboo main &&
314 git rev-parse newmain >after &&
beb6f24b
NTND
315 test_cmp before after
316'
317
0ebf4a2a 318test_expect_success 'add -B' '
883b98ef 319 git worktree add -B poodle bamboo2 main^ &&
0ebf4a2a
NTND
320 git -C bamboo2 symbolic-ref HEAD >actual &&
321 echo refs/heads/poodle >expected &&
322 test_cmp expected actual &&
883b98ef 323 test_cmp_rev main^ poodle
0ebf4a2a
NTND
324'
325
371979c2 326test_expect_success 'add --quiet' '
883b98ef 327 git worktree add --quiet another-worktree main 2>actual &&
371979c2
EP
328 test_must_be_empty actual
329'
330
744e4697
NTND
331test_expect_success 'local clone from linked checkout' '
332 git clone --local here here-clone &&
333 ( cd here-clone && git fsck )
334'
335
b3b05971
ES
336test_expect_success 'local clone --shared from linked checkout' '
337 git -C bare worktree add --detach ../baretree &&
338 git clone --local --shared baretree bare-clone &&
339 grep /bare/ bare-clone/.git/objects/info/alternates
340'
341
ef2a0ac9
RZ
342test_expect_success '"add" worktree with --no-checkout' '
343 git worktree add --no-checkout -b swamp swamp &&
344 ! test -e swamp/init.t &&
345 git -C swamp reset --hard &&
346 test_cmp init.t swamp/init.t
347'
348
349test_expect_success '"add" worktree with --checkout' '
350 git worktree add --checkout -b swmap2 swamp2 &&
351 test_cmp init.t swamp2/init.t
352'
353
8d9fdd70
NTND
354test_expect_success 'put a worktree under rebase' '
355 git worktree add under-rebase &&
356 (
357 cd under-rebase &&
358 set_fake_editor &&
359 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
360 git worktree list | grep "under-rebase.*detached HEAD"
361 )
362'
363
364test_expect_success 'add a worktree, checking out a rebased branch' '
365 test_must_fail git worktree add new-rebase under-rebase &&
366 ! test -d new-rebase
367'
368
369test_expect_success 'checking out a rebased branch from another worktree' '
370 git worktree add new-place &&
371 test_must_fail git -C new-place checkout under-rebase
372'
373
374test_expect_success 'not allow to delete a branch under rebase' '
375 (
376 cd under-rebase &&
377 test_must_fail git branch -D under-rebase
378 )
379'
380
14ace5b7
NTND
381test_expect_success 'rename a branch under rebase not allowed' '
382 test_must_fail git branch -M under-rebase rebase-with-new-name
383'
384
8d9fdd70
NTND
385test_expect_success 'check out from current worktree branch ok' '
386 (
387 cd under-rebase &&
388 git checkout under-rebase &&
389 git checkout - &&
390 git rebase --abort
391 )
392'
393
04a3dfb8
NTND
394test_expect_success 'checkout a branch under bisect' '
395 git worktree add under-bisect &&
396 (
397 cd under-bisect &&
398 git bisect start &&
399 git bisect bad &&
400 git bisect good HEAD~2 &&
401 git worktree list | grep "under-bisect.*detached HEAD" &&
402 test_must_fail git worktree add new-bisect under-bisect &&
403 ! test -d new-bisect
404 )
405'
406
14ace5b7
NTND
407test_expect_success 'rename a branch under bisect not allowed' '
408 test_must_fail git branch -M under-bisect bisect-with-new-name
409'
e284e892
TG
410# Is branch "refs/heads/$1" set to pull from "$2/$3"?
411test_branch_upstream () {
412 printf "%s\n" "$2" "refs/heads/$3" >expect.upstream &&
413 {
414 git config "branch.$1.remote" &&
415 git config "branch.$1.merge"
416 } >actual.upstream &&
417 test_cmp expect.upstream actual.upstream
418}
419
420test_expect_success '--track sets up tracking' '
421 test_when_finished rm -rf track &&
883b98ef
JS
422 git worktree add --track -b track track main &&
423 test_branch_upstream track . main
e284e892
TG
424'
425
426# setup remote repository $1 and repository $2 with $1 set up as
883b98ef 427# remote. The remote has two branches, main and foo.
e284e892
TG
428setup_remote_repo () {
429 git init $1 &&
430 (
431 cd $1 &&
883b98ef 432 test_commit $1_main &&
e284e892
TG
433 git checkout -b foo &&
434 test_commit upstream_foo
435 ) &&
436 git init $2 &&
437 (
438 cd $2 &&
883b98ef 439 test_commit $2_main &&
e284e892
TG
440 git remote add $1 ../$1 &&
441 git config remote.$1.fetch \
442 "refs/heads/*:refs/remotes/$1/*" &&
443 git fetch --all
444 )
445}
446
447test_expect_success '--no-track avoids setting up tracking' '
448 test_when_finished rm -rf repo_upstream repo_local foo &&
449 setup_remote_repo repo_upstream repo_local &&
450 (
451 cd repo_local &&
452 git worktree add --no-track -b foo ../foo repo_upstream/foo
453 ) &&
454 (
455 cd foo &&
456 test_must_fail git config "branch.foo.remote" &&
457 test_must_fail git config "branch.foo.merge" &&
458 test_cmp_rev refs/remotes/repo_upstream/foo refs/heads/foo
459 )
460'
14ace5b7 461
4e853331
TG
462test_expect_success '"add" <path> <non-existent-branch> fails' '
463 test_must_fail git worktree add foo non-existent
464'
465
466test_expect_success '"add" <path> <branch> dwims' '
467 test_when_finished rm -rf repo_upstream repo_dwim foo &&
468 setup_remote_repo repo_upstream repo_dwim &&
469 git init repo_dwim &&
470 (
471 cd repo_dwim &&
472 git worktree add ../foo foo
473 ) &&
474 (
475 cd foo &&
476 test_branch_upstream foo repo_upstream foo &&
477 test_cmp_rev refs/remotes/repo_upstream/foo refs/heads/foo
478 )
479'
480
8d7b558b
ÆAB
481test_expect_success '"add" <path> <branch> dwims with checkout.defaultRemote' '
482 test_when_finished rm -rf repo_upstream repo_dwim foo &&
483 setup_remote_repo repo_upstream repo_dwim &&
484 git init repo_dwim &&
485 (
486 cd repo_dwim &&
487 git remote add repo_upstream2 ../repo_upstream &&
488 git fetch repo_upstream2 &&
489 test_must_fail git worktree add ../foo foo &&
490 git -c checkout.defaultRemote=repo_upstream worktree add ../foo foo &&
8d7b558b 491 git status -uno --porcelain >status.actual &&
9f4bcf81 492 test_must_be_empty status.actual
8d7b558b
ÆAB
493 ) &&
494 (
495 cd foo &&
496 test_branch_upstream foo repo_upstream foo &&
497 test_cmp_rev refs/remotes/repo_upstream/foo refs/heads/foo
498 )
499'
500
71d6682d
TG
501test_expect_success 'git worktree add does not match remote' '
502 test_when_finished rm -rf repo_a repo_b foo &&
503 setup_remote_repo repo_a repo_b &&
504 (
505 cd repo_b &&
506 git worktree add ../foo
507 ) &&
508 (
509 cd foo &&
510 test_must_fail git config "branch.foo.remote" &&
511 test_must_fail git config "branch.foo.merge" &&
2c9e125b 512 test_cmp_rev ! refs/remotes/repo_a/foo refs/heads/foo
71d6682d
TG
513 )
514'
515
516test_expect_success 'git worktree add --guess-remote sets up tracking' '
517 test_when_finished rm -rf repo_a repo_b foo &&
518 setup_remote_repo repo_a repo_b &&
519 (
520 cd repo_b &&
521 git worktree add --guess-remote ../foo
522 ) &&
523 (
524 cd foo &&
525 test_branch_upstream foo repo_a foo &&
526 test_cmp_rev refs/remotes/repo_a/foo refs/heads/foo
527 )
528'
529
e92445a7
TG
530test_expect_success 'git worktree add with worktree.guessRemote sets up tracking' '
531 test_when_finished rm -rf repo_a repo_b foo &&
532 setup_remote_repo repo_a repo_b &&
533 (
534 cd repo_b &&
535 git config worktree.guessRemote true &&
536 git worktree add ../foo
537 ) &&
538 (
539 cd foo &&
540 test_branch_upstream foo repo_a foo &&
541 test_cmp_rev refs/remotes/repo_a/foo refs/heads/foo
542 )
543'
544
545test_expect_success 'git worktree --no-guess-remote option overrides config' '
546 test_when_finished rm -rf repo_a repo_b foo &&
547 setup_remote_repo repo_a repo_b &&
548 (
549 cd repo_b &&
550 git config worktree.guessRemote true &&
551 git worktree add --no-guess-remote ../foo
552 ) &&
553 (
554 cd foo &&
555 test_must_fail git config "branch.foo.remote" &&
556 test_must_fail git config "branch.foo.merge" &&
2c9e125b 557 test_cmp_rev ! refs/remotes/repo_a/foo refs/heads/foo
e92445a7
TG
558 )
559'
560
ade546be 561post_checkout_hook () {
66865d12 562 test_hook -C "$1" post-checkout <<-\EOF
a4bf1e3c
ES
563 {
564 echo $*
565 git rev-parse --git-dir --show-toplevel
566 } >hook.actual
ade546be
ES
567 EOF
568}
569
570test_expect_success '"add" invokes post-checkout hook (branch)' '
571 post_checkout_hook &&
a4bf1e3c 572 {
8125a58b 573 echo $ZERO_OID $(git rev-parse HEAD) 1 &&
a4bf1e3c
ES
574 echo $(pwd)/.git/worktrees/gumby &&
575 echo $(pwd)/gumby
576 } >hook.expect &&
ade546be 577 git worktree add gumby &&
a4bf1e3c 578 test_cmp hook.expect gumby/hook.actual
ade546be
ES
579'
580
581test_expect_success '"add" invokes post-checkout hook (detached)' '
582 post_checkout_hook &&
a4bf1e3c 583 {
8125a58b 584 echo $ZERO_OID $(git rev-parse HEAD) 1 &&
a4bf1e3c
ES
585 echo $(pwd)/.git/worktrees/grumpy &&
586 echo $(pwd)/grumpy
587 } >hook.expect &&
ade546be 588 git worktree add --detach grumpy &&
a4bf1e3c 589 test_cmp hook.expect grumpy/hook.actual
ade546be
ES
590'
591
592test_expect_success '"add --no-checkout" suppresses post-checkout hook' '
593 post_checkout_hook &&
594 rm -f hook.actual &&
595 git worktree add --no-checkout gloopy &&
a4bf1e3c
ES
596 test_path_is_missing gloopy/hook.actual
597'
598
599test_expect_success '"add" in other worktree invokes post-checkout hook' '
600 post_checkout_hook &&
601 {
8125a58b 602 echo $ZERO_OID $(git rev-parse HEAD) 1 &&
a4bf1e3c
ES
603 echo $(pwd)/.git/worktrees/guppy &&
604 echo $(pwd)/guppy
605 } >hook.expect &&
606 git -C gloopy worktree add --detach ../guppy &&
607 test_cmp hook.expect guppy/hook.actual
608'
609
610test_expect_success '"add" in bare repo invokes post-checkout hook' '
611 rm -rf bare &&
612 git clone --bare . bare &&
613 {
8125a58b 614 echo $ZERO_OID $(git --git-dir=bare rev-parse HEAD) 1 &&
a4bf1e3c
ES
615 echo $(pwd)/bare/worktrees/goozy &&
616 echo $(pwd)/goozy
617 } >hook.expect &&
618 post_checkout_hook bare &&
619 git -C bare worktree add --detach ../goozy &&
620 test_cmp hook.expect goozy/hook.actual
ade546be
ES
621'
622
cb56f55c
ES
623test_expect_success '"add" an existing but missing worktree' '
624 git worktree add --detach pneu &&
625 test_must_fail git worktree add --detach pneu &&
626 rm -fr pneu &&
e19831c9
ES
627 test_must_fail git worktree add --detach pneu &&
628 git worktree add --force --detach pneu
629'
630
631test_expect_success '"add" an existing locked but missing worktree' '
632 git worktree add --detach gnoo &&
633 git worktree lock gnoo &&
634 test_when_finished "git worktree unlock gnoo || :" &&
635 rm -fr gnoo &&
636 test_must_fail git worktree add --detach gnoo &&
637 test_must_fail git worktree add --force --detach gnoo &&
638 git worktree add --force --force --detach gnoo
cb56f55c
ES
639'
640
bb69b3b0
ES
641test_expect_success '"add" not tripped up by magic worktree matching"' '
642 # if worktree "sub1/bar" exists, "git worktree add bar" in distinct
643 # directory `sub2` should not mistakenly complain that `bar` is an
644 # already-registered worktree
645 mkdir sub1 sub2 &&
646 git -C sub1 --git-dir=../.git worktree add --detach bozo &&
647 git -C sub2 --git-dir=../.git worktree add --detach bozo
648'
649
1de16aec
NTND
650test_expect_success FUNNYNAMES 'sanitize generated worktree name' '
651 git worktree add --detach ". weird*..?.lock.lock" &&
652 test -d .git/worktrees/---weird-.-
653'
654
105df73e
NTND
655test_expect_success '"add" should not fail because of another bad worktree' '
656 git init add-fail &&
657 (
658 cd add-fail &&
659 test_commit first &&
660 mkdir sub &&
661 git worktree add sub/to-be-deleted &&
662 rm -rf sub &&
663 git worktree add second
664 )
665'
666
4782cf2a 667test_expect_success '"add" with uninitialized submodule, with submodule.recurse unset' '
99f4abb8 668 test_config_global protocol.file.allow always &&
4782cf2a
PB
669 test_create_repo submodule &&
670 test_commit -C submodule first &&
671 test_create_repo project &&
672 git -C project submodule add ../submodule &&
673 git -C project add submodule &&
674 test_tick &&
675 git -C project commit -m add_sub &&
676 git clone project project-clone &&
677 git -C project-clone worktree add ../project-2
678'
679test_expect_success '"add" with uninitialized submodule, with submodule.recurse set' '
680 git -C project-clone -c submodule.recurse worktree add ../project-3
681'
682
683test_expect_success '"add" with initialized submodule, with submodule.recurse unset' '
99f4abb8 684 test_config_global protocol.file.allow always &&
4782cf2a
PB
685 git -C project-clone submodule update --init &&
686 git -C project-clone worktree add ../project-4
687'
688
689test_expect_success '"add" with initialized submodule, with submodule.recurse set' '
690 git -C project-clone -c submodule.recurse worktree add ../project-5
691'
692
529fef20 693test_done