t0001,t1510,t3301: use sane_unset which always returns with status 0
[git] / t / t1510-repo-setup.sh
1 #!/bin/sh
2
3 test_description='Tests of cwd/prefix/worktree/gitdir setup in all cases'
4
5 . ./test-lib.sh
6
7 #
8 # A few rules for repo setup:
9 #
10 # 1. GIT_DIR is relative to user's cwd. --git-dir is equivalent to
11 #    GIT_DIR.
12 #
13 # 2. .git file is relative to parent directory. .git file is basically
14 #    symlink in disguise. The directory where .git file points to will
15 #    become new git_dir.
16 #
17 # 3. core.worktree is relative to git_dir.
18 #
19 # 4. GIT_WORK_TREE is relative to user's cwd. --work-tree is
20 #    equivalent to GIT_WORK_TREE.
21 #
22 # 5. GIT_WORK_TREE/core.worktree is only effective if GIT_DIR is set
23 #    Uneffective worktree settings should be warned.
24 #
25 # 6. Effective GIT_WORK_TREE overrides core.worktree and core.bare
26 #
27 # 7. Effective core.worktree conflicts with core.bare
28 #
29 # 8. If GIT_DIR is set but neither worktree nor bare setting is given,
30 #    original cwd becomes worktree.
31 #
32 # 9. If .git discovery is done inside a repo, the repo becomes a bare
33 #    repo. .git discovery is performed if GIT_DIR is not set.
34 #
35 # 10. If no worktree is available, cwd remains unchanged, prefix is
36 #     NULL.
37 #
38 # 11. When user's cwd is outside worktree, cwd remains unchanged,
39 #     prefix is NULL.
40 #
41
42 test_repo() {
43         (
44         cd "$1" &&
45         if test -n "$2"; then GIT_DIR="$2" && export GIT_DIR; fi &&
46         if test -n "$3"; then GIT_WORK_TREE="$3" && export GIT_WORK_TREE; fi &&
47         rm -f trace &&
48         GIT_TRACE="`pwd`/trace" git symbolic-ref HEAD >/dev/null &&
49         grep '^setup: ' trace >result &&
50         test_cmp expected result
51         )
52 }
53
54 # Bit 0 = GIT_WORK_TREE
55 # Bit 1 = GIT_DIR
56 # Bit 2 = core.worktree
57 # Bit 3 = .git is a file
58 # Bit 4 = bare repo
59 # Case# = encoding of the above 5 bits
60
61 #
62 # Case #0
63 #
64 ############################################################
65 #
66 # Input:
67 #
68 #  - GIT_WORK_TREE is not set
69 #  - GIT_DIR is not set
70 #  - core.worktree is not set
71 #  - .git is a directory
72 #  - core.bare is not set, cwd is outside .git
73 #
74 # Output:
75 #
76 #  - worktree is .git's parent directory
77 #  - cwd is at worktree root dir
78 #  - prefix is calculated
79 #  - git_dir is set to ".git"
80 #  - cwd can't be outside worktree
81
82 test_expect_success '#0: setup' '
83         sane_unset GIT_DIR GIT_WORK_TREE &&
84         mkdir 0 0/sub &&
85         cd 0 && git init && cd ..
86 '
87
88 test_expect_success '#0: at root' '
89         cat >0/expected <<EOF &&
90 setup: git_dir: .git
91 setup: worktree: $TRASH_DIRECTORY/0
92 setup: cwd: $TRASH_DIRECTORY/0
93 setup: prefix: (null)
94 EOF
95         test_repo 0
96 '
97
98 test_expect_success '#0: in subdir' '
99         cat >0/sub/expected <<EOF &&
100 setup: git_dir: .git
101 setup: worktree: $TRASH_DIRECTORY/0
102 setup: cwd: $TRASH_DIRECTORY/0
103 setup: prefix: sub/
104 EOF
105         test_repo 0/sub
106 '
107
108 #
109 # case #1
110 #
111 ############################################################
112 #
113 # Input:
114 #
115 #  - GIT_WORK_TREE is set
116 #  - GIT_DIR is not set
117 #  - core.worktree is not set
118 #  - .git is a directory
119 #  - core.bare is not set, cwd is outside .git
120 #
121 # Output:
122 #
123 # GIT_WORK_TREE is ignored -> #0
124
125 test_expect_success '#1: setup' '
126         sane_unset GIT_DIR GIT_WORK_TREE &&
127         mkdir 1 1/sub 1.wt 1.wt/sub 1/wt 1/wt/sub &&
128         cd 1 &&
129         git init &&
130         GIT_WORK_TREE=non-existent &&
131         export GIT_WORK_TREE &&
132         cd ..
133 '
134
135 test_expect_success '#1: at root' '
136         cat >1/expected <<EOF &&
137 setup: git_dir: .git
138 setup: worktree: $TRASH_DIRECTORY/1
139 setup: cwd: $TRASH_DIRECTORY/1
140 setup: prefix: (null)
141 EOF
142         test_repo 1
143 '
144
145 test_expect_success '#1: in subdir' '
146         cat >1/sub/expected <<EOF &&
147 setup: git_dir: .git
148 setup: worktree: $TRASH_DIRECTORY/1
149 setup: cwd: $TRASH_DIRECTORY/1
150 setup: prefix: sub/
151 EOF
152         test_repo 1/sub
153 '
154
155 #
156 # case #2
157 #
158 ############################################################
159 #
160 # Input:
161 #
162 #  - GIT_WORK_TREE is not set
163 #  - GIT_DIR is set
164 #  - core.worktree is not set
165 #  - .git is a directory
166 #  - core.bare is not set, cwd is outside .git
167 #
168 # Output:
169 #
170 #  - worktree is at original cwd
171 #  - cwd is unchanged
172 #  - prefix is NULL
173 #  - git_dir is set to $GIT_DIR
174 #  - cwd can't be outside worktree
175
176 test_expect_success '#2: setup' '
177         sane_unset GIT_DIR GIT_WORK_TREE &&
178         mkdir 2 2/sub &&
179         cd 2 && git init && cd ..
180 '
181
182 test_expect_success '#2: at root' '
183         cat >2/expected <<EOF &&
184 setup: git_dir: $TRASH_DIRECTORY/2/.git
185 setup: worktree: $TRASH_DIRECTORY/2
186 setup: cwd: $TRASH_DIRECTORY/2
187 setup: prefix: (null)
188 EOF
189         test_repo 2 "$TRASH_DIRECTORY/2/.git"
190 '
191
192 test_expect_success '#2: in subdir' '
193         cat >2/sub/expected <<EOF &&
194 setup: git_dir: $TRASH_DIRECTORY/2/.git
195 setup: worktree: $TRASH_DIRECTORY/2/sub
196 setup: cwd: $TRASH_DIRECTORY/2/sub
197 setup: prefix: (null)
198 EOF
199         test_repo 2/sub "$TRASH_DIRECTORY/2/.git"
200 '
201
202 test_expect_success '#2: relative GIT_DIR at root' '
203         cat >2/expected <<EOF &&
204 setup: git_dir: .git
205 setup: worktree: $TRASH_DIRECTORY/2
206 setup: cwd: $TRASH_DIRECTORY/2
207 setup: prefix: (null)
208 EOF
209         test_repo 2 .git
210 '
211
212 test_expect_success '#2: relative GIT_DIR in subdir' '
213         cat >2/sub/expected <<EOF &&
214 setup: git_dir: ../.git
215 setup: worktree: $TRASH_DIRECTORY/2/sub
216 setup: cwd: $TRASH_DIRECTORY/2/sub
217 setup: prefix: (null)
218 EOF
219         test_repo 2/sub ../.git
220 '
221
222 #
223 # case #3
224 #
225 ############################################################
226 #
227 # Input:
228 #
229 #  - GIT_WORK_TREE is set
230 #  - GIT_DIR is set
231 #  - core.worktree is not set
232 #  - .git is a directory
233 #  - core.bare is not set, cwd is outside .git
234 #
235 # Output:
236 #
237 #  - worktree is set to $GIT_WORK_TREE
238 #  - cwd is at worktree root
239 #  - prefix is calculated
240 #  - git_dir is set to $GIT_DIR
241 #  - cwd can be outside worktree
242
243 test_expect_success '#3: setup' '
244         sane_unset GIT_DIR GIT_WORK_TREE &&
245         mkdir 3 3/sub 3/sub/sub 3.wt 3.wt/sub 3/wt 3/wt/sub &&
246         cd 3 && git init && cd ..
247 '
248
249 test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=root at root' '
250         cat >3/expected <<EOF &&
251 setup: git_dir: .git
252 setup: worktree: $TRASH_DIRECTORY/3
253 setup: cwd: $TRASH_DIRECTORY/3
254 setup: prefix: (null)
255 EOF
256         test_repo 3 .git "$TRASH_DIRECTORY/3"
257 '
258
259 test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=root(rel) at root' '
260         cat >3/expected <<EOF &&
261 setup: git_dir: .git
262 setup: worktree: $TRASH_DIRECTORY/3
263 setup: cwd: $TRASH_DIRECTORY/3
264 setup: prefix: (null)
265 EOF
266         test_repo 3 .git .
267 '
268
269 test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=root at root' '
270         cat >3/expected <<EOF &&
271 setup: git_dir: $TRASH_DIRECTORY/3/.git
272 setup: worktree: $TRASH_DIRECTORY/3
273 setup: cwd: $TRASH_DIRECTORY/3
274 setup: prefix: (null)
275 EOF
276         test_repo 3 "$TRASH_DIRECTORY/3/.git" "$TRASH_DIRECTORY/3"
277 '
278
279 test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=root(rel) at root' '
280         cat >3/expected <<EOF &&
281 setup: git_dir: $TRASH_DIRECTORY/3/.git
282 setup: worktree: $TRASH_DIRECTORY/3
283 setup: cwd: $TRASH_DIRECTORY/3
284 setup: prefix: (null)
285 EOF
286         test_repo 3 "$TRASH_DIRECTORY/3/.git" .
287 '
288
289 test_expect_success '#3: GIT_DIR(rel), GIT_WORKTREE=root in subdir' '
290         cat >3/sub/sub/expected <<EOF &&
291 setup: git_dir: $TRASH_DIRECTORY/3/.git
292 setup: worktree: $TRASH_DIRECTORY/3
293 setup: cwd: $TRASH_DIRECTORY/3
294 setup: prefix: sub/sub/
295 EOF
296         test_repo 3/sub/sub ../../.git "$TRASH_DIRECTORY/3"
297 '
298
299 test_expect_success '#3: GIT_DIR(rel), GIT_WORKTREE=root(rel) in subdir' '
300         cat >3/sub/sub/expected <<EOF &&
301 setup: git_dir: $TRASH_DIRECTORY/3/.git
302 setup: worktree: $TRASH_DIRECTORY/3
303 setup: cwd: $TRASH_DIRECTORY/3
304 setup: prefix: sub/sub/
305 EOF
306         test_repo 3/sub/sub ../../.git ../..
307 '
308
309 test_expect_success '#3: GIT_DIR, GIT_WORKTREE=root in subdir' '
310         cat >3/sub/expected <<EOF &&
311 setup: git_dir: $TRASH_DIRECTORY/3/.git
312 setup: worktree: $TRASH_DIRECTORY/3
313 setup: cwd: $TRASH_DIRECTORY/3
314 setup: prefix: sub/
315 EOF
316         test_repo 3/sub "$TRASH_DIRECTORY/3/.git" "$TRASH_DIRECTORY/3"
317 '
318
319 test_expect_success '#3: GIT_DIR, GIT_WORKTREE=root(rel) in subdir' '
320         cat >3/sub/sub/expected <<EOF &&
321 setup: git_dir: $TRASH_DIRECTORY/3/.git
322 setup: worktree: $TRASH_DIRECTORY/3
323 setup: cwd: $TRASH_DIRECTORY/3
324 setup: prefix: sub/sub/
325 EOF
326         test_repo 3/sub/sub "$TRASH_DIRECTORY/3/.git" ../..
327 '
328
329 test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=wt at root' '
330         cat >3/expected <<EOF &&
331 setup: git_dir: .git
332 setup: worktree: $TRASH_DIRECTORY/3/wt
333 setup: cwd: $TRASH_DIRECTORY/3
334 setup: prefix: (null)
335 EOF
336         test_repo 3 .git "$TRASH_DIRECTORY/3/wt"
337 '
338
339 test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) at root' '
340         cat >3/expected <<EOF &&
341 setup: git_dir: .git
342 setup: worktree: $TRASH_DIRECTORY/3/wt
343 setup: cwd: $TRASH_DIRECTORY/3
344 setup: prefix: (null)
345 EOF
346         test_repo 3 .git wt
347 '
348
349 test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=wt(rel) at root' '
350         cat >3/expected <<EOF &&
351 setup: git_dir: $TRASH_DIRECTORY/3/.git
352 setup: worktree: $TRASH_DIRECTORY/3/wt
353 setup: cwd: $TRASH_DIRECTORY/3
354 setup: prefix: (null)
355 EOF
356         test_repo 3 "$TRASH_DIRECTORY/3/.git" wt
357 '
358
359 test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=wt at root' '
360         cat >3/expected <<EOF &&
361 setup: git_dir: $TRASH_DIRECTORY/3/.git
362 setup: worktree: $TRASH_DIRECTORY/3/wt
363 setup: cwd: $TRASH_DIRECTORY/3
364 setup: prefix: (null)
365 EOF
366         test_repo 3 "$TRASH_DIRECTORY/3/.git" "$TRASH_DIRECTORY/3/wt"
367 '
368
369 test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=wt in subdir' '
370         cat >3/sub/sub/expected <<EOF &&
371 setup: git_dir: ../../.git
372 setup: worktree: $TRASH_DIRECTORY/3/wt
373 setup: cwd: $TRASH_DIRECTORY/3/sub/sub
374 setup: prefix: (null)
375 EOF
376         test_repo 3/sub/sub ../../.git "$TRASH_DIRECTORY/3/wt"
377 '
378
379 test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) in subdir' '
380         cat >3/sub/sub/expected <<EOF &&
381 setup: git_dir: ../../.git
382 setup: worktree: $TRASH_DIRECTORY/3/wt
383 setup: cwd: $TRASH_DIRECTORY/3/sub/sub
384 setup: prefix: (null)
385 EOF
386         test_repo 3/sub/sub ../../.git ../../wt
387 '
388
389 test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=wt(rel) in subdir' '
390         cat >3/sub/sub/expected <<EOF &&
391 setup: git_dir: $TRASH_DIRECTORY/3/.git
392 setup: worktree: $TRASH_DIRECTORY/3/wt
393 setup: cwd: $TRASH_DIRECTORY/3/sub/sub
394 setup: prefix: (null)
395 EOF
396         test_repo 3/sub/sub "$TRASH_DIRECTORY/3/.git" ../../wt
397 '
398
399 test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=wt in subdir' '
400         cat >3/sub/sub/expected <<EOF &&
401 setup: git_dir: $TRASH_DIRECTORY/3/.git
402 setup: worktree: $TRASH_DIRECTORY/3/wt
403 setup: cwd: $TRASH_DIRECTORY/3/sub/sub
404 setup: prefix: (null)
405 EOF
406         test_repo 3/sub/sub "$TRASH_DIRECTORY/3/.git" "$TRASH_DIRECTORY/3/wt"
407 '
408
409 test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=.. at root' '
410         cat >3/expected <<EOF &&
411 setup: git_dir: $TRASH_DIRECTORY/3/.git
412 setup: worktree: $TRASH_DIRECTORY
413 setup: cwd: $TRASH_DIRECTORY
414 setup: prefix: 3/
415 EOF
416         test_repo 3 .git "$TRASH_DIRECTORY"
417 '
418
419 test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=..(rel) at root' '
420         cat >3/expected <<EOF &&
421 setup: git_dir: $TRASH_DIRECTORY/3/.git
422 setup: worktree: $TRASH_DIRECTORY
423 setup: cwd: $TRASH_DIRECTORY
424 setup: prefix: 3/
425 EOF
426         test_repo 3 .git ..
427 '
428
429 test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=..(rel) at root' '
430         cat >3/expected <<EOF &&
431 setup: git_dir: $TRASH_DIRECTORY/3/.git
432 setup: worktree: $TRASH_DIRECTORY
433 setup: cwd: $TRASH_DIRECTORY
434 setup: prefix: 3/
435 EOF
436         test_repo 3 "$TRASH_DIRECTORY/3/.git" ..
437 '
438
439 test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=.. at root' '
440         cat >3/expected <<EOF &&
441 setup: git_dir: $TRASH_DIRECTORY/3/.git
442 setup: worktree: $TRASH_DIRECTORY
443 setup: cwd: $TRASH_DIRECTORY
444 setup: prefix: 3/
445 EOF
446         test_repo 3 "$TRASH_DIRECTORY/3/.git" "$TRASH_DIRECTORY"
447 '
448
449 test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=.. in subdir' '
450         cat >3/sub/sub/expected <<EOF &&
451 setup: git_dir: $TRASH_DIRECTORY/3/.git
452 setup: worktree: $TRASH_DIRECTORY
453 setup: cwd: $TRASH_DIRECTORY
454 setup: prefix: 3/sub/sub/
455 EOF
456         test_repo 3/sub/sub ../../.git "$TRASH_DIRECTORY"
457 '
458
459 test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=..(rel) in subdir' '
460         cat >3/sub/sub/expected <<EOF &&
461 setup: git_dir: $TRASH_DIRECTORY/3/.git
462 setup: worktree: $TRASH_DIRECTORY
463 setup: cwd: $TRASH_DIRECTORY
464 setup: prefix: 3/sub/sub/
465 EOF
466         test_repo 3/sub/sub ../../.git ../../..
467 '
468
469 test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=..(rel) in subdir' '
470         cat >3/sub/sub/expected <<EOF &&
471 setup: git_dir: $TRASH_DIRECTORY/3/.git
472 setup: worktree: $TRASH_DIRECTORY
473 setup: cwd: $TRASH_DIRECTORY
474 setup: prefix: 3/sub/sub/
475 EOF
476         test_repo 3/sub/sub "$TRASH_DIRECTORY/3/.git" ../../../
477 '
478
479 test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=.. in subdir' '
480         cat >3/sub/sub/expected <<EOF &&
481 setup: git_dir: $TRASH_DIRECTORY/3/.git
482 setup: worktree: $TRASH_DIRECTORY
483 setup: cwd: $TRASH_DIRECTORY
484 setup: prefix: 3/sub/sub/
485 EOF
486         test_repo 3/sub/sub "$TRASH_DIRECTORY/3/.git" "$TRASH_DIRECTORY"
487 '
488
489 #
490 # case #4
491 #
492 ############################################################
493 #
494 # Input:
495 #
496 #  - GIT_WORK_TREE is not set
497 #  - GIT_DIR is not set
498 #  - core.worktree is set
499 #  - .git is a directory
500 #  - core.bare is not set, cwd is outside .git
501 #
502 # Output:
503 #
504 # core.worktree is ignored -> #0
505
506 test_expect_success '#4: setup' '
507         sane_unset GIT_DIR GIT_WORK_TREE &&
508         mkdir 4 4/sub &&
509         cd 4 &&
510         git init &&
511         git config core.worktree non-existent &&
512         cd ..
513 '
514
515 test_expect_success '#4: at root' '
516         cat >4/expected <<EOF &&
517 setup: git_dir: .git
518 setup: worktree: $TRASH_DIRECTORY/4
519 setup: cwd: $TRASH_DIRECTORY/4
520 setup: prefix: (null)
521 EOF
522         test_repo 4
523 '
524
525 test_expect_success '#4: in subdir' '
526         cat >4/sub/expected <<EOF &&
527 setup: git_dir: .git
528 setup: worktree: $TRASH_DIRECTORY/4
529 setup: cwd: $TRASH_DIRECTORY/4
530 setup: prefix: sub/
531 EOF
532         test_repo 4/sub
533 '
534
535 #
536 # case #5
537 #
538 ############################################################
539 #
540 # Input:
541 #
542 #  - GIT_WORK_TREE is set
543 #  - GIT_DIR is not set
544 #  - core.worktree is set
545 #  - .git is a directory
546 #  - core.bare is not set, cwd is outside .git
547 #
548 # Output:
549 #
550 # GIT_WORK_TREE/core.worktree are ignored -> #0
551
552 test_expect_success '#5: setup' '
553         sane_unset GIT_DIR GIT_WORK_TREE &&
554         mkdir 5 5/sub &&
555         cd 5 &&
556         git init &&
557         git config core.worktree non-existent &&
558         GIT_WORK_TREE=non-existent-too &&
559         export GIT_WORK_TREE &&
560         cd ..
561 '
562
563 test_expect_success '#5: at root' '
564         cat >5/expected <<EOF &&
565 setup: git_dir: .git
566 setup: worktree: $TRASH_DIRECTORY/5
567 setup: cwd: $TRASH_DIRECTORY/5
568 setup: prefix: (null)
569 EOF
570         test_repo 5
571 '
572
573 test_expect_success '#5: in subdir' '
574         cat >5/sub/expected <<EOF &&
575 setup: git_dir: .git
576 setup: worktree: $TRASH_DIRECTORY/5
577 setup: cwd: $TRASH_DIRECTORY/5
578 setup: prefix: sub/
579 EOF
580         test_repo 5/sub
581 '
582
583 #
584 # case #6
585 #
586 ############################################################
587 #
588 # Input:
589 #
590 #  - GIT_WORK_TREE is not set
591 #  - GIT_DIR is set
592 #  - core.worktree is set
593 #  - .git is a directory
594 #  - core.bare is not set, cwd is outside .git
595 #
596 # Output:
597 #
598 #  - worktree is at core.worktree
599 #  - cwd is at worktree root
600 #  - prefix is calculated
601 #  - git_dir is at $GIT_DIR
602 #  - cwd can be outside worktree
603
604 test_expect_success '#6: setup' '
605         sane_unset GIT_DIR GIT_WORK_TREE &&
606         mkdir 6 6/sub 6/sub/sub 6.wt 6.wt/sub 6/wt 6/wt/sub &&
607         cd 6 && git init && cd ..
608 '
609
610 test_expect_success '#6: GIT_DIR(rel), core.worktree=.. at root' '
611         cat >6/expected <<EOF &&
612 setup: git_dir: .git
613 setup: worktree: $TRASH_DIRECTORY/6
614 setup: cwd: $TRASH_DIRECTORY/6
615 setup: prefix: (null)
616 EOF
617         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY/6" &&
618         test_repo 6 .git
619 '
620
621 test_expect_success '#6: GIT_DIR(rel), core.worktree=..(rel) at root' '
622         cat >6/expected <<EOF &&
623 setup: git_dir: .git
624 setup: worktree: $TRASH_DIRECTORY/6
625 setup: cwd: $TRASH_DIRECTORY/6
626 setup: prefix: (null)
627 EOF
628         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree .. &&
629         test_repo 6 .git
630 '
631
632 test_expect_success '#6: GIT_DIR, core.worktree=.. at root' '
633         cat >6/expected <<EOF &&
634 setup: git_dir: $TRASH_DIRECTORY/6/.git
635 setup: worktree: $TRASH_DIRECTORY/6
636 setup: cwd: $TRASH_DIRECTORY/6
637 setup: prefix: (null)
638 EOF
639         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY/6" &&
640         test_repo 6 "$TRASH_DIRECTORY/6/.git"
641 '
642
643 test_expect_success '#6: GIT_DIR, core.worktree=..(rel) at root' '
644         cat >6/expected <<EOF &&
645 setup: git_dir: $TRASH_DIRECTORY/6/.git
646 setup: worktree: $TRASH_DIRECTORY/6
647 setup: cwd: $TRASH_DIRECTORY/6
648 setup: prefix: (null)
649 EOF
650         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree .. &&
651         test_repo 6 "$TRASH_DIRECTORY/6/.git"
652 '
653
654 test_expect_success '#6: GIT_DIR(rel), core.worktree=.. in subdir' '
655         cat >6/sub/sub/expected <<EOF &&
656 setup: git_dir: $TRASH_DIRECTORY/6/.git
657 setup: worktree: $TRASH_DIRECTORY/6
658 setup: cwd: $TRASH_DIRECTORY/6
659 setup: prefix: sub/sub/
660 EOF
661         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY/6" &&
662         test_repo 6/sub/sub ../../.git
663 '
664
665 test_expect_success '#6: GIT_DIR(rel), core.worktree=..(rel) in subdir' '
666         cat >6/sub/sub/expected <<EOF &&
667 setup: git_dir: $TRASH_DIRECTORY/6/.git
668 setup: worktree: $TRASH_DIRECTORY/6
669 setup: cwd: $TRASH_DIRECTORY/6
670 setup: prefix: sub/sub/
671 EOF
672         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree .. &&
673         test_repo 6/sub/sub ../../.git
674 '
675
676 test_expect_success '#6: GIT_DIR, core.worktree=.. in subdir' '
677         cat >6/sub/expected <<EOF &&
678 setup: git_dir: $TRASH_DIRECTORY/6/.git
679 setup: worktree: $TRASH_DIRECTORY/6
680 setup: cwd: $TRASH_DIRECTORY/6
681 setup: prefix: sub/
682 EOF
683         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY/6" &&
684         test_repo 6/sub "$TRASH_DIRECTORY/6/.git"
685 '
686
687 test_expect_success '#6: GIT_DIR, core.worktree=..(rel) in subdir' '
688         cat >6/sub/sub/expected <<EOF &&
689 setup: git_dir: $TRASH_DIRECTORY/6/.git
690 setup: worktree: $TRASH_DIRECTORY/6
691 setup: cwd: $TRASH_DIRECTORY/6
692 setup: prefix: sub/sub/
693 EOF
694         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree .. &&
695         test_repo 6/sub/sub "$TRASH_DIRECTORY/6/.git"
696 '
697
698 test_expect_success '#6: GIT_DIR(rel), core.worktree=../wt at root' '
699         cat >6/expected <<EOF &&
700 setup: git_dir: .git
701 setup: worktree: $TRASH_DIRECTORY/6/wt
702 setup: cwd: $TRASH_DIRECTORY/6
703 setup: prefix: (null)
704 EOF
705         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY/6/wt" &&
706         test_repo 6 .git
707 '
708
709 test_expect_success '#6: GIT_DIR(rel), core.worktree=../wt(rel) at root' '
710         cat >6/expected <<EOF &&
711 setup: git_dir: .git
712 setup: worktree: $TRASH_DIRECTORY/6/wt
713 setup: cwd: $TRASH_DIRECTORY/6
714 setup: prefix: (null)
715 EOF
716         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree ../wt &&
717         test_repo 6 .git
718 '
719
720 test_expect_success '#6: GIT_DIR, core.worktree=../wt(rel) at root' '
721         cat >6/expected <<EOF &&
722 setup: git_dir: $TRASH_DIRECTORY/6/.git
723 setup: worktree: $TRASH_DIRECTORY/6/wt
724 setup: cwd: $TRASH_DIRECTORY/6
725 setup: prefix: (null)
726 EOF
727         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree ../wt &&
728         test_repo 6 "$TRASH_DIRECTORY/6/.git"
729 '
730
731 test_expect_success '#6: GIT_DIR, core.worktree=../wt at root' '
732         cat >6/expected <<EOF &&
733 setup: git_dir: $TRASH_DIRECTORY/6/.git
734 setup: worktree: $TRASH_DIRECTORY/6/wt
735 setup: cwd: $TRASH_DIRECTORY/6
736 setup: prefix: (null)
737 EOF
738         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY/6/wt" &&
739         test_repo 6 "$TRASH_DIRECTORY/6/.git"
740 '
741
742 test_expect_success '#6: GIT_DIR(rel), core.worktree=../wt in subdir' '
743         cat >6/sub/sub/expected <<EOF &&
744 setup: git_dir: ../../.git
745 setup: worktree: $TRASH_DIRECTORY/6/wt
746 setup: cwd: $TRASH_DIRECTORY/6/sub/sub
747 setup: prefix: (null)
748 EOF
749         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY/6/wt" &&
750         test_repo 6/sub/sub ../../.git
751 '
752
753 test_expect_success '#6: GIT_DIR(rel), core.worktree=../wt(rel) in subdir' '
754         cat >6/sub/sub/expected <<EOF &&
755 setup: git_dir: ../../.git
756 setup: worktree: $TRASH_DIRECTORY/6/wt
757 setup: cwd: $TRASH_DIRECTORY/6/sub/sub
758 setup: prefix: (null)
759 EOF
760         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree ../wt &&
761         test_repo 6/sub/sub ../../.git
762 '
763
764 test_expect_success '#6: GIT_DIR, core.worktree=../wt(rel) in subdir' '
765         cat >6/sub/sub/expected <<EOF &&
766 setup: git_dir: $TRASH_DIRECTORY/6/.git
767 setup: worktree: $TRASH_DIRECTORY/6/wt
768 setup: cwd: $TRASH_DIRECTORY/6/sub/sub
769 setup: prefix: (null)
770 EOF
771         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree ../wt &&
772         test_repo 6/sub/sub "$TRASH_DIRECTORY/6/.git"
773 '
774
775 test_expect_success '#6: GIT_DIR, core.worktree=../wt in subdir' '
776         cat >6/sub/sub/expected <<EOF &&
777 setup: git_dir: $TRASH_DIRECTORY/6/.git
778 setup: worktree: $TRASH_DIRECTORY/6/wt
779 setup: cwd: $TRASH_DIRECTORY/6/sub/sub
780 setup: prefix: (null)
781 EOF
782         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY/6/wt" &&
783         test_repo 6/sub/sub "$TRASH_DIRECTORY/6/.git"
784 '
785
786 test_expect_success '#6: GIT_DIR(rel), core.worktree=../.. at root' '
787         cat >6/expected <<EOF &&
788 setup: git_dir: $TRASH_DIRECTORY/6/.git
789 setup: worktree: $TRASH_DIRECTORY
790 setup: cwd: $TRASH_DIRECTORY
791 setup: prefix: 6/
792 EOF
793         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY" &&
794         test_repo 6 .git
795 '
796
797 test_expect_success '#6: GIT_DIR(rel), core.worktree=../..(rel) at root' '
798         cat >6/expected <<EOF &&
799 setup: git_dir: $TRASH_DIRECTORY/6/.git
800 setup: worktree: $TRASH_DIRECTORY
801 setup: cwd: $TRASH_DIRECTORY
802 setup: prefix: 6/
803 EOF
804         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree ../../ &&
805         test_repo 6 .git
806 '
807
808 test_expect_success '#6: GIT_DIR, core.worktree=../..(rel) at root' '
809         cat >6/expected <<EOF &&
810 setup: git_dir: $TRASH_DIRECTORY/6/.git
811 setup: worktree: $TRASH_DIRECTORY
812 setup: cwd: $TRASH_DIRECTORY
813 setup: prefix: 6/
814 EOF
815         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree ../../ &&
816         test_repo 6 "$TRASH_DIRECTORY/6/.git"
817 '
818
819 test_expect_success '#6: GIT_DIR, core.worktree=../.. at root' '
820         cat >6/expected <<EOF &&
821 setup: git_dir: $TRASH_DIRECTORY/6/.git
822 setup: worktree: $TRASH_DIRECTORY
823 setup: cwd: $TRASH_DIRECTORY
824 setup: prefix: 6/
825 EOF
826         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY" &&
827         test_repo 6 "$TRASH_DIRECTORY/6/.git"
828 '
829
830 test_expect_success '#6: GIT_DIR(rel), core.worktree=../.. in subdir' '
831         cat >6/sub/sub/expected <<EOF &&
832 setup: git_dir: $TRASH_DIRECTORY/6/.git
833 setup: worktree: $TRASH_DIRECTORY
834 setup: cwd: $TRASH_DIRECTORY
835 setup: prefix: 6/sub/sub/
836 EOF
837         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY" &&
838         test_repo 6/sub/sub ../../.git
839 '
840
841 test_expect_success '#6: GIT_DIR(rel), core.worktree=../..(rel) in subdir' '
842         cat >6/sub/sub/expected <<EOF &&
843 setup: git_dir: $TRASH_DIRECTORY/6/.git
844 setup: worktree: $TRASH_DIRECTORY
845 setup: cwd: $TRASH_DIRECTORY
846 setup: prefix: 6/sub/sub/
847 EOF
848         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree ../.. &&
849         test_repo 6/sub/sub ../../.git
850 '
851
852 test_expect_success '#6: GIT_DIR, core.worktree=../..(rel) in subdir' '
853         cat >6/sub/sub/expected <<EOF &&
854 setup: git_dir: $TRASH_DIRECTORY/6/.git
855 setup: worktree: $TRASH_DIRECTORY
856 setup: cwd: $TRASH_DIRECTORY
857 setup: prefix: 6/sub/sub/
858 EOF
859         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree ../.. &&
860         test_repo 6/sub/sub "$TRASH_DIRECTORY/6/.git"
861 '
862
863 test_expect_success '#6: GIT_DIR, core.worktree=../.. in subdir' '
864         cat >6/sub/sub/expected <<EOF &&
865 setup: git_dir: $TRASH_DIRECTORY/6/.git
866 setup: worktree: $TRASH_DIRECTORY
867 setup: cwd: $TRASH_DIRECTORY
868 setup: prefix: 6/sub/sub/
869 EOF
870         git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY" &&
871         test_repo 6/sub/sub "$TRASH_DIRECTORY/6/.git"
872 '
873
874 #
875 # case #7
876 #
877 ############################################################
878 #
879 # Input:
880 #
881 #  - GIT_WORK_TREE is set
882 #  - GIT_DIR is set
883 #  - core.worktree is set
884 #  - .git is a directory
885 #  - core.bare is not set, cwd is outside .git
886 #
887 # Output:
888 #
889 # core.worktree is overridden by GIT_WORK_TREE -> #3
890
891 test_expect_success '#7: setup' '
892         sane_unset GIT_DIR GIT_WORK_TREE &&
893         mkdir 7 7/sub 7/sub/sub 7.wt 7.wt/sub 7/wt 7/wt/sub &&
894         cd 7 &&
895         git init &&
896         git config core.worktree non-existent &&
897         cd ..
898 '
899
900 test_expect_success '#7: GIT_DIR(rel), GIT_WORK_TREE=root at root' '
901         cat >7/expected <<EOF &&
902 setup: git_dir: .git
903 setup: worktree: $TRASH_DIRECTORY/7
904 setup: cwd: $TRASH_DIRECTORY/7
905 setup: prefix: (null)
906 EOF
907         test_repo 7 .git "$TRASH_DIRECTORY/7"
908 '
909
910 test_expect_success '#7: GIT_DIR(rel), GIT_WORK_TREE=root(rel) at root' '
911         cat >7/expected <<EOF &&
912 setup: git_dir: .git
913 setup: worktree: $TRASH_DIRECTORY/7
914 setup: cwd: $TRASH_DIRECTORY/7
915 setup: prefix: (null)
916 EOF
917         test_repo 7 .git .
918 '
919
920 test_expect_success '#7: GIT_DIR, GIT_WORK_TREE=root at root' '
921         cat >7/expected <<EOF &&
922 setup: git_dir: $TRASH_DIRECTORY/7/.git
923 setup: worktree: $TRASH_DIRECTORY/7
924 setup: cwd: $TRASH_DIRECTORY/7
925 setup: prefix: (null)
926 EOF
927         test_repo 7 "$TRASH_DIRECTORY/7/.git" "$TRASH_DIRECTORY/7"
928 '
929
930 test_expect_success '#7: GIT_DIR, GIT_WORK_TREE=root(rel) at root' '
931         cat >7/expected <<EOF &&
932 setup: git_dir: $TRASH_DIRECTORY/7/.git
933 setup: worktree: $TRASH_DIRECTORY/7
934 setup: cwd: $TRASH_DIRECTORY/7
935 setup: prefix: (null)
936 EOF
937         test_repo 7 "$TRASH_DIRECTORY/7/.git" .
938 '
939
940 test_expect_success '#7: GIT_DIR(rel), GIT_WORKTREE=root in subdir' '
941         cat >7/sub/sub/expected <<EOF &&
942 setup: git_dir: $TRASH_DIRECTORY/7/.git
943 setup: worktree: $TRASH_DIRECTORY/7
944 setup: cwd: $TRASH_DIRECTORY/7
945 setup: prefix: sub/sub/
946 EOF
947         test_repo 7/sub/sub ../../.git "$TRASH_DIRECTORY/7"
948 '
949
950 test_expect_success '#7: GIT_DIR(rel), GIT_WORKTREE=root(rel) in subdir' '
951         cat >7/sub/sub/expected <<EOF &&
952 setup: git_dir: $TRASH_DIRECTORY/7/.git
953 setup: worktree: $TRASH_DIRECTORY/7
954 setup: cwd: $TRASH_DIRECTORY/7
955 setup: prefix: sub/sub/
956 EOF
957         test_repo 7/sub/sub ../../.git ../..
958 '
959
960 test_expect_success '#7: GIT_DIR, GIT_WORKTREE=root in subdir' '
961         cat >7/sub/expected <<EOF &&
962 setup: git_dir: $TRASH_DIRECTORY/7/.git
963 setup: worktree: $TRASH_DIRECTORY/7
964 setup: cwd: $TRASH_DIRECTORY/7
965 setup: prefix: sub/
966 EOF
967         test_repo 7/sub "$TRASH_DIRECTORY/7/.git" "$TRASH_DIRECTORY/7"
968 '
969
970 test_expect_success '#7: GIT_DIR, GIT_WORKTREE=root(rel) in subdir' '
971         cat >7/sub/sub/expected <<EOF &&
972 setup: git_dir: $TRASH_DIRECTORY/7/.git
973 setup: worktree: $TRASH_DIRECTORY/7
974 setup: cwd: $TRASH_DIRECTORY/7
975 setup: prefix: sub/sub/
976 EOF
977         test_repo 7/sub/sub "$TRASH_DIRECTORY/7/.git" ../..
978 '
979
980 test_expect_success '#7: GIT_DIR(rel), GIT_WORK_TREE=wt at root' '
981         cat >7/expected <<EOF &&
982 setup: git_dir: .git
983 setup: worktree: $TRASH_DIRECTORY/7/wt
984 setup: cwd: $TRASH_DIRECTORY/7
985 setup: prefix: (null)
986 EOF
987         test_repo 7 .git "$TRASH_DIRECTORY/7/wt"
988 '
989
990 test_expect_success '#7: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) at root' '
991         cat >7/expected <<EOF &&
992 setup: git_dir: .git
993 setup: worktree: $TRASH_DIRECTORY/7/wt
994 setup: cwd: $TRASH_DIRECTORY/7
995 setup: prefix: (null)
996 EOF
997         test_repo 7 .git wt
998 '
999
1000 test_expect_success '#7: GIT_DIR, GIT_WORK_TREE=wt(rel) at root' '
1001         cat >7/expected <<EOF &&
1002 setup: git_dir: $TRASH_DIRECTORY/7/.git
1003 setup: worktree: $TRASH_DIRECTORY/7/wt
1004 setup: cwd: $TRASH_DIRECTORY/7
1005 setup: prefix: (null)
1006 EOF
1007         test_repo 7 "$TRASH_DIRECTORY/7/.git" wt
1008 '
1009
1010 test_expect_success '#7: GIT_DIR, GIT_WORK_TREE=wt at root' '
1011         cat >7/expected <<EOF &&
1012 setup: git_dir: $TRASH_DIRECTORY/7/.git
1013 setup: worktree: $TRASH_DIRECTORY/7/wt
1014 setup: cwd: $TRASH_DIRECTORY/7
1015 setup: prefix: (null)
1016 EOF
1017         test_repo 7 "$TRASH_DIRECTORY/7/.git" "$TRASH_DIRECTORY/7/wt"
1018 '
1019
1020 test_expect_success '#7: GIT_DIR(rel), GIT_WORK_TREE=wt in subdir' '
1021         cat >7/sub/sub/expected <<EOF &&
1022 setup: git_dir: ../../.git
1023 setup: worktree: $TRASH_DIRECTORY/7/wt
1024 setup: cwd: $TRASH_DIRECTORY/7/sub/sub
1025 setup: prefix: (null)
1026 EOF
1027         test_repo 7/sub/sub ../../.git "$TRASH_DIRECTORY/7/wt"
1028 '
1029
1030 test_expect_success '#7: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) in subdir' '
1031         cat >7/sub/sub/expected <<EOF &&
1032 setup: git_dir: ../../.git
1033 setup: worktree: $TRASH_DIRECTORY/7/wt
1034 setup: cwd: $TRASH_DIRECTORY/7/sub/sub
1035 setup: prefix: (null)
1036 EOF
1037         test_repo 7/sub/sub ../../.git ../../wt
1038 '
1039
1040 test_expect_success '#7: GIT_DIR, GIT_WORK_TREE=wt(rel) in subdir' '
1041         cat >7/sub/sub/expected <<EOF &&
1042 setup: git_dir: $TRASH_DIRECTORY/7/.git
1043 setup: worktree: $TRASH_DIRECTORY/7/wt
1044 setup: cwd: $TRASH_DIRECTORY/7/sub/sub
1045 setup: prefix: (null)
1046 EOF
1047         test_repo 7/sub/sub "$TRASH_DIRECTORY/7/.git" ../../wt
1048 '
1049
1050 test_expect_success '#7: GIT_DIR, GIT_WORK_TREE=wt in subdir' '
1051         cat >7/sub/sub/expected <<EOF &&
1052 setup: git_dir: $TRASH_DIRECTORY/7/.git
1053 setup: worktree: $TRASH_DIRECTORY/7/wt
1054 setup: cwd: $TRASH_DIRECTORY/7/sub/sub
1055 setup: prefix: (null)
1056 EOF
1057         test_repo 7/sub/sub "$TRASH_DIRECTORY/7/.git" "$TRASH_DIRECTORY/7/wt"
1058 '
1059
1060 test_expect_success '#7: GIT_DIR(rel), GIT_WORK_TREE=.. at root' '
1061         cat >7/expected <<EOF &&
1062 setup: git_dir: $TRASH_DIRECTORY/7/.git
1063 setup: worktree: $TRASH_DIRECTORY
1064 setup: cwd: $TRASH_DIRECTORY
1065 setup: prefix: 7/
1066 EOF
1067         test_repo 7 .git "$TRASH_DIRECTORY"
1068 '
1069
1070 test_expect_success '#7: GIT_DIR(rel), GIT_WORK_TREE=..(rel) at root' '
1071         cat >7/expected <<EOF &&
1072 setup: git_dir: $TRASH_DIRECTORY/7/.git
1073 setup: worktree: $TRASH_DIRECTORY
1074 setup: cwd: $TRASH_DIRECTORY
1075 setup: prefix: 7/
1076 EOF
1077         test_repo 7 .git ..
1078 '
1079
1080 test_expect_success '#7: GIT_DIR, GIT_WORK_TREE=..(rel) at root' '
1081         cat >7/expected <<EOF &&
1082 setup: git_dir: $TRASH_DIRECTORY/7/.git
1083 setup: worktree: $TRASH_DIRECTORY
1084 setup: cwd: $TRASH_DIRECTORY
1085 setup: prefix: 7/
1086 EOF
1087         test_repo 7 "$TRASH_DIRECTORY/7/.git" ..
1088 '
1089
1090 test_expect_success '#7: GIT_DIR, GIT_WORK_TREE=.. at root' '
1091         cat >7/expected <<EOF &&
1092 setup: git_dir: $TRASH_DIRECTORY/7/.git
1093 setup: worktree: $TRASH_DIRECTORY
1094 setup: cwd: $TRASH_DIRECTORY
1095 setup: prefix: 7/
1096 EOF
1097         test_repo 7 "$TRASH_DIRECTORY/7/.git" "$TRASH_DIRECTORY"
1098 '
1099
1100 test_expect_success '#7: GIT_DIR(rel), GIT_WORK_TREE=.. in subdir' '
1101         cat >7/sub/sub/expected <<EOF &&
1102 setup: git_dir: $TRASH_DIRECTORY/7/.git
1103 setup: worktree: $TRASH_DIRECTORY
1104 setup: cwd: $TRASH_DIRECTORY
1105 setup: prefix: 7/sub/sub/
1106 EOF
1107         test_repo 7/sub/sub ../../.git "$TRASH_DIRECTORY"
1108 '
1109
1110 test_expect_success '#7: GIT_DIR(rel), GIT_WORK_TREE=..(rel) in subdir' '
1111         cat >7/sub/sub/expected <<EOF &&
1112 setup: git_dir: $TRASH_DIRECTORY/7/.git
1113 setup: worktree: $TRASH_DIRECTORY
1114 setup: cwd: $TRASH_DIRECTORY
1115 setup: prefix: 7/sub/sub/
1116 EOF
1117         test_repo 7/sub/sub ../../.git ../../..
1118 '
1119
1120 test_expect_success '#7: GIT_DIR, GIT_WORK_TREE=..(rel) in subdir' '
1121         cat >7/sub/sub/expected <<EOF &&
1122 setup: git_dir: $TRASH_DIRECTORY/7/.git
1123 setup: worktree: $TRASH_DIRECTORY
1124 setup: cwd: $TRASH_DIRECTORY
1125 setup: prefix: 7/sub/sub/
1126 EOF
1127         test_repo 7/sub/sub "$TRASH_DIRECTORY/7/.git" ../../../
1128 '
1129
1130 test_expect_success '#7: GIT_DIR, GIT_WORK_TREE=.. in subdir' '
1131         cat >7/sub/sub/expected <<EOF &&
1132 setup: git_dir: $TRASH_DIRECTORY/7/.git
1133 setup: worktree: $TRASH_DIRECTORY
1134 setup: cwd: $TRASH_DIRECTORY
1135 setup: prefix: 7/sub/sub/
1136 EOF
1137         test_repo 7/sub/sub "$TRASH_DIRECTORY/7/.git" "$TRASH_DIRECTORY"
1138 '
1139
1140 #
1141 # case #8
1142 #
1143 ############################################################
1144 #
1145 # Input:
1146 #
1147 #  - GIT_WORK_TREE is not set
1148 #  - GIT_DIR is not set
1149 #  - core.worktree is not set
1150 #  - .git is a file
1151 #  - core.bare is not set, cwd is outside .git
1152 #
1153 # Output:
1154 #
1155 # #0 except that git_dir is set by .git file
1156
1157 test_expect_success '#8: setup' '
1158         sane_unset GIT_DIR GIT_WORK_TREE &&
1159         mkdir 8 8/sub &&
1160         cd 8 &&
1161         git init &&
1162         mv .git ../8.git &&
1163         echo gitdir: ../8.git >.git &&
1164         cd ..
1165 '
1166
1167 test_expect_success '#8: at root' '
1168         cat >8/expected <<EOF &&
1169 setup: git_dir: $TRASH_DIRECTORY/8.git
1170 setup: worktree: $TRASH_DIRECTORY/8
1171 setup: cwd: $TRASH_DIRECTORY/8
1172 setup: prefix: (null)
1173 EOF
1174         test_repo 8
1175 '
1176
1177 test_expect_success '#8: in subdir' '
1178         cat >8/sub/expected <<EOF &&
1179 setup: git_dir: $TRASH_DIRECTORY/8.git
1180 setup: worktree: $TRASH_DIRECTORY/8
1181 setup: cwd: $TRASH_DIRECTORY/8
1182 setup: prefix: sub/
1183 EOF
1184         test_repo 8/sub
1185 '
1186
1187 #
1188 # case #9
1189 #
1190 ############################################################
1191 #
1192 # Input:
1193 #
1194 #  - GIT_WORK_TREE is set
1195 #  - GIT_DIR is not set
1196 #  - core.worktree is not set
1197 #  - .git is a file
1198 #  - core.bare is not set, cwd is outside .git
1199 #
1200 # Output:
1201 #
1202 # #1 except that git_dir is set by .git file
1203
1204 test_expect_success '#9: setup' '
1205         sane_unset GIT_DIR GIT_WORK_TREE &&
1206         mkdir 9 9/sub 9.wt 9.wt/sub 9/wt 9/wt/sub &&
1207         cd 9 &&
1208         git init &&
1209         mv .git ../9.git &&
1210         echo gitdir: ../9.git >.git &&
1211         GIT_WORK_TREE=non-existent &&
1212         export GIT_WORK_TREE &&
1213         cd ..
1214 '
1215
1216 test_expect_success '#9: at root' '
1217         cat >9/expected <<EOF &&
1218 setup: git_dir: $TRASH_DIRECTORY/9.git
1219 setup: worktree: $TRASH_DIRECTORY/9
1220 setup: cwd: $TRASH_DIRECTORY/9
1221 setup: prefix: (null)
1222 EOF
1223         test_repo 9
1224 '
1225
1226 test_expect_success '#9: in subdir' '
1227         cat >9/sub/expected <<EOF &&
1228 setup: git_dir: $TRASH_DIRECTORY/9.git
1229 setup: worktree: $TRASH_DIRECTORY/9
1230 setup: cwd: $TRASH_DIRECTORY/9
1231 setup: prefix: sub/
1232 EOF
1233         test_repo 9/sub
1234 '
1235
1236 #
1237 # case #10
1238 #
1239 ############################################################
1240 #
1241 # Input:
1242 #
1243 #  - GIT_WORK_TREE is not set
1244 #  - GIT_DIR is set
1245 #  - core.worktree is not set
1246 #  - .git is a file
1247 #  - core.bare is not set, cwd is outside .git
1248 #
1249 # Output:
1250 #
1251 # #2 except that git_dir is set by .git file
1252
1253 test_expect_success '#10: setup' '
1254         sane_unset GIT_DIR GIT_WORK_TREE &&
1255         mkdir 10 10/sub &&
1256         cd 10 &&
1257         git init &&
1258         mv .git ../10.git &&
1259         echo gitdir: ../10.git >.git &&
1260         cd ..
1261 '
1262
1263 test_expect_success '#10: at root' '
1264         cat >10/expected <<EOF &&
1265 setup: git_dir: $TRASH_DIRECTORY/10.git
1266 setup: worktree: $TRASH_DIRECTORY/10
1267 setup: cwd: $TRASH_DIRECTORY/10
1268 setup: prefix: (null)
1269 EOF
1270         test_repo 10 "$TRASH_DIRECTORY/10/.git"
1271 '
1272
1273 test_expect_success '#10: in subdir' '
1274         cat >10/sub/expected <<EOF &&
1275 setup: git_dir: $TRASH_DIRECTORY/10.git
1276 setup: worktree: $TRASH_DIRECTORY/10/sub
1277 setup: cwd: $TRASH_DIRECTORY/10/sub
1278 setup: prefix: (null)
1279 EOF
1280         test_repo 10/sub "$TRASH_DIRECTORY/10/.git"
1281 '
1282
1283 test_expect_success '#10: relative GIT_DIR at root' '
1284         cat >10/expected <<EOF &&
1285 setup: git_dir: $TRASH_DIRECTORY/10.git
1286 setup: worktree: $TRASH_DIRECTORY/10
1287 setup: cwd: $TRASH_DIRECTORY/10
1288 setup: prefix: (null)
1289 EOF
1290         test_repo 10 .git
1291 '
1292
1293 test_expect_success '#10: relative GIT_DIR in subdir' '
1294         cat >10/sub/expected <<EOF &&
1295 setup: git_dir: $TRASH_DIRECTORY/10.git
1296 setup: worktree: $TRASH_DIRECTORY/10/sub
1297 setup: cwd: $TRASH_DIRECTORY/10/sub
1298 setup: prefix: (null)
1299 EOF
1300         test_repo 10/sub ../.git
1301 '
1302
1303 #
1304 # case #11
1305 #
1306 ############################################################
1307 #
1308 # Input:
1309 #
1310 #  - GIT_WORK_TREE is set
1311 #  - GIT_DIR is set
1312 #  - core.worktree is not set
1313 #  - .git is a file
1314 #  - core.bare is not set, cwd is outside .git
1315 #
1316 # Output:
1317 #
1318 # #3 except that git_dir is set by .git file
1319
1320 test_expect_success '#11: setup' '
1321         sane_unset GIT_DIR GIT_WORK_TREE &&
1322         mkdir 11 11/sub 11/sub/sub 11.wt 11.wt/sub 11/wt 11/wt/sub &&
1323         cd 11 &&
1324         git init &&
1325         mv .git ../11.git &&
1326         echo gitdir: ../11.git >.git &&
1327         cd ..
1328 '
1329
1330 test_expect_success '#11: GIT_DIR(rel), GIT_WORK_TREE=root at root' '
1331         cat >11/expected <<EOF &&
1332 setup: git_dir: $TRASH_DIRECTORY/11.git
1333 setup: worktree: $TRASH_DIRECTORY/11
1334 setup: cwd: $TRASH_DIRECTORY/11
1335 setup: prefix: (null)
1336 EOF
1337         test_repo 11 .git "$TRASH_DIRECTORY/11"
1338 '
1339
1340 test_expect_success '#11: GIT_DIR(rel), GIT_WORK_TREE=root(rel) at root' '
1341         cat >11/expected <<EOF &&
1342 setup: git_dir: $TRASH_DIRECTORY/11.git
1343 setup: worktree: $TRASH_DIRECTORY/11
1344 setup: cwd: $TRASH_DIRECTORY/11
1345 setup: prefix: (null)
1346 EOF
1347         test_repo 11 .git .
1348 '
1349
1350 test_expect_success '#11: GIT_DIR, GIT_WORK_TREE=root at root' '
1351         cat >11/expected <<EOF &&
1352 setup: git_dir: $TRASH_DIRECTORY/11.git
1353 setup: worktree: $TRASH_DIRECTORY/11
1354 setup: cwd: $TRASH_DIRECTORY/11
1355 setup: prefix: (null)
1356 EOF
1357         test_repo 11 "$TRASH_DIRECTORY/11/.git" "$TRASH_DIRECTORY/11"
1358 '
1359
1360 test_expect_success '#11: GIT_DIR, GIT_WORK_TREE=root(rel) at root' '
1361         cat >11/expected <<EOF &&
1362 setup: git_dir: $TRASH_DIRECTORY/11.git
1363 setup: worktree: $TRASH_DIRECTORY/11
1364 setup: cwd: $TRASH_DIRECTORY/11
1365 setup: prefix: (null)
1366 EOF
1367         test_repo 11 "$TRASH_DIRECTORY/11/.git" .
1368 '
1369
1370 test_expect_success '#11: GIT_DIR(rel), GIT_WORKTREE=root in subdir' '
1371         cat >11/sub/sub/expected <<EOF &&
1372 setup: git_dir: $TRASH_DIRECTORY/11.git
1373 setup: worktree: $TRASH_DIRECTORY/11
1374 setup: cwd: $TRASH_DIRECTORY/11
1375 setup: prefix: sub/sub/
1376 EOF
1377         test_repo 11/sub/sub ../../.git "$TRASH_DIRECTORY/11"
1378 '
1379
1380 test_expect_success '#11: GIT_DIR(rel), GIT_WORKTREE=root(rel) in subdir' '
1381         cat >11/sub/sub/expected <<EOF &&
1382 setup: git_dir: $TRASH_DIRECTORY/11.git
1383 setup: worktree: $TRASH_DIRECTORY/11
1384 setup: cwd: $TRASH_DIRECTORY/11
1385 setup: prefix: sub/sub/
1386 EOF
1387         test_repo 11/sub/sub ../../.git ../..
1388 '
1389
1390 test_expect_success '#11: GIT_DIR, GIT_WORKTREE=root in subdir' '
1391         cat >11/sub/expected <<EOF &&
1392 setup: git_dir: $TRASH_DIRECTORY/11.git
1393 setup: worktree: $TRASH_DIRECTORY/11
1394 setup: cwd: $TRASH_DIRECTORY/11
1395 setup: prefix: sub/
1396 EOF
1397         test_repo 11/sub "$TRASH_DIRECTORY/11/.git" "$TRASH_DIRECTORY/11"
1398 '
1399
1400 test_expect_success '#11: GIT_DIR, GIT_WORKTREE=root(rel) in subdir' '
1401         cat >11/sub/sub/expected <<EOF &&
1402 setup: git_dir: $TRASH_DIRECTORY/11.git
1403 setup: worktree: $TRASH_DIRECTORY/11
1404 setup: cwd: $TRASH_DIRECTORY/11
1405 setup: prefix: sub/sub/
1406 EOF
1407         test_repo 11/sub/sub "$TRASH_DIRECTORY/11/.git" ../..
1408 '
1409
1410 test_expect_success '#11: GIT_DIR(rel), GIT_WORK_TREE=wt at root' '
1411         cat >11/expected <<EOF &&
1412 setup: git_dir: $TRASH_DIRECTORY/11.git
1413 setup: worktree: $TRASH_DIRECTORY/11/wt
1414 setup: cwd: $TRASH_DIRECTORY/11
1415 setup: prefix: (null)
1416 EOF
1417         test_repo 11 .git "$TRASH_DIRECTORY/11/wt"
1418 '
1419
1420 test_expect_success '#11: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) at root' '
1421         cat >11/expected <<EOF &&
1422 setup: git_dir: $TRASH_DIRECTORY/11.git
1423 setup: worktree: $TRASH_DIRECTORY/11/wt
1424 setup: cwd: $TRASH_DIRECTORY/11
1425 setup: prefix: (null)
1426 EOF
1427         test_repo 11 .git wt
1428 '
1429
1430 test_expect_success '#11: GIT_DIR, GIT_WORK_TREE=wt(rel) at root' '
1431         cat >11/expected <<EOF &&
1432 setup: git_dir: $TRASH_DIRECTORY/11.git
1433 setup: worktree: $TRASH_DIRECTORY/11/wt
1434 setup: cwd: $TRASH_DIRECTORY/11
1435 setup: prefix: (null)
1436 EOF
1437         test_repo 11 "$TRASH_DIRECTORY/11/.git" wt
1438 '
1439
1440 test_expect_success '#11: GIT_DIR, GIT_WORK_TREE=wt at root' '
1441         cat >11/expected <<EOF &&
1442 setup: git_dir: $TRASH_DIRECTORY/11.git
1443 setup: worktree: $TRASH_DIRECTORY/11/wt
1444 setup: cwd: $TRASH_DIRECTORY/11
1445 setup: prefix: (null)
1446 EOF
1447         test_repo 11 "$TRASH_DIRECTORY/11/.git" "$TRASH_DIRECTORY/11/wt"
1448 '
1449
1450 test_expect_success '#11: GIT_DIR(rel), GIT_WORK_TREE=wt in subdir' '
1451         cat >11/sub/sub/expected <<EOF &&
1452 setup: git_dir: $TRASH_DIRECTORY/11.git
1453 setup: worktree: $TRASH_DIRECTORY/11/wt
1454 setup: cwd: $TRASH_DIRECTORY/11/sub/sub
1455 setup: prefix: (null)
1456 EOF
1457         test_repo 11/sub/sub ../../.git "$TRASH_DIRECTORY/11/wt"
1458 '
1459
1460 test_expect_success '#11: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) in subdir' '
1461         cat >11/sub/sub/expected <<EOF &&
1462 setup: git_dir: $TRASH_DIRECTORY/11.git
1463 setup: worktree: $TRASH_DIRECTORY/11/wt
1464 setup: cwd: $TRASH_DIRECTORY/11/sub/sub
1465 setup: prefix: (null)
1466 EOF
1467         test_repo 11/sub/sub ../../.git ../../wt
1468 '
1469
1470 test_expect_success '#11: GIT_DIR, GIT_WORK_TREE=wt(rel) in subdir' '
1471         cat >11/sub/sub/expected <<EOF &&
1472 setup: git_dir: $TRASH_DIRECTORY/11.git
1473 setup: worktree: $TRASH_DIRECTORY/11/wt
1474 setup: cwd: $TRASH_DIRECTORY/11/sub/sub
1475 setup: prefix: (null)
1476 EOF
1477         test_repo 11/sub/sub "$TRASH_DIRECTORY/11/.git" ../../wt
1478 '
1479
1480 test_expect_success '#11: GIT_DIR, GIT_WORK_TREE=wt in subdir' '
1481         cat >11/sub/sub/expected <<EOF &&
1482 setup: git_dir: $TRASH_DIRECTORY/11.git
1483 setup: worktree: $TRASH_DIRECTORY/11/wt
1484 setup: cwd: $TRASH_DIRECTORY/11/sub/sub
1485 setup: prefix: (null)
1486 EOF
1487         test_repo 11/sub/sub "$TRASH_DIRECTORY/11/.git" "$TRASH_DIRECTORY/11/wt"
1488 '
1489
1490 test_expect_success '#11: GIT_DIR(rel), GIT_WORK_TREE=.. at root' '
1491         cat >11/expected <<EOF &&
1492 setup: git_dir: $TRASH_DIRECTORY/11.git
1493 setup: worktree: $TRASH_DIRECTORY
1494 setup: cwd: $TRASH_DIRECTORY
1495 setup: prefix: 11/
1496 EOF
1497         test_repo 11 .git "$TRASH_DIRECTORY"
1498 '
1499
1500 test_expect_success '#11: GIT_DIR(rel), GIT_WORK_TREE=..(rel) at root' '
1501         cat >11/expected <<EOF &&
1502 setup: git_dir: $TRASH_DIRECTORY/11.git
1503 setup: worktree: $TRASH_DIRECTORY
1504 setup: cwd: $TRASH_DIRECTORY
1505 setup: prefix: 11/
1506 EOF
1507         test_repo 11 .git ..
1508 '
1509
1510 test_expect_success '#11: GIT_DIR, GIT_WORK_TREE=..(rel) at root' '
1511         cat >11/expected <<EOF &&
1512 setup: git_dir: $TRASH_DIRECTORY/11.git
1513 setup: worktree: $TRASH_DIRECTORY
1514 setup: cwd: $TRASH_DIRECTORY
1515 setup: prefix: 11/
1516 EOF
1517         test_repo 11 "$TRASH_DIRECTORY/11/.git" ..
1518 '
1519
1520 test_expect_success '#11: GIT_DIR, GIT_WORK_TREE=.. at root' '
1521         cat >11/expected <<EOF &&
1522 setup: git_dir: $TRASH_DIRECTORY/11.git
1523 setup: worktree: $TRASH_DIRECTORY
1524 setup: cwd: $TRASH_DIRECTORY
1525 setup: prefix: 11/
1526 EOF
1527         test_repo 11 "$TRASH_DIRECTORY/11/.git" "$TRASH_DIRECTORY"
1528 '
1529
1530 test_expect_success '#11: GIT_DIR(rel), GIT_WORK_TREE=.. in subdir' '
1531         cat >11/sub/sub/expected <<EOF &&
1532 setup: git_dir: $TRASH_DIRECTORY/11.git
1533 setup: worktree: $TRASH_DIRECTORY
1534 setup: cwd: $TRASH_DIRECTORY
1535 setup: prefix: 11/sub/sub/
1536 EOF
1537         test_repo 11/sub/sub ../../.git "$TRASH_DIRECTORY"
1538 '
1539
1540 test_expect_success '#11: GIT_DIR(rel), GIT_WORK_TREE=..(rel) in subdir' '
1541         cat >11/sub/sub/expected <<EOF &&
1542 setup: git_dir: $TRASH_DIRECTORY/11.git
1543 setup: worktree: $TRASH_DIRECTORY
1544 setup: cwd: $TRASH_DIRECTORY
1545 setup: prefix: 11/sub/sub/
1546 EOF
1547         test_repo 11/sub/sub ../../.git ../../..
1548 '
1549
1550 test_expect_success '#11: GIT_DIR, GIT_WORK_TREE=..(rel) in subdir' '
1551         cat >11/sub/sub/expected <<EOF &&
1552 setup: git_dir: $TRASH_DIRECTORY/11.git
1553 setup: worktree: $TRASH_DIRECTORY
1554 setup: cwd: $TRASH_DIRECTORY
1555 setup: prefix: 11/sub/sub/
1556 EOF
1557         test_repo 11/sub/sub "$TRASH_DIRECTORY/11/.git" ../../../
1558 '
1559
1560 test_expect_success '#11: GIT_DIR, GIT_WORK_TREE=.. in subdir' '
1561         cat >11/sub/sub/expected <<EOF &&
1562 setup: git_dir: $TRASH_DIRECTORY/11.git
1563 setup: worktree: $TRASH_DIRECTORY
1564 setup: cwd: $TRASH_DIRECTORY
1565 setup: prefix: 11/sub/sub/
1566 EOF
1567         test_repo 11/sub/sub "$TRASH_DIRECTORY/11/.git" "$TRASH_DIRECTORY"
1568 '
1569
1570 #
1571 # case #12
1572 #
1573 ############################################################
1574 #
1575 # Input:
1576 #
1577 #  - GIT_WORK_TREE is not set
1578 #  - GIT_DIR is not set
1579 #  - core.worktree is set
1580 #  - .git is a file
1581 #  - core.bare is not set, cwd is outside .git
1582 #
1583 # Output:
1584 #
1585 # #4 except that git_dir is set by .git file
1586
1587
1588 test_expect_success '#12: setup' '
1589         sane_unset GIT_DIR GIT_WORK_TREE &&
1590         mkdir 12 12/sub 12/sub/sub 12.wt 12.wt/sub 12/wt 12/wt/sub &&
1591         cd 12 &&
1592         git init &&
1593         git config core.worktree non-existent &&
1594         mv .git ../12.git &&
1595         echo gitdir: ../12.git >.git &&
1596         cd ..
1597 '
1598
1599 test_expect_success '#12: at root' '
1600         cat >12/expected <<EOF &&
1601 setup: git_dir: $TRASH_DIRECTORY/12.git
1602 setup: worktree: $TRASH_DIRECTORY/12
1603 setup: cwd: $TRASH_DIRECTORY/12
1604 setup: prefix: (null)
1605 EOF
1606         test_repo 12
1607 '
1608
1609 test_expect_success '#12: in subdir' '
1610         cat >12/sub/expected <<EOF &&
1611 setup: git_dir: $TRASH_DIRECTORY/12.git
1612 setup: worktree: $TRASH_DIRECTORY/12
1613 setup: cwd: $TRASH_DIRECTORY/12
1614 setup: prefix: sub/
1615 EOF
1616         test_repo 12/sub
1617 '
1618
1619 #
1620 # case #13
1621 #
1622 ############################################################
1623 #
1624 # Input:
1625 #
1626 #  - GIT_WORK_TREE is set
1627 #  - GIT_DIR is not set
1628 #  - core.worktree is set
1629 #  - .git is a file
1630 #  - core.bare is not set, cwd is outside .git
1631 #
1632 # Output:
1633 #
1634 # #5 except that git_dir is set by .git file
1635
1636 test_expect_success '#13: setup' '
1637         sane_unset GIT_DIR GIT_WORK_TREE &&
1638         mkdir 13 13/sub 13/sub/sub 13.wt 13.wt/sub 13/wt 13/wt/sub &&
1639         cd 13 &&
1640         git init &&
1641         git config core.worktree non-existent &&
1642         GIT_WORK_TREE=non-existent-too &&
1643         export GIT_WORK_TREE &&
1644         mv .git ../13.git &&
1645         echo gitdir: ../13.git >.git &&
1646         cd ..
1647 '
1648
1649 test_expect_success '#13: at root' '
1650         cat >13/expected <<EOF &&
1651 setup: git_dir: $TRASH_DIRECTORY/13.git
1652 setup: worktree: $TRASH_DIRECTORY/13
1653 setup: cwd: $TRASH_DIRECTORY/13
1654 setup: prefix: (null)
1655 EOF
1656         test_repo 13
1657 '
1658
1659 test_expect_success '#13: in subdir' '
1660         cat >13/sub/expected <<EOF &&
1661 setup: git_dir: $TRASH_DIRECTORY/13.git
1662 setup: worktree: $TRASH_DIRECTORY/13
1663 setup: cwd: $TRASH_DIRECTORY/13
1664 setup: prefix: sub/
1665 EOF
1666         test_repo 13/sub
1667 '
1668
1669 #
1670 # case #14
1671 #
1672 ############################################################
1673 #
1674 # Input:
1675 #
1676 #  - GIT_WORK_TREE is not set
1677 #  - GIT_DIR is set
1678 #  - core.worktree is set
1679 #  - .git is a file
1680 #  - core.bare is not set, cwd is outside .git
1681 #
1682 # Output:
1683 #
1684 # #6 except that git_dir is set by .git file
1685
1686 test_expect_success '#14: setup' '
1687         sane_unset GIT_DIR GIT_WORK_TREE &&
1688         mkdir 14 14/sub 14/sub/sub 14.wt 14.wt/sub 14/wt 14/wt/sub &&
1689         cd 14 &&
1690         git init &&
1691         mv .git ../14.git &&
1692         echo gitdir: ../14.git >.git &&
1693         cd ..
1694 '
1695
1696 test_expect_success '#14: GIT_DIR(rel), core.worktree=../14 at root' '
1697         cat >14/expected <<EOF &&
1698 setup: git_dir: $TRASH_DIRECTORY/14.git
1699 setup: worktree: $TRASH_DIRECTORY/14
1700 setup: cwd: $TRASH_DIRECTORY/14
1701 setup: prefix: (null)
1702 EOF
1703         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree "$TRASH_DIRECTORY/14" &&
1704         test_repo 14 .git
1705 '
1706
1707 test_expect_success '#14: GIT_DIR(rel), core.worktree=../14(rel) at root' '
1708         cat >14/expected <<EOF &&
1709 setup: git_dir: $TRASH_DIRECTORY/14.git
1710 setup: worktree: $TRASH_DIRECTORY/14
1711 setup: cwd: $TRASH_DIRECTORY/14
1712 setup: prefix: (null)
1713 EOF
1714         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree ../14 &&
1715         test_repo 14 .git
1716 '
1717
1718 test_expect_success '#14: GIT_DIR, core.worktree=../14 at root' '
1719         cat >14/expected <<EOF &&
1720 setup: git_dir: $TRASH_DIRECTORY/14.git
1721 setup: worktree: $TRASH_DIRECTORY/14
1722 setup: cwd: $TRASH_DIRECTORY/14
1723 setup: prefix: (null)
1724 EOF
1725         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree "$TRASH_DIRECTORY/14" &&
1726         test_repo 14 "$TRASH_DIRECTORY/14/.git"
1727 '
1728
1729 test_expect_success '#14: GIT_DIR, core.worktree=../14(rel) at root' '
1730         cat >14/expected <<EOF &&
1731 setup: git_dir: $TRASH_DIRECTORY/14.git
1732 setup: worktree: $TRASH_DIRECTORY/14
1733 setup: cwd: $TRASH_DIRECTORY/14
1734 setup: prefix: (null)
1735 EOF
1736         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree ../14 &&
1737         test_repo 14 "$TRASH_DIRECTORY/14/.git"
1738 '
1739
1740 test_expect_success '#14: GIT_DIR(rel), core.worktree=../14 in subdir' '
1741         cat >14/sub/sub/expected <<EOF &&
1742 setup: git_dir: $TRASH_DIRECTORY/14.git
1743 setup: worktree: $TRASH_DIRECTORY/14
1744 setup: cwd: $TRASH_DIRECTORY/14
1745 setup: prefix: sub/sub/
1746 EOF
1747         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree "$TRASH_DIRECTORY/14" &&
1748         test_repo 14/sub/sub ../../.git
1749 '
1750
1751 test_expect_success '#14: GIT_DIR(rel), core.worktree=../14(rel) in subdir' '
1752         cat >14/sub/sub/expected <<EOF &&
1753 setup: git_dir: $TRASH_DIRECTORY/14.git
1754 setup: worktree: $TRASH_DIRECTORY/14
1755 setup: cwd: $TRASH_DIRECTORY/14
1756 setup: prefix: sub/sub/
1757 EOF
1758         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree ../14 &&
1759         test_repo 14/sub/sub ../../.git
1760 '
1761
1762 test_expect_success '#14: GIT_DIR, core.worktree=../14 in subdir' '
1763         cat >14/sub/expected <<EOF &&
1764 setup: git_dir: $TRASH_DIRECTORY/14.git
1765 setup: worktree: $TRASH_DIRECTORY/14
1766 setup: cwd: $TRASH_DIRECTORY/14
1767 setup: prefix: sub/
1768 EOF
1769         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree "$TRASH_DIRECTORY/14" &&
1770         test_repo 14/sub "$TRASH_DIRECTORY/14/.git"
1771 '
1772
1773 test_expect_success '#14: GIT_DIR, core.worktree=../14(rel) in subdir' '
1774         cat >14/sub/sub/expected <<EOF &&
1775 setup: git_dir: $TRASH_DIRECTORY/14.git
1776 setup: worktree: $TRASH_DIRECTORY/14
1777 setup: cwd: $TRASH_DIRECTORY/14
1778 setup: prefix: sub/sub/
1779 EOF
1780         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree ../14 &&
1781         test_repo 14/sub/sub "$TRASH_DIRECTORY/14/.git"
1782 '
1783
1784 test_expect_success '#14: GIT_DIR(rel), core.worktree=../14/wt at root' '
1785         cat >14/expected <<EOF &&
1786 setup: git_dir: $TRASH_DIRECTORY/14.git
1787 setup: worktree: $TRASH_DIRECTORY/14/wt
1788 setup: cwd: $TRASH_DIRECTORY/14
1789 setup: prefix: (null)
1790 EOF
1791         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree "$TRASH_DIRECTORY/14/wt" &&
1792         test_repo 14 .git
1793 '
1794
1795 test_expect_success '#14: GIT_DIR(rel), core.worktree=../14/wt(rel) at root' '
1796         cat >14/expected <<EOF &&
1797 setup: git_dir: $TRASH_DIRECTORY/14.git
1798 setup: worktree: $TRASH_DIRECTORY/14/wt
1799 setup: cwd: $TRASH_DIRECTORY/14
1800 setup: prefix: (null)
1801 EOF
1802         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree ../14/wt &&
1803         test_repo 14 .git
1804 '
1805
1806 test_expect_success '#14: GIT_DIR, core.worktree=../14/wt(rel) at root' '
1807         cat >14/expected <<EOF &&
1808 setup: git_dir: $TRASH_DIRECTORY/14.git
1809 setup: worktree: $TRASH_DIRECTORY/14/wt
1810 setup: cwd: $TRASH_DIRECTORY/14
1811 setup: prefix: (null)
1812 EOF
1813         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree ../14/wt &&
1814         test_repo 14 "$TRASH_DIRECTORY/14/.git"
1815 '
1816
1817 test_expect_success '#14: GIT_DIR, core.worktree=../14/wt at root' '
1818         cat >14/expected <<EOF &&
1819 setup: git_dir: $TRASH_DIRECTORY/14.git
1820 setup: worktree: $TRASH_DIRECTORY/14/wt
1821 setup: cwd: $TRASH_DIRECTORY/14
1822 setup: prefix: (null)
1823 EOF
1824         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree "$TRASH_DIRECTORY/14/wt" &&
1825         test_repo 14 "$TRASH_DIRECTORY/14/.git"
1826 '
1827
1828 test_expect_success '#14: GIT_DIR(rel), core.worktree=../14/wt in subdir' '
1829         cat >14/sub/sub/expected <<EOF &&
1830 setup: git_dir: $TRASH_DIRECTORY/14.git
1831 setup: worktree: $TRASH_DIRECTORY/14/wt
1832 setup: cwd: $TRASH_DIRECTORY/14/sub/sub
1833 setup: prefix: (null)
1834 EOF
1835         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree "$TRASH_DIRECTORY/14/wt" &&
1836         test_repo 14/sub/sub ../../.git
1837 '
1838
1839 test_expect_success '#14: GIT_DIR(rel), core.worktree=../14/wt(rel) in subdir' '
1840         cat >14/sub/sub/expected <<EOF &&
1841 setup: git_dir: $TRASH_DIRECTORY/14.git
1842 setup: worktree: $TRASH_DIRECTORY/14/wt
1843 setup: cwd: $TRASH_DIRECTORY/14/sub/sub
1844 setup: prefix: (null)
1845 EOF
1846         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree ../14/wt &&
1847         test_repo 14/sub/sub ../../.git
1848 '
1849
1850 test_expect_success '#14: GIT_DIR, core.worktree=../14/wt(rel) in subdir' '
1851         cat >14/sub/sub/expected <<EOF &&
1852 setup: git_dir: $TRASH_DIRECTORY/14.git
1853 setup: worktree: $TRASH_DIRECTORY/14/wt
1854 setup: cwd: $TRASH_DIRECTORY/14/sub/sub
1855 setup: prefix: (null)
1856 EOF
1857         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree ../14/wt &&
1858         test_repo 14/sub/sub "$TRASH_DIRECTORY/14/.git"
1859 '
1860
1861 test_expect_success '#14: GIT_DIR, core.worktree=../14/wt in subdir' '
1862         cat >14/sub/sub/expected <<EOF &&
1863 setup: git_dir: $TRASH_DIRECTORY/14.git
1864 setup: worktree: $TRASH_DIRECTORY/14/wt
1865 setup: cwd: $TRASH_DIRECTORY/14/sub/sub
1866 setup: prefix: (null)
1867 EOF
1868         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree "$TRASH_DIRECTORY/14/wt" &&
1869         test_repo 14/sub/sub "$TRASH_DIRECTORY/14/.git"
1870 '
1871
1872 test_expect_success '#14: GIT_DIR(rel), core.worktree=.. at root' '
1873         cat >14/expected <<EOF &&
1874 setup: git_dir: $TRASH_DIRECTORY/14.git
1875 setup: worktree: $TRASH_DIRECTORY
1876 setup: cwd: $TRASH_DIRECTORY
1877 setup: prefix: 14/
1878 EOF
1879         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree "$TRASH_DIRECTORY" &&
1880         test_repo 14 .git
1881 '
1882
1883 test_expect_success '#14: GIT_DIR(rel), core.worktree=..(rel) at root' '
1884         cat >14/expected <<EOF &&
1885 setup: git_dir: $TRASH_DIRECTORY/14.git
1886 setup: worktree: $TRASH_DIRECTORY
1887 setup: cwd: $TRASH_DIRECTORY
1888 setup: prefix: 14/
1889 EOF
1890         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree .. &&
1891         test_repo 14 .git
1892 '
1893
1894 test_expect_success '#14: GIT_DIR, core.worktree=..(rel) at root' '
1895         cat >14/expected <<EOF &&
1896 setup: git_dir: $TRASH_DIRECTORY/14.git
1897 setup: worktree: $TRASH_DIRECTORY
1898 setup: cwd: $TRASH_DIRECTORY
1899 setup: prefix: 14/
1900 EOF
1901         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree .. &&
1902         test_repo 14 "$TRASH_DIRECTORY/14/.git"
1903 '
1904
1905 test_expect_success '#14: GIT_DIR, core.worktree=.. at root' '
1906         cat >14/expected <<EOF &&
1907 setup: git_dir: $TRASH_DIRECTORY/14.git
1908 setup: worktree: $TRASH_DIRECTORY
1909 setup: cwd: $TRASH_DIRECTORY
1910 setup: prefix: 14/
1911 EOF
1912         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree "$TRASH_DIRECTORY" &&
1913         test_repo 14 "$TRASH_DIRECTORY/14/.git"
1914 '
1915
1916 test_expect_success '#14: GIT_DIR(rel), core.worktree=.. in subdir' '
1917         cat >14/sub/sub/expected <<EOF &&
1918 setup: git_dir: $TRASH_DIRECTORY/14.git
1919 setup: worktree: $TRASH_DIRECTORY
1920 setup: cwd: $TRASH_DIRECTORY
1921 setup: prefix: 14/sub/sub/
1922 EOF
1923         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree "$TRASH_DIRECTORY" &&
1924         test_repo 14/sub/sub ../../.git
1925 '
1926
1927 test_expect_success '#14: GIT_DIR(rel), core.worktree=..(rel) in subdir' '
1928         cat >14/sub/sub/expected <<EOF &&
1929 setup: git_dir: $TRASH_DIRECTORY/14.git
1930 setup: worktree: $TRASH_DIRECTORY
1931 setup: cwd: $TRASH_DIRECTORY
1932 setup: prefix: 14/sub/sub/
1933 EOF
1934         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree .. &&
1935         test_repo 14/sub/sub ../../.git
1936 '
1937
1938 test_expect_success '#14: GIT_DIR, core.worktree=..(rel) in subdir' '
1939         cat >14/sub/sub/expected <<EOF &&
1940 setup: git_dir: $TRASH_DIRECTORY/14.git
1941 setup: worktree: $TRASH_DIRECTORY
1942 setup: cwd: $TRASH_DIRECTORY
1943 setup: prefix: 14/sub/sub/
1944 EOF
1945         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree .. &&
1946         test_repo 14/sub/sub "$TRASH_DIRECTORY/14/.git"
1947 '
1948
1949 test_expect_success '#14: GIT_DIR, core.worktree=.. in subdir' '
1950         cat >14/sub/sub/expected <<EOF &&
1951 setup: git_dir: $TRASH_DIRECTORY/14.git
1952 setup: worktree: $TRASH_DIRECTORY
1953 setup: cwd: $TRASH_DIRECTORY
1954 setup: prefix: 14/sub/sub/
1955 EOF
1956         git config --file="$TRASH_DIRECTORY/14.git/config" core.worktree "$TRASH_DIRECTORY" &&
1957         test_repo 14/sub/sub "$TRASH_DIRECTORY/14/.git"
1958 '
1959
1960 #
1961 # case #15
1962 #
1963 ############################################################
1964 #
1965 # Input:
1966 #
1967 #  - GIT_WORK_TREE is set
1968 #  - GIT_DIR is set
1969 #  - core.worktree is set
1970 #  - .git is a file
1971 #  - core.bare is not set, cwd is outside .git
1972 #
1973 # Output:
1974 #
1975 # #7 except that git_dir is set by .git file
1976
1977 test_expect_success '#15: setup' '
1978         sane_unset GIT_DIR GIT_WORK_TREE &&
1979         mkdir 15 15/sub 15/sub/sub 15.wt 15.wt/sub 15/wt 15/wt/sub &&
1980         cd 15 &&
1981         git init &&
1982         git config core.worktree non-existent &&
1983         mv .git ../15.git &&
1984         echo gitdir: ../15.git >.git &&
1985         cd ..
1986 '
1987
1988 test_expect_success '#15: GIT_DIR(rel), GIT_WORK_TREE=root at root' '
1989         cat >15/expected <<EOF &&
1990 setup: git_dir: $TRASH_DIRECTORY/15.git
1991 setup: worktree: $TRASH_DIRECTORY/15
1992 setup: cwd: $TRASH_DIRECTORY/15
1993 setup: prefix: (null)
1994 EOF
1995         test_repo 15 .git "$TRASH_DIRECTORY/15"
1996 '
1997
1998 test_expect_success '#15: GIT_DIR(rel), GIT_WORK_TREE=root(rel) at root' '
1999         cat >15/expected <<EOF &&
2000 setup: git_dir: $TRASH_DIRECTORY/15.git
2001 setup: worktree: $TRASH_DIRECTORY/15
2002 setup: cwd: $TRASH_DIRECTORY/15
2003 setup: prefix: (null)
2004 EOF
2005         test_repo 15 .git .
2006 '
2007
2008 test_expect_success '#15: GIT_DIR, GIT_WORK_TREE=root at root' '
2009         cat >15/expected <<EOF &&
2010 setup: git_dir: $TRASH_DIRECTORY/15.git
2011 setup: worktree: $TRASH_DIRECTORY/15
2012 setup: cwd: $TRASH_DIRECTORY/15
2013 setup: prefix: (null)
2014 EOF
2015         test_repo 15 "$TRASH_DIRECTORY/15/.git" "$TRASH_DIRECTORY/15"
2016 '
2017
2018 test_expect_success '#15: GIT_DIR, GIT_WORK_TREE=root(rel) at root' '
2019         cat >15/expected <<EOF &&
2020 setup: git_dir: $TRASH_DIRECTORY/15.git
2021 setup: worktree: $TRASH_DIRECTORY/15
2022 setup: cwd: $TRASH_DIRECTORY/15
2023 setup: prefix: (null)
2024 EOF
2025         test_repo 15 "$TRASH_DIRECTORY/15/.git" .
2026 '
2027
2028 test_expect_success '#15: GIT_DIR(rel), GIT_WORKTREE=root in subdir' '
2029         cat >15/sub/sub/expected <<EOF &&
2030 setup: git_dir: $TRASH_DIRECTORY/15.git
2031 setup: worktree: $TRASH_DIRECTORY/15
2032 setup: cwd: $TRASH_DIRECTORY/15
2033 setup: prefix: sub/sub/
2034 EOF
2035         test_repo 15/sub/sub ../../.git "$TRASH_DIRECTORY/15"
2036 '
2037
2038 test_expect_success '#15: GIT_DIR(rel), GIT_WORKTREE=root(rel) in subdir' '
2039         cat >15/sub/sub/expected <<EOF &&
2040 setup: git_dir: $TRASH_DIRECTORY/15.git
2041 setup: worktree: $TRASH_DIRECTORY/15
2042 setup: cwd: $TRASH_DIRECTORY/15
2043 setup: prefix: sub/sub/
2044 EOF
2045         test_repo 15/sub/sub ../../.git ../..
2046 '
2047
2048 test_expect_success '#15: GIT_DIR, GIT_WORKTREE=root in subdir' '
2049         cat >15/sub/expected <<EOF &&
2050 setup: git_dir: $TRASH_DIRECTORY/15.git
2051 setup: worktree: $TRASH_DIRECTORY/15
2052 setup: cwd: $TRASH_DIRECTORY/15
2053 setup: prefix: sub/
2054 EOF
2055         test_repo 15/sub "$TRASH_DIRECTORY/15/.git" "$TRASH_DIRECTORY/15"
2056 '
2057
2058 test_expect_success '#15: GIT_DIR, GIT_WORKTREE=root(rel) in subdir' '
2059         cat >15/sub/sub/expected <<EOF &&
2060 setup: git_dir: $TRASH_DIRECTORY/15.git
2061 setup: worktree: $TRASH_DIRECTORY/15
2062 setup: cwd: $TRASH_DIRECTORY/15
2063 setup: prefix: sub/sub/
2064 EOF
2065         test_repo 15/sub/sub "$TRASH_DIRECTORY/15/.git" ../..
2066 '
2067
2068 test_expect_success '#15: GIT_DIR(rel), GIT_WORK_TREE=wt at root' '
2069         cat >15/expected <<EOF &&
2070 setup: git_dir: $TRASH_DIRECTORY/15.git
2071 setup: worktree: $TRASH_DIRECTORY/15/wt
2072 setup: cwd: $TRASH_DIRECTORY/15
2073 setup: prefix: (null)
2074 EOF
2075         test_repo 15 .git "$TRASH_DIRECTORY/15/wt"
2076 '
2077
2078 test_expect_success '#15: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) at root' '
2079         cat >15/expected <<EOF &&
2080 setup: git_dir: $TRASH_DIRECTORY/15.git
2081 setup: worktree: $TRASH_DIRECTORY/15/wt
2082 setup: cwd: $TRASH_DIRECTORY/15
2083 setup: prefix: (null)
2084 EOF
2085         test_repo 15 .git wt
2086 '
2087
2088 test_expect_success '#15: GIT_DIR, GIT_WORK_TREE=wt(rel) at root' '
2089         cat >15/expected <<EOF &&
2090 setup: git_dir: $TRASH_DIRECTORY/15.git
2091 setup: worktree: $TRASH_DIRECTORY/15/wt
2092 setup: cwd: $TRASH_DIRECTORY/15
2093 setup: prefix: (null)
2094 EOF
2095         test_repo 15 "$TRASH_DIRECTORY/15/.git" wt
2096 '
2097
2098 test_expect_success '#15: GIT_DIR, GIT_WORK_TREE=wt at root' '
2099         cat >15/expected <<EOF &&
2100 setup: git_dir: $TRASH_DIRECTORY/15.git
2101 setup: worktree: $TRASH_DIRECTORY/15/wt
2102 setup: cwd: $TRASH_DIRECTORY/15
2103 setup: prefix: (null)
2104 EOF
2105         test_repo 15 "$TRASH_DIRECTORY/15/.git" "$TRASH_DIRECTORY/15/wt"
2106 '
2107
2108 test_expect_success '#15: GIT_DIR(rel), GIT_WORK_TREE=wt in subdir' '
2109         cat >15/sub/sub/expected <<EOF &&
2110 setup: git_dir: $TRASH_DIRECTORY/15.git
2111 setup: worktree: $TRASH_DIRECTORY/15/wt
2112 setup: cwd: $TRASH_DIRECTORY/15/sub/sub
2113 setup: prefix: (null)
2114 EOF
2115         test_repo 15/sub/sub ../../.git "$TRASH_DIRECTORY/15/wt"
2116 '
2117
2118 test_expect_success '#15: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) in subdir' '
2119         cat >15/sub/sub/expected <<EOF &&
2120 setup: git_dir: $TRASH_DIRECTORY/15.git
2121 setup: worktree: $TRASH_DIRECTORY/15/wt
2122 setup: cwd: $TRASH_DIRECTORY/15/sub/sub
2123 setup: prefix: (null)
2124 EOF
2125         test_repo 15/sub/sub ../../.git ../../wt
2126 '
2127
2128 test_expect_success '#15: GIT_DIR, GIT_WORK_TREE=wt(rel) in subdir' '
2129         cat >15/sub/sub/expected <<EOF &&
2130 setup: git_dir: $TRASH_DIRECTORY/15.git
2131 setup: worktree: $TRASH_DIRECTORY/15/wt
2132 setup: cwd: $TRASH_DIRECTORY/15/sub/sub
2133 setup: prefix: (null)
2134 EOF
2135         test_repo 15/sub/sub "$TRASH_DIRECTORY/15/.git" ../../wt
2136 '
2137
2138 test_expect_success '#15: GIT_DIR, GIT_WORK_TREE=wt in subdir' '
2139         cat >15/sub/sub/expected <<EOF &&
2140 setup: git_dir: $TRASH_DIRECTORY/15.git
2141 setup: worktree: $TRASH_DIRECTORY/15/wt
2142 setup: cwd: $TRASH_DIRECTORY/15/sub/sub
2143 setup: prefix: (null)
2144 EOF
2145         test_repo 15/sub/sub "$TRASH_DIRECTORY/15/.git" "$TRASH_DIRECTORY/15/wt"
2146 '
2147
2148 test_expect_success '#15: GIT_DIR(rel), GIT_WORK_TREE=.. at root' '
2149         cat >15/expected <<EOF &&
2150 setup: git_dir: $TRASH_DIRECTORY/15.git
2151 setup: worktree: $TRASH_DIRECTORY
2152 setup: cwd: $TRASH_DIRECTORY
2153 setup: prefix: 15/
2154 EOF
2155         test_repo 15 .git "$TRASH_DIRECTORY"
2156 '
2157
2158 test_expect_success '#15: GIT_DIR(rel), GIT_WORK_TREE=..(rel) at root' '
2159         cat >15/expected <<EOF &&
2160 setup: git_dir: $TRASH_DIRECTORY/15.git
2161 setup: worktree: $TRASH_DIRECTORY
2162 setup: cwd: $TRASH_DIRECTORY
2163 setup: prefix: 15/
2164 EOF
2165         test_repo 15 .git ..
2166 '
2167
2168 test_expect_success '#15: GIT_DIR, GIT_WORK_TREE=..(rel) at root' '
2169         cat >15/expected <<EOF &&
2170 setup: git_dir: $TRASH_DIRECTORY/15.git
2171 setup: worktree: $TRASH_DIRECTORY
2172 setup: cwd: $TRASH_DIRECTORY
2173 setup: prefix: 15/
2174 EOF
2175         test_repo 15 "$TRASH_DIRECTORY/15/.git" ..
2176 '
2177
2178 test_expect_success '#15: GIT_DIR, GIT_WORK_TREE=.. at root' '
2179         cat >15/expected <<EOF &&
2180 setup: git_dir: $TRASH_DIRECTORY/15.git
2181 setup: worktree: $TRASH_DIRECTORY
2182 setup: cwd: $TRASH_DIRECTORY
2183 setup: prefix: 15/
2184 EOF
2185         test_repo 15 "$TRASH_DIRECTORY/15/.git" "$TRASH_DIRECTORY"
2186 '
2187
2188 test_expect_success '#15: GIT_DIR(rel), GIT_WORK_TREE=.. in subdir' '
2189         cat >15/sub/sub/expected <<EOF &&
2190 setup: git_dir: $TRASH_DIRECTORY/15.git
2191 setup: worktree: $TRASH_DIRECTORY
2192 setup: cwd: $TRASH_DIRECTORY
2193 setup: prefix: 15/sub/sub/
2194 EOF
2195         test_repo 15/sub/sub ../../.git "$TRASH_DIRECTORY"
2196 '
2197
2198 test_expect_success '#15: GIT_DIR(rel), GIT_WORK_TREE=..(rel) in subdir' '
2199         cat >15/sub/sub/expected <<EOF &&
2200 setup: git_dir: $TRASH_DIRECTORY/15.git
2201 setup: worktree: $TRASH_DIRECTORY
2202 setup: cwd: $TRASH_DIRECTORY
2203 setup: prefix: 15/sub/sub/
2204 EOF
2205         test_repo 15/sub/sub ../../.git ../../..
2206 '
2207
2208 test_expect_success '#15: GIT_DIR, GIT_WORK_TREE=..(rel) in subdir' '
2209         cat >15/sub/sub/expected <<EOF &&
2210 setup: git_dir: $TRASH_DIRECTORY/15.git
2211 setup: worktree: $TRASH_DIRECTORY
2212 setup: cwd: $TRASH_DIRECTORY
2213 setup: prefix: 15/sub/sub/
2214 EOF
2215         test_repo 15/sub/sub "$TRASH_DIRECTORY/15/.git" ../../../
2216 '
2217
2218 test_expect_success '#15: GIT_DIR, GIT_WORK_TREE=.. in subdir' '
2219         cat >15/sub/sub/expected <<EOF &&
2220 setup: git_dir: $TRASH_DIRECTORY/15.git
2221 setup: worktree: $TRASH_DIRECTORY
2222 setup: cwd: $TRASH_DIRECTORY
2223 setup: prefix: 15/sub/sub/
2224 EOF
2225         test_repo 15/sub/sub "$TRASH_DIRECTORY/15/.git" "$TRASH_DIRECTORY"
2226 '
2227
2228 #
2229 # case #16.1
2230 #
2231 ############################################################
2232 #
2233 # Input:
2234 #
2235 #  - GIT_WORK_TREE is not set
2236 #  - GIT_DIR is not set
2237 #  - core.worktree is not set
2238 #  - .git is a directory
2239 #  - cwd is inside .git
2240 #
2241 # Output:
2242 #
2243 #  - no worktree
2244 #  - cwd is unchanged
2245 #  - prefix is NULL
2246 #  - git_dir is set
2247 #  - cwd can't be outside worktree
2248
2249 test_expect_success '#16.1: setup' '
2250         sane_unset GIT_DIR GIT_WORK_TREE &&
2251         mkdir 16 16/sub &&
2252         cd 16 &&
2253         git init &&
2254         mkdir .git/wt .git/wt/sub &&
2255         cd ..
2256 '
2257
2258 test_expect_success '#16.1: at .git' '
2259         cat >16/.git/expected <<EOF &&
2260 setup: git_dir: .
2261 setup: worktree: (null)
2262 setup: cwd: $TRASH_DIRECTORY/16/.git
2263 setup: prefix: (null)
2264 EOF
2265         test_repo 16/.git
2266 '
2267
2268 test_expect_success '#16.1: in .git/wt' '
2269         cat >16/.git/wt/expected <<EOF &&
2270 setup: git_dir: $TRASH_DIRECTORY/16/.git
2271 setup: worktree: (null)
2272 setup: cwd: $TRASH_DIRECTORY/16/.git/wt
2273 setup: prefix: (null)
2274 EOF
2275         test_repo 16/.git/wt
2276 '
2277
2278 test_expect_success '#16.1: in .git/wt/sub' '
2279         cat >16/.git/wt/sub/expected <<EOF &&
2280 setup: git_dir: $TRASH_DIRECTORY/16/.git
2281 setup: worktree: (null)
2282 setup: cwd: $TRASH_DIRECTORY/16/.git/wt/sub
2283 setup: prefix: (null)
2284 EOF
2285         test_repo 16/.git/wt/sub
2286 '
2287
2288 #
2289 # case #16.2
2290 #
2291 ############################################################
2292 #
2293 # Input:
2294 #
2295 #  - GIT_WORK_TREE is not set
2296 #  - GIT_DIR is not set
2297 #  - core.worktree is not set
2298 #  - .git is a directory
2299 #  - core.bare is set
2300 #
2301 # Output:
2302 #
2303 #  - no worktree
2304 #  - cwd is unchanged
2305 #  - prefix is NULL
2306 #  - git_dir is set
2307 #  - cwd can't be outside worktree
2308
2309 test_expect_success '#16.2: setup' '
2310         git config --file="$TRASH_DIRECTORY/16/.git/config" core.bare true
2311 '
2312
2313 test_expect_success '#16.2: at .git' '
2314         cat >16/.git/expected <<EOF &&
2315 setup: git_dir: .
2316 setup: worktree: (null)
2317 setup: cwd: $TRASH_DIRECTORY/16/.git
2318 setup: prefix: (null)
2319 EOF
2320         test_repo 16/.git
2321 '
2322
2323 test_expect_success '#16.2: in .git/wt' '
2324         cat >16/.git/wt/expected <<EOF &&
2325 setup: git_dir: $TRASH_DIRECTORY/16/.git
2326 setup: worktree: (null)
2327 setup: cwd: $TRASH_DIRECTORY/16/.git/wt
2328 setup: prefix: (null)
2329 EOF
2330         test_repo 16/.git/wt
2331 '
2332
2333 test_expect_success '#16.2: in .git/wt/sub' '
2334         cat >16/.git/wt/sub/expected <<EOF &&
2335 setup: git_dir: $TRASH_DIRECTORY/16/.git
2336 setup: worktree: (null)
2337 setup: cwd: $TRASH_DIRECTORY/16/.git/wt/sub
2338 setup: prefix: (null)
2339 EOF
2340         test_repo 16/.git/wt/sub
2341 '
2342
2343 test_expect_success '#16.2: at root' '
2344         cat >16/expected <<EOF &&
2345 setup: git_dir: .git
2346 setup: worktree: (null)
2347 setup: cwd: $TRASH_DIRECTORY/16
2348 setup: prefix: (null)
2349 EOF
2350         test_repo 16
2351 '
2352
2353 test_expect_success '#16.2: in subdir' '
2354         cat >16/sub/expected <<EOF &&
2355 setup: git_dir: $TRASH_DIRECTORY/16/.git
2356 setup: worktree: (null)
2357 setup: cwd: $TRASH_DIRECTORY/16/sub
2358 setup: prefix: (null)
2359 EOF
2360         test_repo 16/sub
2361 '
2362
2363 #
2364 # case #17.1
2365 #
2366 ############################################################
2367 #
2368 # Input:
2369 #
2370 #  - GIT_WORK_TREE is set
2371 #  - GIT_DIR is not set
2372 #  - core.worktree is not set
2373 #  - .git is a directory
2374 #  - cwd is inside .git
2375 #
2376 # Output:
2377 #
2378 # GIT_WORK_TREE is ignored -> #16.1 (with warnings perhaps)
2379
2380 test_expect_success '#17.1: setup' '
2381         sane_unset GIT_DIR GIT_WORK_TREE &&
2382         mkdir 17 17/sub &&
2383         cd 17 &&
2384         git init &&
2385         mkdir .git/wt .git/wt/sub &&
2386         GIT_WORK_TREE=non-existent &&
2387         export GIT_WORK_TREE &&
2388         cd ..
2389 '
2390
2391 test_expect_success '#17.1: at .git' '
2392         cat >17/.git/expected <<EOF &&
2393 setup: git_dir: .
2394 setup: worktree: (null)
2395 setup: cwd: $TRASH_DIRECTORY/17/.git
2396 setup: prefix: (null)
2397 EOF
2398         test_repo 17/.git
2399 '
2400
2401 test_expect_success '#17.1: in .git/wt' '
2402         cat >17/.git/wt/expected <<EOF &&
2403 setup: git_dir: $TRASH_DIRECTORY/17/.git
2404 setup: worktree: (null)
2405 setup: cwd: $TRASH_DIRECTORY/17/.git/wt
2406 setup: prefix: (null)
2407 EOF
2408         test_repo 17/.git/wt
2409 '
2410
2411 test_expect_success '#17.1: in .git/wt/sub' '
2412         cat >17/.git/wt/sub/expected <<EOF &&
2413 setup: git_dir: $TRASH_DIRECTORY/17/.git
2414 setup: worktree: (null)
2415 setup: cwd: $TRASH_DIRECTORY/17/.git/wt/sub
2416 setup: prefix: (null)
2417 EOF
2418         test_repo 17/.git/wt/sub
2419 '
2420
2421 #
2422 # case #17.2
2423 #
2424 ############################################################
2425 #
2426 # Input:
2427 #
2428 #  - GIT_WORK_TREE is set
2429 #  - GIT_DIR is not set
2430 #  - core.worktree is not set
2431 #  - .git is a directory
2432 #  - core.bare is set
2433 #
2434 # Output:
2435 #
2436 # GIT_WORK_TREE is ignored -> #16.2 (with warnings perhaps)
2437
2438 test_expect_success '#17.2: setup' '
2439         git config --file="$TRASH_DIRECTORY/17/.git/config" core.bare true
2440 '
2441
2442 test_expect_success '#17.2: at .git' '
2443         cat >17/.git/expected <<EOF &&
2444 setup: git_dir: .
2445 setup: worktree: (null)
2446 setup: cwd: $TRASH_DIRECTORY/17/.git
2447 setup: prefix: (null)
2448 EOF
2449         test_repo 17/.git
2450 '
2451
2452 test_expect_success '#17.2: in .git/wt' '
2453         cat >17/.git/wt/expected <<EOF &&
2454 setup: git_dir: $TRASH_DIRECTORY/17/.git
2455 setup: worktree: (null)
2456 setup: cwd: $TRASH_DIRECTORY/17/.git/wt
2457 setup: prefix: (null)
2458 EOF
2459         test_repo 17/.git/wt
2460 '
2461
2462 test_expect_success '#17.2: in .git/wt/sub' '
2463         cat >17/.git/wt/sub/expected <<EOF &&
2464 setup: git_dir: $TRASH_DIRECTORY/17/.git
2465 setup: worktree: (null)
2466 setup: cwd: $TRASH_DIRECTORY/17/.git/wt/sub
2467 setup: prefix: (null)
2468 EOF
2469         test_repo 17/.git/wt/sub
2470 '
2471
2472 test_expect_success '#17.2: at root' '
2473         cat >17/expected <<EOF &&
2474 setup: git_dir: .git
2475 setup: worktree: (null)
2476 setup: cwd: $TRASH_DIRECTORY/17
2477 setup: prefix: (null)
2478 EOF
2479         test_repo 17
2480 '
2481
2482 test_expect_success '#17.2: in subdir' '
2483         cat >17/sub/expected <<EOF &&
2484 setup: git_dir: $TRASH_DIRECTORY/17/.git
2485 setup: worktree: (null)
2486 setup: cwd: $TRASH_DIRECTORY/17/sub
2487 setup: prefix: (null)
2488 EOF
2489         test_repo 17/sub
2490 '
2491
2492 #
2493 # case #18
2494 #
2495 ############################################################
2496 #
2497 # Input:
2498 #
2499 #  - GIT_WORK_TREE is not set
2500 #  - GIT_DIR is set
2501 #  - core.worktree is not set
2502 #  - .git is a directory
2503 #  - core.bare is set
2504 #
2505 # Output:
2506 #
2507 #  - no worktree (rule #8)
2508 #  - cwd is unchanged
2509 #  - prefix is NULL
2510 #  - git_dir is set to $GIT_DIR
2511 #  - cwd can't be outside worktree
2512
2513 test_expect_success '#18: setup' '
2514         sane_unset GIT_DIR GIT_WORK_TREE &&
2515         mkdir 18 18/sub &&
2516         cd 18 &&
2517         git init &&
2518         mkdir .git/wt .git/wt/sub &&
2519         git config core.bare true &&
2520         cd ..
2521 '
2522
2523 test_expect_success '#18: (rel) at root' '
2524         cat >18/expected <<EOF &&
2525 setup: git_dir: .git
2526 setup: worktree: (null)
2527 setup: cwd: $TRASH_DIRECTORY/18
2528 setup: prefix: (null)
2529 EOF
2530          test_repo 18 .git
2531 '
2532
2533 test_expect_success '#18: at root' '
2534         cat >18/expected <<EOF &&
2535 setup: git_dir: $TRASH_DIRECTORY/18/.git
2536 setup: worktree: (null)
2537 setup: cwd: $TRASH_DIRECTORY/18
2538 setup: prefix: (null)
2539 EOF
2540          test_repo 18 "$TRASH_DIRECTORY/18/.git"
2541 '
2542
2543 test_expect_success '#18: (rel) in subdir' '
2544         cat >18/sub/expected <<EOF &&
2545 setup: git_dir: ../.git
2546 setup: worktree: (null)
2547 setup: cwd: $TRASH_DIRECTORY/18/sub
2548 setup: prefix: (null)
2549 EOF
2550         test_repo 18/sub ../.git
2551 '
2552
2553 test_expect_success '#18: in subdir' '
2554         cat >18/sub/expected <<EOF &&
2555 setup: git_dir: $TRASH_DIRECTORY/18/.git
2556 setup: worktree: (null)
2557 setup: cwd: $TRASH_DIRECTORY/18/sub
2558 setup: prefix: (null)
2559 EOF
2560         test_repo 18/sub "$TRASH_DIRECTORY/18/.git"
2561 '
2562
2563 #
2564 # case #19
2565 #
2566 ############################################################
2567 #
2568 # Input:
2569 #
2570 #  - GIT_WORK_TREE is set
2571 #  - GIT_DIR is set
2572 #  - .git is a directory
2573 #  - core.worktree is not set
2574 #  - core.bare is set
2575 #
2576 # Output:
2577 #
2578 # bare repo is overridden by GIT_WORK_TREE -> #3
2579
2580 test_expect_success '#19: setup' '
2581         sane_unset GIT_DIR GIT_WORK_TREE &&
2582         mkdir 19 19/sub 19/sub/sub 19.wt 19.wt/sub 19/wt 19/wt/sub &&
2583         cd 19 &&
2584         git init &&
2585         git config core.bare true &&
2586         cd ..
2587 '
2588
2589 test_expect_success '#19: GIT_DIR(rel), GIT_WORK_TREE=root at root' '
2590         cat >19/expected <<EOF &&
2591 setup: git_dir: .git
2592 setup: worktree: $TRASH_DIRECTORY/19
2593 setup: cwd: $TRASH_DIRECTORY/19
2594 setup: prefix: (null)
2595 EOF
2596         test_repo 19 .git "$TRASH_DIRECTORY/19"
2597 '
2598
2599 test_expect_success '#19: GIT_DIR(rel), GIT_WORK_TREE=root(rel) at root' '
2600         cat >19/expected <<EOF &&
2601 setup: git_dir: .git
2602 setup: worktree: $TRASH_DIRECTORY/19
2603 setup: cwd: $TRASH_DIRECTORY/19
2604 setup: prefix: (null)
2605 EOF
2606         test_repo 19 .git .
2607 '
2608
2609 test_expect_success '#19: GIT_DIR, GIT_WORK_TREE=root at root' '
2610         cat >19/expected <<EOF &&
2611 setup: git_dir: $TRASH_DIRECTORY/19/.git
2612 setup: worktree: $TRASH_DIRECTORY/19
2613 setup: cwd: $TRASH_DIRECTORY/19
2614 setup: prefix: (null)
2615 EOF
2616         test_repo 19 "$TRASH_DIRECTORY/19/.git" "$TRASH_DIRECTORY/19"
2617 '
2618
2619 test_expect_success '#19: GIT_DIR, GIT_WORK_TREE=root(rel) at root' '
2620         cat >19/expected <<EOF &&
2621 setup: git_dir: $TRASH_DIRECTORY/19/.git
2622 setup: worktree: $TRASH_DIRECTORY/19
2623 setup: cwd: $TRASH_DIRECTORY/19
2624 setup: prefix: (null)
2625 EOF
2626         test_repo 19 "$TRASH_DIRECTORY/19/.git" .
2627 '
2628
2629 test_expect_success '#19: GIT_DIR(rel), GIT_WORKTREE=root in subdir' '
2630         cat >19/sub/sub/expected <<EOF &&
2631 setup: git_dir: $TRASH_DIRECTORY/19/.git
2632 setup: worktree: $TRASH_DIRECTORY/19
2633 setup: cwd: $TRASH_DIRECTORY/19
2634 setup: prefix: sub/sub/
2635 EOF
2636         test_repo 19/sub/sub ../../.git "$TRASH_DIRECTORY/19"
2637 '
2638
2639 test_expect_success '#19: GIT_DIR(rel), GIT_WORKTREE=root(rel) in subdir' '
2640         cat >19/sub/sub/expected <<EOF &&
2641 setup: git_dir: $TRASH_DIRECTORY/19/.git
2642 setup: worktree: $TRASH_DIRECTORY/19
2643 setup: cwd: $TRASH_DIRECTORY/19
2644 setup: prefix: sub/sub/
2645 EOF
2646         test_repo 19/sub/sub ../../.git ../..
2647 '
2648
2649 test_expect_success '#19: GIT_DIR, GIT_WORKTREE=root in subdir' '
2650         cat >19/sub/expected <<EOF &&
2651 setup: git_dir: $TRASH_DIRECTORY/19/.git
2652 setup: worktree: $TRASH_DIRECTORY/19
2653 setup: cwd: $TRASH_DIRECTORY/19
2654 setup: prefix: sub/
2655 EOF
2656         test_repo 19/sub "$TRASH_DIRECTORY/19/.git" "$TRASH_DIRECTORY/19"
2657 '
2658
2659 test_expect_success '#19: GIT_DIR, GIT_WORKTREE=root(rel) in subdir' '
2660         cat >19/sub/sub/expected <<EOF &&
2661 setup: git_dir: $TRASH_DIRECTORY/19/.git
2662 setup: worktree: $TRASH_DIRECTORY/19
2663 setup: cwd: $TRASH_DIRECTORY/19
2664 setup: prefix: sub/sub/
2665 EOF
2666         test_repo 19/sub/sub "$TRASH_DIRECTORY/19/.git" ../..
2667 '
2668
2669 test_expect_success '#19: GIT_DIR(rel), GIT_WORK_TREE=wt at root' '
2670         cat >19/expected <<EOF &&
2671 setup: git_dir: .git
2672 setup: worktree: $TRASH_DIRECTORY/19/wt
2673 setup: cwd: $TRASH_DIRECTORY/19
2674 setup: prefix: (null)
2675 EOF
2676         test_repo 19 .git "$TRASH_DIRECTORY/19/wt"
2677 '
2678
2679 test_expect_success '#19: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) at root' '
2680         cat >19/expected <<EOF &&
2681 setup: git_dir: .git
2682 setup: worktree: $TRASH_DIRECTORY/19/wt
2683 setup: cwd: $TRASH_DIRECTORY/19
2684 setup: prefix: (null)
2685 EOF
2686         test_repo 19 .git wt
2687 '
2688
2689 test_expect_success '#19: GIT_DIR, GIT_WORK_TREE=wt(rel) at root' '
2690         cat >19/expected <<EOF &&
2691 setup: git_dir: $TRASH_DIRECTORY/19/.git
2692 setup: worktree: $TRASH_DIRECTORY/19/wt
2693 setup: cwd: $TRASH_DIRECTORY/19
2694 setup: prefix: (null)
2695 EOF
2696         test_repo 19 "$TRASH_DIRECTORY/19/.git" wt
2697 '
2698
2699 test_expect_success '#19: GIT_DIR, GIT_WORK_TREE=wt at root' '
2700         cat >19/expected <<EOF &&
2701 setup: git_dir: $TRASH_DIRECTORY/19/.git
2702 setup: worktree: $TRASH_DIRECTORY/19/wt
2703 setup: cwd: $TRASH_DIRECTORY/19
2704 setup: prefix: (null)
2705 EOF
2706         test_repo 19 "$TRASH_DIRECTORY/19/.git" "$TRASH_DIRECTORY/19/wt"
2707 '
2708
2709 test_expect_success '#19: GIT_DIR(rel), GIT_WORK_TREE=wt in subdir' '
2710         cat >19/sub/sub/expected <<EOF &&
2711 setup: git_dir: ../../.git
2712 setup: worktree: $TRASH_DIRECTORY/19/wt
2713 setup: cwd: $TRASH_DIRECTORY/19/sub/sub
2714 setup: prefix: (null)
2715 EOF
2716         test_repo 19/sub/sub ../../.git "$TRASH_DIRECTORY/19/wt"
2717 '
2718
2719 test_expect_success '#19: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) in subdir' '
2720         cat >19/sub/sub/expected <<EOF &&
2721 setup: git_dir: ../../.git
2722 setup: worktree: $TRASH_DIRECTORY/19/wt
2723 setup: cwd: $TRASH_DIRECTORY/19/sub/sub
2724 setup: prefix: (null)
2725 EOF
2726         test_repo 19/sub/sub ../../.git ../../wt
2727 '
2728
2729 test_expect_success '#19: GIT_DIR, GIT_WORK_TREE=wt(rel) in subdir' '
2730         cat >19/sub/sub/expected <<EOF &&
2731 setup: git_dir: $TRASH_DIRECTORY/19/.git
2732 setup: worktree: $TRASH_DIRECTORY/19/wt
2733 setup: cwd: $TRASH_DIRECTORY/19/sub/sub
2734 setup: prefix: (null)
2735 EOF
2736         test_repo 19/sub/sub "$TRASH_DIRECTORY/19/.git" ../../wt
2737 '
2738
2739 test_expect_success '#19: GIT_DIR, GIT_WORK_TREE=wt in subdir' '
2740         cat >19/sub/sub/expected <<EOF &&
2741 setup: git_dir: $TRASH_DIRECTORY/19/.git
2742 setup: worktree: $TRASH_DIRECTORY/19/wt
2743 setup: cwd: $TRASH_DIRECTORY/19/sub/sub
2744 setup: prefix: (null)
2745 EOF
2746         test_repo 19/sub/sub "$TRASH_DIRECTORY/19/.git" "$TRASH_DIRECTORY/19/wt"
2747 '
2748
2749 test_expect_success '#19: GIT_DIR(rel), GIT_WORK_TREE=.. at root' '
2750         cat >19/expected <<EOF &&
2751 setup: git_dir: $TRASH_DIRECTORY/19/.git
2752 setup: worktree: $TRASH_DIRECTORY
2753 setup: cwd: $TRASH_DIRECTORY
2754 setup: prefix: 19/
2755 EOF
2756         test_repo 19 .git "$TRASH_DIRECTORY"
2757 '
2758
2759 test_expect_success '#19: GIT_DIR(rel), GIT_WORK_TREE=..(rel) at root' '
2760         cat >19/expected <<EOF &&
2761 setup: git_dir: $TRASH_DIRECTORY/19/.git
2762 setup: worktree: $TRASH_DIRECTORY
2763 setup: cwd: $TRASH_DIRECTORY
2764 setup: prefix: 19/
2765 EOF
2766         test_repo 19 .git ..
2767 '
2768
2769 test_expect_success '#19: GIT_DIR, GIT_WORK_TREE=..(rel) at root' '
2770         cat >19/expected <<EOF &&
2771 setup: git_dir: $TRASH_DIRECTORY/19/.git
2772 setup: worktree: $TRASH_DIRECTORY
2773 setup: cwd: $TRASH_DIRECTORY
2774 setup: prefix: 19/
2775 EOF
2776         test_repo 19 "$TRASH_DIRECTORY/19/.git" ..
2777 '
2778
2779 test_expect_success '#19: GIT_DIR, GIT_WORK_TREE=.. at root' '
2780         cat >19/expected <<EOF &&
2781 setup: git_dir: $TRASH_DIRECTORY/19/.git
2782 setup: worktree: $TRASH_DIRECTORY
2783 setup: cwd: $TRASH_DIRECTORY
2784 setup: prefix: 19/
2785 EOF
2786         test_repo 19 "$TRASH_DIRECTORY/19/.git" "$TRASH_DIRECTORY"
2787 '
2788
2789 test_expect_success '#19: GIT_DIR(rel), GIT_WORK_TREE=.. in subdir' '
2790         cat >19/sub/sub/expected <<EOF &&
2791 setup: git_dir: $TRASH_DIRECTORY/19/.git
2792 setup: worktree: $TRASH_DIRECTORY
2793 setup: cwd: $TRASH_DIRECTORY
2794 setup: prefix: 19/sub/sub/
2795 EOF
2796         test_repo 19/sub/sub ../../.git "$TRASH_DIRECTORY"
2797 '
2798
2799 test_expect_success '#19: GIT_DIR(rel), GIT_WORK_TREE=..(rel) in subdir' '
2800         cat >19/sub/sub/expected <<EOF &&
2801 setup: git_dir: $TRASH_DIRECTORY/19/.git
2802 setup: worktree: $TRASH_DIRECTORY
2803 setup: cwd: $TRASH_DIRECTORY
2804 setup: prefix: 19/sub/sub/
2805 EOF
2806         test_repo 19/sub/sub ../../.git ../../..
2807 '
2808
2809 test_expect_success '#19: GIT_DIR, GIT_WORK_TREE=..(rel) in subdir' '
2810         cat >19/sub/sub/expected <<EOF &&
2811 setup: git_dir: $TRASH_DIRECTORY/19/.git
2812 setup: worktree: $TRASH_DIRECTORY
2813 setup: cwd: $TRASH_DIRECTORY
2814 setup: prefix: 19/sub/sub/
2815 EOF
2816         test_repo 19/sub/sub "$TRASH_DIRECTORY/19/.git" ../../../
2817 '
2818
2819 test_expect_success '#19: GIT_DIR, GIT_WORK_TREE=.. in subdir' '
2820         cat >19/sub/sub/expected <<EOF &&
2821 setup: git_dir: $TRASH_DIRECTORY/19/.git
2822 setup: worktree: $TRASH_DIRECTORY
2823 setup: cwd: $TRASH_DIRECTORY
2824 setup: prefix: 19/sub/sub/
2825 EOF
2826         test_repo 19/sub/sub "$TRASH_DIRECTORY/19/.git" "$TRASH_DIRECTORY"
2827 '
2828
2829 #
2830 # case #20.1
2831 #
2832 ############################################################
2833 #
2834 # Input:
2835 #
2836 #  - GIT_WORK_TREE is not set
2837 #  - GIT_DIR is not set
2838 #  - core.worktree is set
2839 #  - .git is a directory
2840 #  - cwd is inside .git
2841 #
2842 # Output:
2843 #
2844 # core.worktree is ignored -> #16.1
2845
2846 test_expect_success '#20.1: setup' '
2847         sane_unset GIT_DIR GIT_WORK_TREE &&
2848         mkdir 20 20/sub &&
2849         cd 20 &&
2850         git init &&
2851         git config core.worktree non-existent &&
2852         mkdir .git/wt .git/wt/sub &&
2853         cd ..
2854 '
2855
2856 test_expect_success '#20.1: at .git' '
2857         cat >20/.git/expected <<EOF &&
2858 setup: git_dir: .
2859 setup: worktree: (null)
2860 setup: cwd: $TRASH_DIRECTORY/20/.git
2861 setup: prefix: (null)
2862 EOF
2863         test_repo 20/.git
2864 '
2865
2866 test_expect_success '#20.1: in .git/wt' '
2867         cat >20/.git/wt/expected <<EOF &&
2868 setup: git_dir: $TRASH_DIRECTORY/20/.git
2869 setup: worktree: (null)
2870 setup: cwd: $TRASH_DIRECTORY/20/.git/wt
2871 setup: prefix: (null)
2872 EOF
2873         test_repo 20/.git/wt
2874 '
2875
2876 test_expect_success '#20.1: in .git/wt/sub' '
2877         cat >20/.git/wt/sub/expected <<EOF &&
2878 setup: git_dir: $TRASH_DIRECTORY/20/.git
2879 setup: worktree: (null)
2880 setup: cwd: $TRASH_DIRECTORY/20/.git/wt/sub
2881 setup: prefix: (null)
2882 EOF
2883         test_repo 20/.git/wt/sub
2884 '
2885
2886 #
2887 # case #20.2
2888 #
2889 ############################################################
2890 #
2891 # Input:
2892 #
2893 #  - GIT_WORK_TREE is not set
2894 #  - GIT_DIR is not set
2895 #  - core.worktree is set
2896 #  - .git is a directory
2897 #  - core.bare is set
2898 #
2899 # Output:
2900 #
2901 # core.worktree is ignored -> #16.2
2902
2903 test_expect_success '#20.2: setup' '
2904         git config --file="$TRASH_DIRECTORY/20/.git/config" core.bare true
2905 '
2906
2907 test_expect_success '#20.2: at .git' '
2908         cat >20/.git/expected <<EOF &&
2909 setup: git_dir: .
2910 setup: worktree: (null)
2911 setup: cwd: $TRASH_DIRECTORY/20/.git
2912 setup: prefix: (null)
2913 EOF
2914         test_repo 20/.git
2915 '
2916
2917 test_expect_success '#20.2: in .git/wt' '
2918         cat >20/.git/wt/expected <<EOF &&
2919 setup: git_dir: $TRASH_DIRECTORY/20/.git
2920 setup: worktree: (null)
2921 setup: cwd: $TRASH_DIRECTORY/20/.git/wt
2922 setup: prefix: (null)
2923 EOF
2924         test_repo 20/.git/wt
2925 '
2926
2927 test_expect_success '#20.2: in .git/wt/sub' '
2928         cat >20/.git/wt/sub/expected <<EOF &&
2929 setup: git_dir: $TRASH_DIRECTORY/20/.git
2930 setup: worktree: (null)
2931 setup: cwd: $TRASH_DIRECTORY/20/.git/wt/sub
2932 setup: prefix: (null)
2933 EOF
2934         test_repo 20/.git/wt/sub
2935 '
2936
2937 test_expect_success '#20.2: at root' '
2938         cat >20/expected <<EOF &&
2939 setup: git_dir: .git
2940 setup: worktree: (null)
2941 setup: cwd: $TRASH_DIRECTORY/20
2942 setup: prefix: (null)
2943 EOF
2944         test_repo 20
2945 '
2946
2947 test_expect_success '#20.2: in subdir' '
2948         cat >20/sub/expected <<EOF &&
2949 setup: git_dir: $TRASH_DIRECTORY/20/.git
2950 setup: worktree: (null)
2951 setup: cwd: $TRASH_DIRECTORY/20/sub
2952 setup: prefix: (null)
2953 EOF
2954         test_repo 20/sub
2955 '
2956
2957 #
2958 # case #21.1
2959 #
2960 ############################################################
2961 #
2962 # Input:
2963 #
2964 #  - GIT_WORK_TREE is set
2965 #  - GIT_DIR is not set
2966 #  - core.worktree is set
2967 #  - .git is a directory
2968 #  - cwd is inside .git
2969 #
2970 # Output:
2971 #
2972 # GIT_WORK_TREE/core.worktree are ignored -> #20.1
2973
2974 test_expect_success '#21.1: setup' '
2975         sane_unset GIT_DIR GIT_WORK_TREE &&
2976         mkdir 21 21/sub &&
2977         cd 21 &&
2978         git init &&
2979         git config core.worktree non-existent &&
2980         GIT_WORK_TREE=non-existent-too &&
2981         export GIT_WORK_TREE &&
2982         mkdir .git/wt .git/wt/sub &&
2983         cd ..
2984 '
2985
2986 test_expect_success '#21.1: at .git' '
2987         cat >21/.git/expected <<EOF &&
2988 setup: git_dir: .
2989 setup: worktree: (null)
2990 setup: cwd: $TRASH_DIRECTORY/21/.git
2991 setup: prefix: (null)
2992 EOF
2993         test_repo 21/.git
2994 '
2995
2996 test_expect_success '#21.1: in .git/wt' '
2997         cat >21/.git/wt/expected <<EOF &&
2998 setup: git_dir: $TRASH_DIRECTORY/21/.git
2999 setup: worktree: (null)
3000 setup: cwd: $TRASH_DIRECTORY/21/.git/wt
3001 setup: prefix: (null)
3002 EOF
3003         test_repo 21/.git/wt
3004 '
3005
3006 test_expect_success '#21.1: in .git/wt/sub' '
3007         cat >21/.git/wt/sub/expected <<EOF &&
3008 setup: git_dir: $TRASH_DIRECTORY/21/.git
3009 setup: worktree: (null)
3010 setup: cwd: $TRASH_DIRECTORY/21/.git/wt/sub
3011 setup: prefix: (null)
3012 EOF
3013         test_repo 21/.git/wt/sub
3014 '
3015
3016 #
3017 # case #21.2
3018 #
3019 ############################################################
3020 #
3021 # Input:
3022 #
3023 #  - GIT_WORK_TREE is set
3024 #  - GIT_DIR is not set
3025 #  - core.worktree is set
3026 #  - .git is a directory
3027 #  - core.bare is set
3028 #
3029 # Output:
3030 #
3031 # GIT_WORK_TREE/core.worktree are ignored -> #20.2
3032
3033 test_expect_success '#21.2: setup' '
3034         git config --file="$TRASH_DIRECTORY/21/.git/config" core.bare true
3035 '
3036
3037 test_expect_success '#21.2: at .git' '
3038         cat >21/.git/expected <<EOF &&
3039 setup: git_dir: .
3040 setup: worktree: (null)
3041 setup: cwd: $TRASH_DIRECTORY/21/.git
3042 setup: prefix: (null)
3043 EOF
3044         test_repo 21/.git
3045 '
3046
3047 test_expect_success '#21.2: in .git/wt' '
3048         cat >21/.git/wt/expected <<EOF &&
3049 setup: git_dir: $TRASH_DIRECTORY/21/.git
3050 setup: worktree: (null)
3051 setup: cwd: $TRASH_DIRECTORY/21/.git/wt
3052 setup: prefix: (null)
3053 EOF
3054         test_repo 21/.git/wt
3055 '
3056
3057 test_expect_success '#21.2: in .git/wt/sub' '
3058         cat >21/.git/wt/sub/expected <<EOF &&
3059 setup: git_dir: $TRASH_DIRECTORY/21/.git
3060 setup: worktree: (null)
3061 setup: cwd: $TRASH_DIRECTORY/21/.git/wt/sub
3062 setup: prefix: (null)
3063 EOF
3064         test_repo 21/.git/wt/sub
3065 '
3066
3067 test_expect_success '#21.2: at root' '
3068         cat >21/expected <<EOF &&
3069 setup: git_dir: .git
3070 setup: worktree: (null)
3071 setup: cwd: $TRASH_DIRECTORY/21
3072 setup: prefix: (null)
3073 EOF
3074         test_repo 21
3075 '
3076
3077 test_expect_success '#21.2: in subdir' '
3078         cat >21/sub/expected <<EOF &&
3079 setup: git_dir: $TRASH_DIRECTORY/21/.git
3080 setup: worktree: (null)
3081 setup: cwd: $TRASH_DIRECTORY/21/sub
3082 setup: prefix: (null)
3083 EOF
3084         test_repo 21/sub
3085 '
3086
3087 #
3088 # case #22.1
3089 #
3090 ############################################################
3091 #
3092 # Input:
3093 #
3094 #  - GIT_WORK_TREE is not set
3095 #  - GIT_DIR is set
3096 #  - core.worktree is set
3097 #  - .git is a directory
3098 #  - cwd is inside .git
3099 #
3100 # Output:
3101 #
3102 # bare attribute is ignored
3103 #
3104 #  - worktree is at core.worktree
3105 #  - cwd is at worktree root
3106 #  - prefix is calculated
3107 #  - git_dir is at $GIT_DIR
3108 #  - cwd can be outside worktree
3109
3110 test_expect_success '#22.1: setup' '
3111         sane_unset GIT_DIR GIT_WORK_TREE &&
3112         mkdir 22 &&
3113         cd 22 &&
3114         git init &&
3115         mkdir .git/sub .git/wt .git/wt/sub &&
3116         cd ..
3117 '
3118
3119 test_expect_success '#22.1: GIT_DIR(rel), core.worktree=. at .git' '
3120         cat >22/.git/expected <<EOF &&
3121 setup: git_dir: .
3122 setup: worktree: $TRASH_DIRECTORY/22/.git
3123 setup: cwd: $TRASH_DIRECTORY/22/.git
3124 setup: prefix: (null)
3125 EOF
3126         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree "$TRASH_DIRECTORY/22/.git" &&
3127         test_repo 22/.git .
3128 '
3129
3130 test_expect_success '#22.1: GIT_DIR(rel), core.worktree=.(rel) at .git' '
3131         cat >22/.git/expected <<EOF &&
3132 setup: git_dir: .
3133 setup: worktree: $TRASH_DIRECTORY/22/.git
3134 setup: cwd: $TRASH_DIRECTORY/22/.git
3135 setup: prefix: (null)
3136 EOF
3137         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree . &&
3138         test_repo 22/.git .
3139 '
3140
3141 test_expect_success '#22.1: GIT_DIR, core.worktree=. at .git' '
3142         cat >22/.git/expected <<EOF &&
3143 setup: git_dir: $TRASH_DIRECTORY/22/.git
3144 setup: worktree: $TRASH_DIRECTORY/22/.git
3145 setup: cwd: $TRASH_DIRECTORY/22/.git
3146 setup: prefix: (null)
3147 EOF
3148         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree "$TRASH_DIRECTORY/22/.git" &&
3149         test_repo 22/.git "$TRASH_DIRECTORY/22/.git"
3150 '
3151
3152 test_expect_success '#22.1: GIT_DIR, core.worktree=.(rel) at root' '
3153         cat >22/.git/expected <<EOF &&
3154 setup: git_dir: $TRASH_DIRECTORY/22/.git
3155 setup: worktree: $TRASH_DIRECTORY/22/.git
3156 setup: cwd: $TRASH_DIRECTORY/22/.git
3157 setup: prefix: (null)
3158 EOF
3159         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree . &&
3160         test_repo 22/.git "$TRASH_DIRECTORY/22/.git"
3161 '
3162
3163 test_expect_success '#22.1: GIT_DIR(rel), core.worktree=. in .git/sub' '
3164         cat >22/.git/sub/expected <<EOF &&
3165 setup: git_dir: $TRASH_DIRECTORY/22/.git
3166 setup: worktree: $TRASH_DIRECTORY/22/.git
3167 setup: cwd: $TRASH_DIRECTORY/22/.git
3168 setup: prefix: sub/
3169 EOF
3170         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree "$TRASH_DIRECTORY/22/.git" &&
3171         test_repo 22/.git/sub ..
3172 '
3173
3174 test_expect_success '#22.1: GIT_DIR(rel), core.worktree=.(rel) in .git/sub' '
3175         cat >22/.git/sub/expected <<EOF &&
3176 setup: git_dir: $TRASH_DIRECTORY/22/.git
3177 setup: worktree: $TRASH_DIRECTORY/22/.git
3178 setup: cwd: $TRASH_DIRECTORY/22/.git
3179 setup: prefix: sub/
3180 EOF
3181         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree . &&
3182         test_repo 22/.git/sub/ ..
3183 '
3184
3185 test_expect_success '#22.1: GIT_DIR, core.worktree=. in .git/sub' '
3186         cat >22/.git/sub/expected <<EOF &&
3187 setup: git_dir: $TRASH_DIRECTORY/22/.git
3188 setup: worktree: $TRASH_DIRECTORY/22/.git
3189 setup: cwd: $TRASH_DIRECTORY/22/.git
3190 setup: prefix: sub/
3191 EOF
3192         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree "$TRASH_DIRECTORY/22/.git" &&
3193         test_repo 22/.git/sub "$TRASH_DIRECTORY/22/.git"
3194 '
3195
3196 test_expect_success '#22.1: GIT_DIR, core.worktree=.(rel) in .git/sub' '
3197         cat >22/.git/sub/expected <<EOF &&
3198 setup: git_dir: $TRASH_DIRECTORY/22/.git
3199 setup: worktree: $TRASH_DIRECTORY/22/.git
3200 setup: cwd: $TRASH_DIRECTORY/22/.git
3201 setup: prefix: sub/
3202 EOF
3203         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree . &&
3204         test_repo 22/.git/sub "$TRASH_DIRECTORY/22/.git"
3205 '
3206
3207 test_expect_success '#22.1: GIT_DIR(rel), core.worktree=wt at .git' '
3208         cat >22/.git/expected <<EOF &&
3209 setup: git_dir: .
3210 setup: worktree: $TRASH_DIRECTORY/22/.git/wt
3211 setup: cwd: $TRASH_DIRECTORY/22/.git
3212 setup: prefix: (null)
3213 EOF
3214         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree "$TRASH_DIRECTORY/22/.git/wt" &&
3215         test_repo 22/.git .
3216 '
3217
3218 test_expect_success '#22.1: GIT_DIR(rel), core.worktree=wt(rel) at .git' '
3219         cat >22/.git/expected <<EOF &&
3220 setup: git_dir: .
3221 setup: worktree: $TRASH_DIRECTORY/22/.git/wt
3222 setup: cwd: $TRASH_DIRECTORY/22/.git
3223 setup: prefix: (null)
3224 EOF
3225         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree wt &&
3226         test_repo 22/.git .
3227 '
3228
3229 test_expect_success '#22.1: GIT_DIR, core.worktree=wt(rel) at .git' '
3230         cat >22/.git/expected <<EOF &&
3231 setup: git_dir: $TRASH_DIRECTORY/22/.git
3232 setup: worktree: $TRASH_DIRECTORY/22/.git/wt
3233 setup: cwd: $TRASH_DIRECTORY/22/.git
3234 setup: prefix: (null)
3235 EOF
3236         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree wt &&
3237         test_repo 22/.git "$TRASH_DIRECTORY/22/.git"
3238 '
3239
3240 test_expect_success '#22.1: GIT_DIR, core.worktree=wt at .git' '
3241         cat >22/.git/expected <<EOF &&
3242 setup: git_dir: $TRASH_DIRECTORY/22/.git
3243 setup: worktree: $TRASH_DIRECTORY/22/.git/wt
3244 setup: cwd: $TRASH_DIRECTORY/22/.git
3245 setup: prefix: (null)
3246 EOF
3247         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree "$TRASH_DIRECTORY/22/.git/wt" &&
3248         test_repo 22/.git "$TRASH_DIRECTORY/22/.git"
3249 '
3250
3251 test_expect_success '#22.1: GIT_DIR(rel), core.worktree=wt in .git/sub' '
3252         cat >22/.git/sub/expected <<EOF &&
3253 setup: git_dir: ..
3254 setup: worktree: $TRASH_DIRECTORY/22/.git/wt
3255 setup: cwd: $TRASH_DIRECTORY/22/.git/sub
3256 setup: prefix: (null)
3257 EOF
3258         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree "$TRASH_DIRECTORY/22/.git/wt" &&
3259         test_repo 22/.git/sub ..
3260 '
3261
3262 test_expect_success '#22.1: GIT_DIR(rel), core.worktree=wt(rel) in .git/sub' '
3263         cat >22/.git/sub/expected <<EOF &&
3264 setup: git_dir: ..
3265 setup: worktree: $TRASH_DIRECTORY/22/.git/wt
3266 setup: cwd: $TRASH_DIRECTORY/22/.git/sub
3267 setup: prefix: (null)
3268 EOF
3269         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree wt &&
3270         test_repo 22/.git/sub ..
3271 '
3272
3273 test_expect_success '#22.1: GIT_DIR, core.worktree=wt(rel) in .git/sub' '
3274         cat >22/.git/sub/expected <<EOF &&
3275 setup: git_dir: $TRASH_DIRECTORY/22/.git
3276 setup: worktree: $TRASH_DIRECTORY/22/.git/wt
3277 setup: cwd: $TRASH_DIRECTORY/22/.git/sub
3278 setup: prefix: (null)
3279 EOF
3280         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree wt &&
3281         test_repo 22/.git/sub "$TRASH_DIRECTORY/22/.git"
3282 '
3283
3284 test_expect_success '#22.1: GIT_DIR, core.worktree=wt in .git/sub' '
3285         cat >22/.git/sub/expected <<EOF &&
3286 setup: git_dir: $TRASH_DIRECTORY/22/.git
3287 setup: worktree: $TRASH_DIRECTORY/22/.git/wt
3288 setup: cwd: $TRASH_DIRECTORY/22/.git/sub
3289 setup: prefix: (null)
3290 EOF
3291         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree "$TRASH_DIRECTORY/22/.git/wt" &&
3292         test_repo 22/.git/sub "$TRASH_DIRECTORY/22/.git"
3293 '
3294
3295 test_expect_success '#22.1: GIT_DIR(rel), core.worktree=.. at .git' '
3296         cat >22/.git/expected <<EOF &&
3297 setup: git_dir: $TRASH_DIRECTORY/22/.git
3298 setup: worktree: $TRASH_DIRECTORY/22
3299 setup: cwd: $TRASH_DIRECTORY/22
3300 setup: prefix: .git/
3301 EOF
3302         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree "$TRASH_DIRECTORY/22" &&
3303         test_repo 22/.git .
3304 '
3305
3306 test_expect_success '#22.1: GIT_DIR(rel), core.worktree=..(rel) at .git' '
3307         cat >22/.git/expected <<EOF &&
3308 setup: git_dir: $TRASH_DIRECTORY/22/.git
3309 setup: worktree: $TRASH_DIRECTORY/22
3310 setup: cwd: $TRASH_DIRECTORY/22
3311 setup: prefix: .git/
3312 EOF
3313         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree .. &&
3314         test_repo 22/.git .
3315 '
3316
3317 test_expect_success '#22.1: GIT_DIR, core.worktree=..(rel) at .git' '
3318         cat >22/.git/expected <<EOF &&
3319 setup: git_dir: $TRASH_DIRECTORY/22/.git
3320 setup: worktree: $TRASH_DIRECTORY/22
3321 setup: cwd: $TRASH_DIRECTORY/22
3322 setup: prefix: .git/
3323 EOF
3324         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree .. &&
3325         test_repo 22/.git "$TRASH_DIRECTORY/22/.git"
3326 '
3327
3328 test_expect_success '#22.1: GIT_DIR, core.worktree=.. at .git' '
3329         cat >22/.git/expected <<EOF &&
3330 setup: git_dir: $TRASH_DIRECTORY/22/.git
3331 setup: worktree: $TRASH_DIRECTORY/22
3332 setup: cwd: $TRASH_DIRECTORY/22
3333 setup: prefix: .git/
3334 EOF
3335         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree "$TRASH_DIRECTORY/22" &&
3336         test_repo 22/.git "$TRASH_DIRECTORY/22/.git"
3337 '
3338
3339 test_expect_success '#22.1: GIT_DIR(rel), core.worktree=.. in .git/sub' '
3340         cat >22/.git/sub/expected <<EOF &&
3341 setup: git_dir: $TRASH_DIRECTORY/22/.git
3342 setup: worktree: $TRASH_DIRECTORY/22
3343 setup: cwd: $TRASH_DIRECTORY/22
3344 setup: prefix: .git/sub/
3345 EOF
3346         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree "$TRASH_DIRECTORY/22" &&
3347         test_repo 22/.git/sub ..
3348 '
3349
3350 test_expect_success '#22.1: GIT_DIR(rel), core.worktree=..(rel) in .git/sub' '
3351         cat >22/.git/sub/expected <<EOF &&
3352 setup: git_dir: $TRASH_DIRECTORY/22/.git
3353 setup: worktree: $TRASH_DIRECTORY/22
3354 setup: cwd: $TRASH_DIRECTORY/22
3355 setup: prefix: .git/sub/
3356 EOF
3357         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree .. &&
3358         test_repo 22/.git/sub ..
3359 '
3360
3361 test_expect_success '#22.1: GIT_DIR, core.worktree=..(rel) in .git/sub' '
3362         cat >22/.git/sub/expected <<EOF &&
3363 setup: git_dir: $TRASH_DIRECTORY/22/.git
3364 setup: worktree: $TRASH_DIRECTORY/22
3365 setup: cwd: $TRASH_DIRECTORY/22
3366 setup: prefix: .git/sub/
3367 EOF
3368         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree .. &&
3369         test_repo 22/.git/sub "$TRASH_DIRECTORY/22/.git"
3370 '
3371
3372 test_expect_success '#22.1: GIT_DIR, core.worktree=.. in .git/sub' '
3373         cat >22/.git/sub/expected <<EOF &&
3374 setup: git_dir: $TRASH_DIRECTORY/22/.git
3375 setup: worktree: $TRASH_DIRECTORY/22
3376 setup: cwd: $TRASH_DIRECTORY/22
3377 setup: prefix: .git/sub/
3378 EOF
3379         git config --file="$TRASH_DIRECTORY/22/.git/config" core.worktree "$TRASH_DIRECTORY/22" &&
3380         test_repo 22/.git/sub "$TRASH_DIRECTORY/22/.git"
3381 '
3382
3383 #
3384 # case #22.2
3385 #
3386 ############################################################
3387 #
3388 # Input:
3389 #
3390 #  - GIT_WORK_TREE is not set
3391 #  - GIT_DIR is set
3392 #  - core.worktree is set
3393 #  - .git is a directory
3394 #  - core.bare is set
3395 #
3396 # Output:
3397 #
3398 # core.worktree and core.bare conflict, won't fly.
3399
3400 test_expect_success '#22.2: setup' '
3401         git config --file="$TRASH_DIRECTORY/22/.git/config" core.bare true
3402 '
3403
3404 test_expect_success '#22.2: at .git' '
3405         (
3406         cd 22/.git &&
3407         GIT_DIR=. &&
3408         export GIT_DIR &&
3409         test_must_fail git symbolic-ref HEAD 2>result &&
3410         grep "core.bare and core.worktree do not make sense" result
3411         )
3412 '
3413
3414 test_expect_success '#22.2: at root' '
3415         (
3416         cd 22 &&
3417         GIT_DIR=.git &&
3418         export GIT_DIR &&
3419         test_must_fail git symbolic-ref HEAD 2>result &&
3420         grep "core.bare and core.worktree do not make sense" result
3421         )
3422 '
3423
3424 #
3425 # case #23
3426 #
3427 ############################################################
3428 #
3429 # Input:
3430 #
3431 #  - GIT_WORK_TREE is set
3432 #  - GIT_DIR is set
3433 #  - core.worktree is set
3434 #  - .git is a directory
3435 #  - core.bare is set
3436 #
3437 # Output:
3438 #
3439 # core.worktree is overridden by GIT_WORK_TREE -> #19
3440
3441 test_expect_success '#23: setup' '
3442         sane_unset GIT_DIR GIT_WORK_TREE &&
3443         mkdir 23 23/sub 23/sub/sub 23.wt 23.wt/sub 23/wt 23/wt/sub &&
3444         cd 23 &&
3445         git init &&
3446         git config core.bare true &&
3447         git config core.worktree non-existent &&
3448         cd ..
3449 '
3450
3451 test_expect_success '#23: GIT_DIR(rel), GIT_WORK_TREE=root at root' '
3452         cat >23/expected <<EOF &&
3453 setup: git_dir: .git
3454 setup: worktree: $TRASH_DIRECTORY/23
3455 setup: cwd: $TRASH_DIRECTORY/23
3456 setup: prefix: (null)
3457 EOF
3458         test_repo 23 .git "$TRASH_DIRECTORY/23"
3459 '
3460
3461 test_expect_success '#23: GIT_DIR(rel), GIT_WORK_TREE=root(rel) at root' '
3462         cat >23/expected <<EOF &&
3463 setup: git_dir: .git
3464 setup: worktree: $TRASH_DIRECTORY/23
3465 setup: cwd: $TRASH_DIRECTORY/23
3466 setup: prefix: (null)
3467 EOF
3468         test_repo 23 .git .
3469 '
3470
3471 test_expect_success '#23: GIT_DIR, GIT_WORK_TREE=root at root' '
3472         cat >23/expected <<EOF &&
3473 setup: git_dir: $TRASH_DIRECTORY/23/.git
3474 setup: worktree: $TRASH_DIRECTORY/23
3475 setup: cwd: $TRASH_DIRECTORY/23
3476 setup: prefix: (null)
3477 EOF
3478         test_repo 23 "$TRASH_DIRECTORY/23/.git" "$TRASH_DIRECTORY/23"
3479 '
3480
3481 test_expect_success '#23: GIT_DIR, GIT_WORK_TREE=root(rel) at root' '
3482         cat >23/expected <<EOF &&
3483 setup: git_dir: $TRASH_DIRECTORY/23/.git
3484 setup: worktree: $TRASH_DIRECTORY/23
3485 setup: cwd: $TRASH_DIRECTORY/23
3486 setup: prefix: (null)
3487 EOF
3488         test_repo 23 "$TRASH_DIRECTORY/23/.git" .
3489 '
3490
3491 test_expect_success '#23: GIT_DIR(rel), GIT_WORKTREE=root in subdir' '
3492         cat >23/sub/sub/expected <<EOF &&
3493 setup: git_dir: $TRASH_DIRECTORY/23/.git
3494 setup: worktree: $TRASH_DIRECTORY/23
3495 setup: cwd: $TRASH_DIRECTORY/23
3496 setup: prefix: sub/sub/
3497 EOF
3498         test_repo 23/sub/sub ../../.git "$TRASH_DIRECTORY/23"
3499 '
3500
3501 test_expect_success '#23: GIT_DIR(rel), GIT_WORKTREE=root(rel) in subdir' '
3502         cat >23/sub/sub/expected <<EOF &&
3503 setup: git_dir: $TRASH_DIRECTORY/23/.git
3504 setup: worktree: $TRASH_DIRECTORY/23
3505 setup: cwd: $TRASH_DIRECTORY/23
3506 setup: prefix: sub/sub/
3507 EOF
3508         test_repo 23/sub/sub ../../.git ../..
3509 '
3510
3511 test_expect_success '#23: GIT_DIR, GIT_WORKTREE=root in subdir' '
3512         cat >23/sub/expected <<EOF &&
3513 setup: git_dir: $TRASH_DIRECTORY/23/.git
3514 setup: worktree: $TRASH_DIRECTORY/23
3515 setup: cwd: $TRASH_DIRECTORY/23
3516 setup: prefix: sub/
3517 EOF
3518         test_repo 23/sub "$TRASH_DIRECTORY/23/.git" "$TRASH_DIRECTORY/23"
3519 '
3520
3521 test_expect_success '#23: GIT_DIR, GIT_WORKTREE=root(rel) in subdir' '
3522         cat >23/sub/sub/expected <<EOF &&
3523 setup: git_dir: $TRASH_DIRECTORY/23/.git
3524 setup: worktree: $TRASH_DIRECTORY/23
3525 setup: cwd: $TRASH_DIRECTORY/23
3526 setup: prefix: sub/sub/
3527 EOF
3528         test_repo 23/sub/sub "$TRASH_DIRECTORY/23/.git" ../..
3529 '
3530
3531 test_expect_success '#23: GIT_DIR(rel), GIT_WORK_TREE=wt at root' '
3532         cat >23/expected <<EOF &&
3533 setup: git_dir: .git
3534 setup: worktree: $TRASH_DIRECTORY/23/wt
3535 setup: cwd: $TRASH_DIRECTORY/23
3536 setup: prefix: (null)
3537 EOF
3538         test_repo 23 .git "$TRASH_DIRECTORY/23/wt"
3539 '
3540
3541 test_expect_success '#23: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) at root' '
3542         cat >23/expected <<EOF &&
3543 setup: git_dir: .git
3544 setup: worktree: $TRASH_DIRECTORY/23/wt
3545 setup: cwd: $TRASH_DIRECTORY/23
3546 setup: prefix: (null)
3547 EOF
3548         test_repo 23 .git wt
3549 '
3550
3551 test_expect_success '#23: GIT_DIR, GIT_WORK_TREE=wt(rel) at root' '
3552         cat >23/expected <<EOF &&
3553 setup: git_dir: $TRASH_DIRECTORY/23/.git
3554 setup: worktree: $TRASH_DIRECTORY/23/wt
3555 setup: cwd: $TRASH_DIRECTORY/23
3556 setup: prefix: (null)
3557 EOF
3558         test_repo 23 "$TRASH_DIRECTORY/23/.git" wt
3559 '
3560
3561 test_expect_success '#23: GIT_DIR, GIT_WORK_TREE=wt at root' '
3562         cat >23/expected <<EOF &&
3563 setup: git_dir: $TRASH_DIRECTORY/23/.git
3564 setup: worktree: $TRASH_DIRECTORY/23/wt
3565 setup: cwd: $TRASH_DIRECTORY/23
3566 setup: prefix: (null)
3567 EOF
3568         test_repo 23 "$TRASH_DIRECTORY/23/.git" "$TRASH_DIRECTORY/23/wt"
3569 '
3570
3571 test_expect_success '#23: GIT_DIR(rel), GIT_WORK_TREE=wt in subdir' '
3572         cat >23/sub/sub/expected <<EOF &&
3573 setup: git_dir: ../../.git
3574 setup: worktree: $TRASH_DIRECTORY/23/wt
3575 setup: cwd: $TRASH_DIRECTORY/23/sub/sub
3576 setup: prefix: (null)
3577 EOF
3578         test_repo 23/sub/sub ../../.git "$TRASH_DIRECTORY/23/wt"
3579 '
3580
3581 test_expect_success '#23: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) in subdir' '
3582         cat >23/sub/sub/expected <<EOF &&
3583 setup: git_dir: ../../.git
3584 setup: worktree: $TRASH_DIRECTORY/23/wt
3585 setup: cwd: $TRASH_DIRECTORY/23/sub/sub
3586 setup: prefix: (null)
3587 EOF
3588         test_repo 23/sub/sub ../../.git ../../wt
3589 '
3590
3591 test_expect_success '#23: GIT_DIR, GIT_WORK_TREE=wt(rel) in subdir' '
3592         cat >23/sub/sub/expected <<EOF &&
3593 setup: git_dir: $TRASH_DIRECTORY/23/.git
3594 setup: worktree: $TRASH_DIRECTORY/23/wt
3595 setup: cwd: $TRASH_DIRECTORY/23/sub/sub
3596 setup: prefix: (null)
3597 EOF
3598         test_repo 23/sub/sub "$TRASH_DIRECTORY/23/.git" ../../wt
3599 '
3600
3601 test_expect_success '#23: GIT_DIR, GIT_WORK_TREE=wt in subdir' '
3602         cat >23/sub/sub/expected <<EOF &&
3603 setup: git_dir: $TRASH_DIRECTORY/23/.git
3604 setup: worktree: $TRASH_DIRECTORY/23/wt
3605 setup: cwd: $TRASH_DIRECTORY/23/sub/sub
3606 setup: prefix: (null)
3607 EOF
3608         test_repo 23/sub/sub "$TRASH_DIRECTORY/23/.git" "$TRASH_DIRECTORY/23/wt"
3609 '
3610
3611 test_expect_success '#23: GIT_DIR(rel), GIT_WORK_TREE=.. at root' '
3612         cat >23/expected <<EOF &&
3613 setup: git_dir: $TRASH_DIRECTORY/23/.git
3614 setup: worktree: $TRASH_DIRECTORY
3615 setup: cwd: $TRASH_DIRECTORY
3616 setup: prefix: 23/
3617 EOF
3618         test_repo 23 .git "$TRASH_DIRECTORY"
3619 '
3620
3621 test_expect_success '#23: GIT_DIR(rel), GIT_WORK_TREE=..(rel) at root' '
3622         cat >23/expected <<EOF &&
3623 setup: git_dir: $TRASH_DIRECTORY/23/.git
3624 setup: worktree: $TRASH_DIRECTORY
3625 setup: cwd: $TRASH_DIRECTORY
3626 setup: prefix: 23/
3627 EOF
3628         test_repo 23 .git ..
3629 '
3630
3631 test_expect_success '#23: GIT_DIR, GIT_WORK_TREE=..(rel) at root' '
3632         cat >23/expected <<EOF &&
3633 setup: git_dir: $TRASH_DIRECTORY/23/.git
3634 setup: worktree: $TRASH_DIRECTORY
3635 setup: cwd: $TRASH_DIRECTORY
3636 setup: prefix: 23/
3637 EOF
3638         test_repo 23 "$TRASH_DIRECTORY/23/.git" ..
3639 '
3640
3641 test_expect_success '#23: GIT_DIR, GIT_WORK_TREE=.. at root' '
3642         cat >23/expected <<EOF &&
3643 setup: git_dir: $TRASH_DIRECTORY/23/.git
3644 setup: worktree: $TRASH_DIRECTORY
3645 setup: cwd: $TRASH_DIRECTORY
3646 setup: prefix: 23/
3647 EOF
3648         test_repo 23 "$TRASH_DIRECTORY/23/.git" "$TRASH_DIRECTORY"
3649 '
3650
3651 test_expect_success '#23: GIT_DIR(rel), GIT_WORK_TREE=.. in subdir' '
3652         cat >23/sub/sub/expected <<EOF &&
3653 setup: git_dir: $TRASH_DIRECTORY/23/.git
3654 setup: worktree: $TRASH_DIRECTORY
3655 setup: cwd: $TRASH_DIRECTORY
3656 setup: prefix: 23/sub/sub/
3657 EOF
3658         test_repo 23/sub/sub ../../.git "$TRASH_DIRECTORY"
3659 '
3660
3661 test_expect_success '#23: GIT_DIR(rel), GIT_WORK_TREE=..(rel) in subdir' '
3662         cat >23/sub/sub/expected <<EOF &&
3663 setup: git_dir: $TRASH_DIRECTORY/23/.git
3664 setup: worktree: $TRASH_DIRECTORY
3665 setup: cwd: $TRASH_DIRECTORY
3666 setup: prefix: 23/sub/sub/
3667 EOF
3668         test_repo 23/sub/sub ../../.git ../../..
3669 '
3670
3671 test_expect_success '#23: GIT_DIR, GIT_WORK_TREE=..(rel) in subdir' '
3672         cat >23/sub/sub/expected <<EOF &&
3673 setup: git_dir: $TRASH_DIRECTORY/23/.git
3674 setup: worktree: $TRASH_DIRECTORY
3675 setup: cwd: $TRASH_DIRECTORY
3676 setup: prefix: 23/sub/sub/
3677 EOF
3678         test_repo 23/sub/sub "$TRASH_DIRECTORY/23/.git" ../../../
3679 '
3680
3681 test_expect_success '#23: GIT_DIR, GIT_WORK_TREE=.. in subdir' '
3682         cat >23/sub/sub/expected <<EOF &&
3683 setup: git_dir: $TRASH_DIRECTORY/23/.git
3684 setup: worktree: $TRASH_DIRECTORY
3685 setup: cwd: $TRASH_DIRECTORY
3686 setup: prefix: 23/sub/sub/
3687 EOF
3688         test_repo 23/sub/sub "$TRASH_DIRECTORY/23/.git" "$TRASH_DIRECTORY"
3689 '
3690
3691 #
3692 # case #24
3693 #
3694 ############################################################
3695 #
3696 # Input:
3697 #
3698 #  - GIT_WORK_TREE is not set
3699 #  - GIT_DIR is not set
3700 #  - core.worktree is not set
3701 #  - .git is a file
3702 #  - core.bare is set
3703 #
3704 # Output:
3705 #
3706 # #16.2 except git_dir is set according to .git file
3707
3708 test_expect_success '#24: setup' '
3709         sane_unset GIT_DIR GIT_WORK_TREE &&
3710         mkdir 24 24/sub &&
3711         cd 24 &&
3712         git init &&
3713         git config core.bare true &&
3714         mv .git ../24.git &&
3715         echo gitdir: ../24.git >.git &&
3716         cd ..
3717 '
3718
3719 test_expect_success '#24: at root' '
3720         cat >24/expected <<EOF &&
3721 setup: git_dir: $TRASH_DIRECTORY/24.git
3722 setup: worktree: (null)
3723 setup: cwd: $TRASH_DIRECTORY/24
3724 setup: prefix: (null)
3725 EOF
3726         test_repo 24
3727 '
3728
3729 test_expect_success '#24: in subdir' '
3730         cat >24/sub/expected <<EOF &&
3731 setup: git_dir: $TRASH_DIRECTORY/24.git
3732 setup: worktree: (null)
3733 setup: cwd: $TRASH_DIRECTORY/24/sub
3734 setup: prefix: (null)
3735 EOF
3736         test_repo 24/sub
3737 '
3738
3739 #
3740 # case #25
3741 #
3742 ############################################################
3743 #
3744 # Input:
3745 #
3746 #  - GIT_WORK_TREE is set
3747 #  - GIT_DIR is not set
3748 #  - core.worktree is not set
3749 #  - .git is a file
3750 #  - core.bare is set
3751 #
3752 # Output:
3753 #
3754 # #17.2 except git_dir is set according to .git file
3755
3756 test_expect_success '#25: setup' '
3757         sane_unset GIT_DIR GIT_WORK_TREE &&
3758         mkdir 25 25/sub &&
3759         cd 25 &&
3760         git init &&
3761         git config core.bare true &&
3762         GIT_WORK_TREE=non-existent &&
3763         export GIT_WORK_TREE &&
3764         mv .git ../25.git &&
3765         echo gitdir: ../25.git >.git &&
3766         cd ..
3767 '
3768
3769 test_expect_success '#25: at root' '
3770         cat >25/expected <<EOF &&
3771 setup: git_dir: $TRASH_DIRECTORY/25.git
3772 setup: worktree: (null)
3773 setup: cwd: $TRASH_DIRECTORY/25
3774 setup: prefix: (null)
3775 EOF
3776         test_repo 25
3777 '
3778
3779 test_expect_success '#25: in subdir' '
3780         cat >25/sub/expected <<EOF &&
3781 setup: git_dir: $TRASH_DIRECTORY/25.git
3782 setup: worktree: (null)
3783 setup: cwd: $TRASH_DIRECTORY/25/sub
3784 setup: prefix: (null)
3785 EOF
3786         test_repo 25/sub
3787 '
3788
3789 #
3790 # case #26
3791 #
3792 ############################################################
3793 #
3794 # Input:
3795 #
3796 #  - GIT_WORK_TREE is not set
3797 #  - GIT_DIR is set
3798 #  - core.worktree is not set
3799 #  - .git is a file
3800 #  - core.bare is set
3801 #
3802 # Output:
3803 #
3804 # #18 except git_dir is set according to .git file
3805
3806 test_expect_success '#26: setup' '
3807         sane_unset GIT_DIR GIT_WORK_TREE &&
3808         mkdir 26 26/sub &&
3809         cd 26 &&
3810         git init &&
3811         git config core.bare true &&
3812         mv .git ../26.git &&
3813         echo gitdir: ../26.git >.git &&
3814         cd ..
3815 '
3816
3817 test_expect_success '#26: (rel) at root' '
3818         cat >26/expected <<EOF &&
3819 setup: git_dir: $TRASH_DIRECTORY/26.git
3820 setup: worktree: (null)
3821 setup: cwd: $TRASH_DIRECTORY/26
3822 setup: prefix: (null)
3823 EOF
3824          test_repo 26 .git
3825 '
3826
3827 test_expect_success '#26: at root' '
3828         cat >26/expected <<EOF &&
3829 setup: git_dir: $TRASH_DIRECTORY/26.git
3830 setup: worktree: (null)
3831 setup: cwd: $TRASH_DIRECTORY/26
3832 setup: prefix: (null)
3833 EOF
3834          test_repo 26 "$TRASH_DIRECTORY/26/.git"
3835 '
3836
3837 test_expect_success '#26: (rel) in subdir' '
3838         cat >26/sub/expected <<EOF &&
3839 setup: git_dir: $TRASH_DIRECTORY/26.git
3840 setup: worktree: (null)
3841 setup: cwd: $TRASH_DIRECTORY/26/sub
3842 setup: prefix: (null)
3843 EOF
3844         test_repo 26/sub ../.git
3845 '
3846
3847 test_expect_success '#26: in subdir' '
3848         cat >26/sub/expected <<EOF &&
3849 setup: git_dir: $TRASH_DIRECTORY/26.git
3850 setup: worktree: (null)
3851 setup: cwd: $TRASH_DIRECTORY/26/sub
3852 setup: prefix: (null)
3853 EOF
3854         test_repo 26/sub "$TRASH_DIRECTORY/26/.git"
3855 '
3856
3857 #
3858 # case #27
3859 #
3860 ############################################################
3861 #
3862 # Input:
3863 #
3864 #  - GIT_WORK_TREE is set
3865 #  - GIT_DIR is set
3866 #  - .git is a file
3867 #  - core.worktree is not set
3868 #  - core.bare is set
3869 #
3870 # Output:
3871 #
3872 # #19 except git_dir is set according to .git file
3873
3874 test_expect_success '#27: setup' '
3875         sane_unset GIT_DIR GIT_WORK_TREE &&
3876         mkdir 27 27/sub 27/sub/sub 27.wt 27.wt/sub 27/wt 27/wt/sub &&
3877         cd 27 &&
3878         git init &&
3879         git config core.bare true &&
3880         mv .git ../27.git &&
3881         echo gitdir: ../27.git >.git &&
3882         cd ..
3883 '
3884
3885 test_expect_success '#27: GIT_DIR(rel), GIT_WORK_TREE=root at root' '
3886         cat >27/expected <<EOF &&
3887 setup: git_dir: $TRASH_DIRECTORY/27.git
3888 setup: worktree: $TRASH_DIRECTORY/27
3889 setup: cwd: $TRASH_DIRECTORY/27
3890 setup: prefix: (null)
3891 EOF
3892         test_repo 27 .git "$TRASH_DIRECTORY/27"
3893 '
3894
3895 test_expect_success '#27: GIT_DIR(rel), GIT_WORK_TREE=root(rel) at root' '
3896         cat >27/expected <<EOF &&
3897 setup: git_dir: $TRASH_DIRECTORY/27.git
3898 setup: worktree: $TRASH_DIRECTORY/27
3899 setup: cwd: $TRASH_DIRECTORY/27
3900 setup: prefix: (null)
3901 EOF
3902         test_repo 27 .git .
3903 '
3904
3905 test_expect_success '#27: GIT_DIR, GIT_WORK_TREE=root at root' '
3906         cat >27/expected <<EOF &&
3907 setup: git_dir: $TRASH_DIRECTORY/27.git
3908 setup: worktree: $TRASH_DIRECTORY/27
3909 setup: cwd: $TRASH_DIRECTORY/27
3910 setup: prefix: (null)
3911 EOF
3912         test_repo 27 "$TRASH_DIRECTORY/27/.git" "$TRASH_DIRECTORY/27"
3913 '
3914
3915 test_expect_success '#27: GIT_DIR, GIT_WORK_TREE=root(rel) at root' '
3916         cat >27/expected <<EOF &&
3917 setup: git_dir: $TRASH_DIRECTORY/27.git
3918 setup: worktree: $TRASH_DIRECTORY/27
3919 setup: cwd: $TRASH_DIRECTORY/27
3920 setup: prefix: (null)
3921 EOF
3922         test_repo 27 "$TRASH_DIRECTORY/27/.git" .
3923 '
3924
3925 test_expect_success '#27: GIT_DIR(rel), GIT_WORKTREE=root in subdir' '
3926         cat >27/sub/sub/expected <<EOF &&
3927 setup: git_dir: $TRASH_DIRECTORY/27.git
3928 setup: worktree: $TRASH_DIRECTORY/27
3929 setup: cwd: $TRASH_DIRECTORY/27
3930 setup: prefix: sub/sub/
3931 EOF
3932         test_repo 27/sub/sub ../../.git "$TRASH_DIRECTORY/27"
3933 '
3934
3935 test_expect_success '#27: GIT_DIR(rel), GIT_WORKTREE=root(rel) in subdir' '
3936         cat >27/sub/sub/expected <<EOF &&
3937 setup: git_dir: $TRASH_DIRECTORY/27.git
3938 setup: worktree: $TRASH_DIRECTORY/27
3939 setup: cwd: $TRASH_DIRECTORY/27
3940 setup: prefix: sub/sub/
3941 EOF
3942         test_repo 27/sub/sub ../../.git ../..
3943 '
3944
3945 test_expect_success '#27: GIT_DIR, GIT_WORKTREE=root in subdir' '
3946         cat >27/sub/expected <<EOF &&
3947 setup: git_dir: $TRASH_DIRECTORY/27.git
3948 setup: worktree: $TRASH_DIRECTORY/27
3949 setup: cwd: $TRASH_DIRECTORY/27
3950 setup: prefix: sub/
3951 EOF
3952         test_repo 27/sub "$TRASH_DIRECTORY/27/.git" "$TRASH_DIRECTORY/27"
3953 '
3954
3955 test_expect_success '#27: GIT_DIR, GIT_WORKTREE=root(rel) in subdir' '
3956         cat >27/sub/sub/expected <<EOF &&
3957 setup: git_dir: $TRASH_DIRECTORY/27.git
3958 setup: worktree: $TRASH_DIRECTORY/27
3959 setup: cwd: $TRASH_DIRECTORY/27
3960 setup: prefix: sub/sub/
3961 EOF
3962         test_repo 27/sub/sub "$TRASH_DIRECTORY/27/.git" ../..
3963 '
3964
3965 test_expect_success '#27: GIT_DIR(rel), GIT_WORK_TREE=wt at root' '
3966         cat >27/expected <<EOF &&
3967 setup: git_dir: $TRASH_DIRECTORY/27.git
3968 setup: worktree: $TRASH_DIRECTORY/27/wt
3969 setup: cwd: $TRASH_DIRECTORY/27
3970 setup: prefix: (null)
3971 EOF
3972         test_repo 27 .git "$TRASH_DIRECTORY/27/wt"
3973 '
3974
3975 test_expect_success '#27: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) at root' '
3976         cat >27/expected <<EOF &&
3977 setup: git_dir: $TRASH_DIRECTORY/27.git
3978 setup: worktree: $TRASH_DIRECTORY/27/wt
3979 setup: cwd: $TRASH_DIRECTORY/27
3980 setup: prefix: (null)
3981 EOF
3982         test_repo 27 .git wt
3983 '
3984
3985 test_expect_success '#27: GIT_DIR, GIT_WORK_TREE=wt(rel) at root' '
3986         cat >27/expected <<EOF &&
3987 setup: git_dir: $TRASH_DIRECTORY/27.git
3988 setup: worktree: $TRASH_DIRECTORY/27/wt
3989 setup: cwd: $TRASH_DIRECTORY/27
3990 setup: prefix: (null)
3991 EOF
3992         test_repo 27 "$TRASH_DIRECTORY/27/.git" wt
3993 '
3994
3995 test_expect_success '#27: GIT_DIR, GIT_WORK_TREE=wt at root' '
3996         cat >27/expected <<EOF &&
3997 setup: git_dir: $TRASH_DIRECTORY/27.git
3998 setup: worktree: $TRASH_DIRECTORY/27/wt
3999 setup: cwd: $TRASH_DIRECTORY/27
4000 setup: prefix: (null)
4001 EOF
4002         test_repo 27 "$TRASH_DIRECTORY/27/.git" "$TRASH_DIRECTORY/27/wt"
4003 '
4004
4005 test_expect_success '#27: GIT_DIR(rel), GIT_WORK_TREE=wt in subdir' '
4006         cat >27/sub/sub/expected <<EOF &&
4007 setup: git_dir: $TRASH_DIRECTORY/27.git
4008 setup: worktree: $TRASH_DIRECTORY/27/wt
4009 setup: cwd: $TRASH_DIRECTORY/27/sub/sub
4010 setup: prefix: (null)
4011 EOF
4012         test_repo 27/sub/sub ../../.git "$TRASH_DIRECTORY/27/wt"
4013 '
4014
4015 test_expect_success '#27: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) in subdir' '
4016         cat >27/sub/sub/expected <<EOF &&
4017 setup: git_dir: $TRASH_DIRECTORY/27.git
4018 setup: worktree: $TRASH_DIRECTORY/27/wt
4019 setup: cwd: $TRASH_DIRECTORY/27/sub/sub
4020 setup: prefix: (null)
4021 EOF
4022         test_repo 27/sub/sub ../../.git ../../wt
4023 '
4024
4025 test_expect_success '#27: GIT_DIR, GIT_WORK_TREE=wt(rel) in subdir' '
4026         cat >27/sub/sub/expected <<EOF &&
4027 setup: git_dir: $TRASH_DIRECTORY/27.git
4028 setup: worktree: $TRASH_DIRECTORY/27/wt
4029 setup: cwd: $TRASH_DIRECTORY/27/sub/sub
4030 setup: prefix: (null)
4031 EOF
4032         test_repo 27/sub/sub "$TRASH_DIRECTORY/27/.git" ../../wt
4033 '
4034
4035 test_expect_success '#27: GIT_DIR, GIT_WORK_TREE=wt in subdir' '
4036         cat >27/sub/sub/expected <<EOF &&
4037 setup: git_dir: $TRASH_DIRECTORY/27.git
4038 setup: worktree: $TRASH_DIRECTORY/27/wt
4039 setup: cwd: $TRASH_DIRECTORY/27/sub/sub
4040 setup: prefix: (null)
4041 EOF
4042         test_repo 27/sub/sub "$TRASH_DIRECTORY/27/.git" "$TRASH_DIRECTORY/27/wt"
4043 '
4044
4045 test_expect_success '#27: GIT_DIR(rel), GIT_WORK_TREE=.. at root' '
4046         cat >27/expected <<EOF &&
4047 setup: git_dir: $TRASH_DIRECTORY/27.git
4048 setup: worktree: $TRASH_DIRECTORY
4049 setup: cwd: $TRASH_DIRECTORY
4050 setup: prefix: 27/
4051 EOF
4052         test_repo 27 .git "$TRASH_DIRECTORY"
4053 '
4054
4055 test_expect_success '#27: GIT_DIR(rel), GIT_WORK_TREE=..(rel) at root' '
4056         cat >27/expected <<EOF &&
4057 setup: git_dir: $TRASH_DIRECTORY/27.git
4058 setup: worktree: $TRASH_DIRECTORY
4059 setup: cwd: $TRASH_DIRECTORY
4060 setup: prefix: 27/
4061 EOF
4062         test_repo 27 .git ..
4063 '
4064
4065 test_expect_success '#27: GIT_DIR, GIT_WORK_TREE=..(rel) at root' '
4066         cat >27/expected <<EOF &&
4067 setup: git_dir: $TRASH_DIRECTORY/27.git
4068 setup: worktree: $TRASH_DIRECTORY
4069 setup: cwd: $TRASH_DIRECTORY
4070 setup: prefix: 27/
4071 EOF
4072         test_repo 27 "$TRASH_DIRECTORY/27/.git" ..
4073 '
4074
4075 test_expect_success '#27: GIT_DIR, GIT_WORK_TREE=.. at root' '
4076         cat >27/expected <<EOF &&
4077 setup: git_dir: $TRASH_DIRECTORY/27.git
4078 setup: worktree: $TRASH_DIRECTORY
4079 setup: cwd: $TRASH_DIRECTORY
4080 setup: prefix: 27/
4081 EOF
4082         test_repo 27 "$TRASH_DIRECTORY/27/.git" "$TRASH_DIRECTORY"
4083 '
4084
4085 test_expect_success '#27: GIT_DIR(rel), GIT_WORK_TREE=.. in subdir' '
4086         cat >27/sub/sub/expected <<EOF &&
4087 setup: git_dir: $TRASH_DIRECTORY/27.git
4088 setup: worktree: $TRASH_DIRECTORY
4089 setup: cwd: $TRASH_DIRECTORY
4090 setup: prefix: 27/sub/sub/
4091 EOF
4092         test_repo 27/sub/sub ../../.git "$TRASH_DIRECTORY"
4093 '
4094
4095 test_expect_success '#27: GIT_DIR(rel), GIT_WORK_TREE=..(rel) in subdir' '
4096         cat >27/sub/sub/expected <<EOF &&
4097 setup: git_dir: $TRASH_DIRECTORY/27.git
4098 setup: worktree: $TRASH_DIRECTORY
4099 setup: cwd: $TRASH_DIRECTORY
4100 setup: prefix: 27/sub/sub/
4101 EOF
4102         test_repo 27/sub/sub ../../.git ../../..
4103 '
4104
4105 test_expect_success '#27: GIT_DIR, GIT_WORK_TREE=..(rel) in subdir' '
4106         cat >27/sub/sub/expected <<EOF &&
4107 setup: git_dir: $TRASH_DIRECTORY/27.git
4108 setup: worktree: $TRASH_DIRECTORY
4109 setup: cwd: $TRASH_DIRECTORY
4110 setup: prefix: 27/sub/sub/
4111 EOF
4112         test_repo 27/sub/sub "$TRASH_DIRECTORY/27/.git" ../../../
4113 '
4114
4115 test_expect_success '#27: GIT_DIR, GIT_WORK_TREE=.. in subdir' '
4116         cat >27/sub/sub/expected <<EOF &&
4117 setup: git_dir: $TRASH_DIRECTORY/27.git
4118 setup: worktree: $TRASH_DIRECTORY
4119 setup: cwd: $TRASH_DIRECTORY
4120 setup: prefix: 27/sub/sub/
4121 EOF
4122         test_repo 27/sub/sub "$TRASH_DIRECTORY/27/.git" "$TRASH_DIRECTORY"
4123 '
4124
4125 #
4126 # case #28
4127 #
4128 ############################################################
4129 #
4130 # Input:
4131 #
4132 #  - GIT_WORK_TREE is not set
4133 #  - GIT_DIR is not set
4134 #  - core.worktree is set
4135 #  - .git is a file
4136 #  - core.bare is set
4137 #
4138 # Output:
4139 #
4140 # core.worktree is ignored -> #24
4141
4142 test_expect_success '#28: setup' '
4143         sane_unset GIT_DIR GIT_WORK_TREE &&
4144         mkdir 28 28/sub &&
4145         cd 28 &&
4146         git init &&
4147         git config core.bare true &&
4148         git config core.worktree non-existent &&
4149         mv .git ../28.git &&
4150         echo gitdir: ../28.git >.git &&
4151         cd ..
4152 '
4153
4154 test_expect_success '#28: at root' '
4155         cat >28/expected <<EOF &&
4156 setup: git_dir: $TRASH_DIRECTORY/28.git
4157 setup: worktree: (null)
4158 setup: cwd: $TRASH_DIRECTORY/28
4159 setup: prefix: (null)
4160 EOF
4161         test_repo 28
4162 '
4163
4164 test_expect_success '#28: in subdir' '
4165         cat >28/sub/expected <<EOF &&
4166 setup: git_dir: $TRASH_DIRECTORY/28.git
4167 setup: worktree: (null)
4168 setup: cwd: $TRASH_DIRECTORY/28/sub
4169 setup: prefix: (null)
4170 EOF
4171         test_repo 28/sub
4172 '
4173
4174 #
4175 # case #29
4176 #
4177 ############################################################
4178 #
4179 # Input:
4180 #
4181 #  - GIT_WORK_TREE is set
4182 #  - GIT_DIR is not set
4183 #  - core.worktree is set
4184 #  - .git is a file
4185 #  - core.bare is set
4186 #
4187 # Output:
4188 #
4189 # GIT_WORK_TREE/core.worktree are ignored -> #28
4190
4191 test_expect_success '#29: setup' '
4192         sane_unset GIT_DIR GIT_WORK_TREE &&
4193         mkdir 29 29/sub &&
4194         cd 29 &&
4195         git init &&
4196         git config core.bare true &&
4197         GIT_WORK_TREE=non-existent &&
4198         export GIT_WORK_TREE &&
4199         mv .git ../29.git &&
4200         echo gitdir: ../29.git >.git &&
4201         cd ..
4202 '
4203
4204 test_expect_success '#29: at root' '
4205         cat >29/expected <<EOF &&
4206 setup: git_dir: $TRASH_DIRECTORY/29.git
4207 setup: worktree: (null)
4208 setup: cwd: $TRASH_DIRECTORY/29
4209 setup: prefix: (null)
4210 EOF
4211         test_repo 29
4212 '
4213
4214 test_expect_success '#29: in subdir' '
4215         cat >29/sub/expected <<EOF &&
4216 setup: git_dir: $TRASH_DIRECTORY/29.git
4217 setup: worktree: (null)
4218 setup: cwd: $TRASH_DIRECTORY/29/sub
4219 setup: prefix: (null)
4220 EOF
4221         test_repo 29/sub
4222 '
4223
4224 #
4225 # case #30
4226 #
4227 ############################################################
4228 #
4229 # Input:
4230 #
4231 #  - GIT_WORK_TREE is not set
4232 #  - GIT_DIR is set
4233 #  - core.worktree is set
4234 #  - .git is a file
4235 #  - core.bare is set
4236 #
4237 # Output:
4238 #
4239 # core.worktree and core.bare conflict, won't fly.
4240
4241 test_expect_success '#30: setup' '
4242         sane_unset GIT_DIR GIT_WORK_TREE &&
4243         mkdir 30 &&
4244         cd 30 &&
4245         git init &&
4246         git config core.bare true &&
4247         git config core.worktree non-existent &&
4248         mv .git ../30.git &&
4249         echo gitdir: ../30.git >.git &&
4250         cd ..
4251 '
4252
4253 test_expect_success '#30: at root' '
4254         (
4255         cd 30 &&
4256         GIT_DIR=.git &&
4257         export GIT_DIR &&
4258         test_must_fail git symbolic-ref HEAD 2>result &&
4259         grep "core.bare and core.worktree do not make sense" result
4260         )
4261 '
4262
4263 #
4264 # case #31
4265 #
4266 ############################################################
4267 #
4268 # Input:
4269 #
4270 #  - GIT_WORK_TREE is set
4271 #  - GIT_DIR is set
4272 #  - core.worktree is set
4273 #  - .git is a file
4274 #  - core.bare is set
4275 #
4276 # Output:
4277 #
4278 # #23 except git_dir is set according to .git file
4279
4280 test_expect_success '#31: setup' '
4281         sane_unset GIT_DIR GIT_WORK_TREE &&
4282         mkdir 31 31/sub 31/sub/sub 31.wt 31.wt/sub 31/wt 31/wt/sub &&
4283         cd 31 &&
4284         git init &&
4285         git config core.bare true &&
4286         git config core.worktree non-existent &&
4287         mv .git ../31.git &&
4288         echo gitdir: ../31.git >.git &&
4289         cd ..
4290 '
4291
4292 test_expect_success '#31: GIT_DIR(rel), GIT_WORK_TREE=root at root' '
4293         cat >31/expected <<EOF &&
4294 setup: git_dir: $TRASH_DIRECTORY/31.git
4295 setup: worktree: $TRASH_DIRECTORY/31
4296 setup: cwd: $TRASH_DIRECTORY/31
4297 setup: prefix: (null)
4298 EOF
4299         test_repo 31 .git "$TRASH_DIRECTORY/31"
4300 '
4301
4302 test_expect_success '#31: GIT_DIR(rel), GIT_WORK_TREE=root(rel) at root' '
4303         cat >31/expected <<EOF &&
4304 setup: git_dir: $TRASH_DIRECTORY/31.git
4305 setup: worktree: $TRASH_DIRECTORY/31
4306 setup: cwd: $TRASH_DIRECTORY/31
4307 setup: prefix: (null)
4308 EOF
4309         test_repo 31 .git .
4310 '
4311
4312 test_expect_success '#31: GIT_DIR, GIT_WORK_TREE=root at root' '
4313         cat >31/expected <<EOF &&
4314 setup: git_dir: $TRASH_DIRECTORY/31.git
4315 setup: worktree: $TRASH_DIRECTORY/31
4316 setup: cwd: $TRASH_DIRECTORY/31
4317 setup: prefix: (null)
4318 EOF
4319         test_repo 31 "$TRASH_DIRECTORY/31/.git" "$TRASH_DIRECTORY/31"
4320 '
4321
4322 test_expect_success '#31: GIT_DIR, GIT_WORK_TREE=root(rel) at root' '
4323         cat >31/expected <<EOF &&
4324 setup: git_dir: $TRASH_DIRECTORY/31.git
4325 setup: worktree: $TRASH_DIRECTORY/31
4326 setup: cwd: $TRASH_DIRECTORY/31
4327 setup: prefix: (null)
4328 EOF
4329         test_repo 31 "$TRASH_DIRECTORY/31/.git" .
4330 '
4331
4332 test_expect_success '#31: GIT_DIR(rel), GIT_WORKTREE=root in subdir' '
4333         cat >31/sub/sub/expected <<EOF &&
4334 setup: git_dir: $TRASH_DIRECTORY/31.git
4335 setup: worktree: $TRASH_DIRECTORY/31
4336 setup: cwd: $TRASH_DIRECTORY/31
4337 setup: prefix: sub/sub/
4338 EOF
4339         test_repo 31/sub/sub ../../.git "$TRASH_DIRECTORY/31"
4340 '
4341
4342 test_expect_success '#31: GIT_DIR(rel), GIT_WORKTREE=root(rel) in subdir' '
4343         cat >31/sub/sub/expected <<EOF &&
4344 setup: git_dir: $TRASH_DIRECTORY/31.git
4345 setup: worktree: $TRASH_DIRECTORY/31
4346 setup: cwd: $TRASH_DIRECTORY/31
4347 setup: prefix: sub/sub/
4348 EOF
4349         test_repo 31/sub/sub ../../.git ../..
4350 '
4351
4352 test_expect_success '#31: GIT_DIR, GIT_WORKTREE=root in subdir' '
4353         cat >31/sub/expected <<EOF &&
4354 setup: git_dir: $TRASH_DIRECTORY/31.git
4355 setup: worktree: $TRASH_DIRECTORY/31
4356 setup: cwd: $TRASH_DIRECTORY/31
4357 setup: prefix: sub/
4358 EOF
4359         test_repo 31/sub "$TRASH_DIRECTORY/31/.git" "$TRASH_DIRECTORY/31"
4360 '
4361
4362 test_expect_success '#31: GIT_DIR, GIT_WORKTREE=root(rel) in subdir' '
4363         cat >31/sub/sub/expected <<EOF &&
4364 setup: git_dir: $TRASH_DIRECTORY/31.git
4365 setup: worktree: $TRASH_DIRECTORY/31
4366 setup: cwd: $TRASH_DIRECTORY/31
4367 setup: prefix: sub/sub/
4368 EOF
4369         test_repo 31/sub/sub "$TRASH_DIRECTORY/31/.git" ../..
4370 '
4371
4372 test_expect_success '#31: GIT_DIR(rel), GIT_WORK_TREE=wt at root' '
4373         cat >31/expected <<EOF &&
4374 setup: git_dir: $TRASH_DIRECTORY/31.git
4375 setup: worktree: $TRASH_DIRECTORY/31/wt
4376 setup: cwd: $TRASH_DIRECTORY/31
4377 setup: prefix: (null)
4378 EOF
4379         test_repo 31 .git "$TRASH_DIRECTORY/31/wt"
4380 '
4381
4382 test_expect_success '#31: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) at root' '
4383         cat >31/expected <<EOF &&
4384 setup: git_dir: $TRASH_DIRECTORY/31.git
4385 setup: worktree: $TRASH_DIRECTORY/31/wt
4386 setup: cwd: $TRASH_DIRECTORY/31
4387 setup: prefix: (null)
4388 EOF
4389         test_repo 31 .git wt
4390 '
4391
4392 test_expect_success '#31: GIT_DIR, GIT_WORK_TREE=wt(rel) at root' '
4393         cat >31/expected <<EOF &&
4394 setup: git_dir: $TRASH_DIRECTORY/31.git
4395 setup: worktree: $TRASH_DIRECTORY/31/wt
4396 setup: cwd: $TRASH_DIRECTORY/31
4397 setup: prefix: (null)
4398 EOF
4399         test_repo 31 "$TRASH_DIRECTORY/31/.git" wt
4400 '
4401
4402 test_expect_success '#31: GIT_DIR, GIT_WORK_TREE=wt at root' '
4403         cat >31/expected <<EOF &&
4404 setup: git_dir: $TRASH_DIRECTORY/31.git
4405 setup: worktree: $TRASH_DIRECTORY/31/wt
4406 setup: cwd: $TRASH_DIRECTORY/31
4407 setup: prefix: (null)
4408 EOF
4409         test_repo 31 "$TRASH_DIRECTORY/31/.git" "$TRASH_DIRECTORY/31/wt"
4410 '
4411
4412 test_expect_success '#31: GIT_DIR(rel), GIT_WORK_TREE=wt in subdir' '
4413         cat >31/sub/sub/expected <<EOF &&
4414 setup: git_dir: $TRASH_DIRECTORY/31.git
4415 setup: worktree: $TRASH_DIRECTORY/31/wt
4416 setup: cwd: $TRASH_DIRECTORY/31/sub/sub
4417 setup: prefix: (null)
4418 EOF
4419         test_repo 31/sub/sub ../../.git "$TRASH_DIRECTORY/31/wt"
4420 '
4421
4422 test_expect_success '#31: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) in subdir' '
4423         cat >31/sub/sub/expected <<EOF &&
4424 setup: git_dir: $TRASH_DIRECTORY/31.git
4425 setup: worktree: $TRASH_DIRECTORY/31/wt
4426 setup: cwd: $TRASH_DIRECTORY/31/sub/sub
4427 setup: prefix: (null)
4428 EOF
4429         test_repo 31/sub/sub ../../.git ../../wt
4430 '
4431
4432 test_expect_success '#31: GIT_DIR, GIT_WORK_TREE=wt(rel) in subdir' '
4433         cat >31/sub/sub/expected <<EOF &&
4434 setup: git_dir: $TRASH_DIRECTORY/31.git
4435 setup: worktree: $TRASH_DIRECTORY/31/wt
4436 setup: cwd: $TRASH_DIRECTORY/31/sub/sub
4437 setup: prefix: (null)
4438 EOF
4439         test_repo 31/sub/sub "$TRASH_DIRECTORY/31/.git" ../../wt
4440 '
4441
4442 test_expect_success '#31: GIT_DIR, GIT_WORK_TREE=wt in subdir' '
4443         cat >31/sub/sub/expected <<EOF &&
4444 setup: git_dir: $TRASH_DIRECTORY/31.git
4445 setup: worktree: $TRASH_DIRECTORY/31/wt
4446 setup: cwd: $TRASH_DIRECTORY/31/sub/sub
4447 setup: prefix: (null)
4448 EOF
4449         test_repo 31/sub/sub "$TRASH_DIRECTORY/31/.git" "$TRASH_DIRECTORY/31/wt"
4450 '
4451
4452 test_expect_success '#31: GIT_DIR(rel), GIT_WORK_TREE=.. at root' '
4453         cat >31/expected <<EOF &&
4454 setup: git_dir: $TRASH_DIRECTORY/31.git
4455 setup: worktree: $TRASH_DIRECTORY
4456 setup: cwd: $TRASH_DIRECTORY
4457 setup: prefix: 31/
4458 EOF
4459         test_repo 31 .git "$TRASH_DIRECTORY"
4460 '
4461
4462 test_expect_success '#31: GIT_DIR(rel), GIT_WORK_TREE=..(rel) at root' '
4463         cat >31/expected <<EOF &&
4464 setup: git_dir: $TRASH_DIRECTORY/31.git
4465 setup: worktree: $TRASH_DIRECTORY
4466 setup: cwd: $TRASH_DIRECTORY
4467 setup: prefix: 31/
4468 EOF
4469         test_repo 31 .git ..
4470 '
4471
4472 test_expect_success '#31: GIT_DIR, GIT_WORK_TREE=..(rel) at root' '
4473         cat >31/expected <<EOF &&
4474 setup: git_dir: $TRASH_DIRECTORY/31.git
4475 setup: worktree: $TRASH_DIRECTORY
4476 setup: cwd: $TRASH_DIRECTORY
4477 setup: prefix: 31/
4478 EOF
4479         test_repo 31 "$TRASH_DIRECTORY/31/.git" ..
4480 '
4481
4482 test_expect_success '#31: GIT_DIR, GIT_WORK_TREE=.. at root' '
4483         cat >31/expected <<EOF &&
4484 setup: git_dir: $TRASH_DIRECTORY/31.git
4485 setup: worktree: $TRASH_DIRECTORY
4486 setup: cwd: $TRASH_DIRECTORY
4487 setup: prefix: 31/
4488 EOF
4489         test_repo 31 "$TRASH_DIRECTORY/31/.git" "$TRASH_DIRECTORY"
4490 '
4491
4492 test_expect_success '#31: GIT_DIR(rel), GIT_WORK_TREE=.. in subdir' '
4493         cat >31/sub/sub/expected <<EOF &&
4494 setup: git_dir: $TRASH_DIRECTORY/31.git
4495 setup: worktree: $TRASH_DIRECTORY
4496 setup: cwd: $TRASH_DIRECTORY
4497 setup: prefix: 31/sub/sub/
4498 EOF
4499         test_repo 31/sub/sub ../../.git "$TRASH_DIRECTORY"
4500 '
4501
4502 test_expect_success '#31: GIT_DIR(rel), GIT_WORK_TREE=..(rel) in subdir' '
4503         cat >31/sub/sub/expected <<EOF &&
4504 setup: git_dir: $TRASH_DIRECTORY/31.git
4505 setup: worktree: $TRASH_DIRECTORY
4506 setup: cwd: $TRASH_DIRECTORY
4507 setup: prefix: 31/sub/sub/
4508 EOF
4509         test_repo 31/sub/sub ../../.git ../../..
4510 '
4511
4512 test_expect_success '#31: GIT_DIR, GIT_WORK_TREE=..(rel) in subdir' '
4513         cat >31/sub/sub/expected <<EOF &&
4514 setup: git_dir: $TRASH_DIRECTORY/31.git
4515 setup: worktree: $TRASH_DIRECTORY
4516 setup: cwd: $TRASH_DIRECTORY
4517 setup: prefix: 31/sub/sub/
4518 EOF
4519         test_repo 31/sub/sub "$TRASH_DIRECTORY/31/.git" ../../../
4520 '
4521
4522 test_expect_success '#31: GIT_DIR, GIT_WORK_TREE=.. in subdir' '
4523         cat >31/sub/sub/expected <<EOF &&
4524 setup: git_dir: $TRASH_DIRECTORY/31.git
4525 setup: worktree: $TRASH_DIRECTORY
4526 setup: cwd: $TRASH_DIRECTORY
4527 setup: prefix: 31/sub/sub/
4528 EOF
4529         test_repo 31/sub/sub "$TRASH_DIRECTORY/31/.git" "$TRASH_DIRECTORY"
4530 '
4531
4532 test_done