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