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