1 #!/bin/sh
3 test_description='Tests of cwd/prefix/worktree/gitdir setup in all cases'
5 . ./test-lib.sh
7 #
8 # A few rules for repo setup:
9 #
10 # 1. GIT_DIR is relative to user's cwd. --git-dir is equivalent to
11 # GIT_DIR.
12 #
13 # 2. .git file is relative to parent directory. .git file is basically
14 # symlink in disguise. The directory where .git file points to will
15 # become new git_dir.
16 #
17 # 3. core.worktree is relative to git_dir.
18 #
19 # 4. GIT_WORK_TREE is relative to user's cwd. --work-tree is
20 # equivalent to GIT_WORK_TREE.
21 #
22 # 5. GIT_WORK_TREE/core.worktree is only effective if GIT_DIR is set
23 # Uneffective worktree settings should be warned.
24 #
25 # 6. Effective GIT_WORK_TREE overrides core.worktree and core.bare
26 #
27 # 7. Effective core.worktree conflicts with core.bare
28 #
29 # 8. If GIT_DIR is set but neither worktree nor bare setting is given,
30 # original cwd becomes worktree.
31 #
32 # 9. If .git discovery is done inside a repo, the repo becomes a bare
33 # repo. .git discovery is performed if GIT_DIR is not set.
34 #
35 # 10. If no worktree is available, cwd remains unchanged, prefix is
36 # NULL.
37 #
38 # 11. When user's cwd is outside worktree, cwd remains unchanged,
39 # prefix is NULL.
40 #
42 test_repo() {
43 (
44 cd "$1" &&
45 if test -n "$2"; then GIT_DIR="$2" && export GIT_DIR; fi &&
46 if test -n "$3"; then GIT_WORK_TREE="$3" && export GIT_WORK_TREE; fi &&
47 rm -f trace &&
48 GIT_TRACE="`pwd`/trace" git symbolic-ref HEAD >/dev/null &&
49 grep '^setup: ' trace >result &&
50 test_cmp expected result
51 )
52 }
54 # Bit 0 = GIT_WORK_TREE
55 # Bit 1 = GIT_DIR
56 # Bit 2 = core.worktree
57 # Bit 3 = .git is a file
58 # Bit 4 = bare repo
59 # Case# = encoding of the above 5 bits
61 #
62 # Case #0
63 #
64 ############################################################
65 #
66 # Input:
67 #
68 # - GIT_WORK_TREE is not set
69 # - GIT_DIR is not set
70 # - core.worktree is not set
71 # - .git is a directory
72 # - core.bare is not set, cwd is outside .git
73 #
74 # Output:
75 #
76 # - worktree is .git's parent directory
77 # - cwd is at worktree root dir
78 # - prefix is calculated
79 # - git_dir is set to ".git"
80 # - cwd can't be outside worktree
82 test_expect_success '#0: setup' '
83 unset GIT_DIR GIT_WORK_TREE &&
84 mkdir 0 0/sub &&
85 cd 0 && git init && cd ..
86 '
88 test_expect_success '#0: at root' '
89 cat >0/expected <<EOF &&
90 setup: git_dir: .git
91 setup: worktree: $TRASH_DIRECTORY/0
92 setup: cwd: $TRASH_DIRECTORY/0
93 setup: prefix: (null)
94 EOF
95 test_repo 0
96 '
98 test_expect_success '#0: in subdir' '
99 cat >0/sub/expected <<EOF &&
100 setup: git_dir: .git
101 setup: worktree: $TRASH_DIRECTORY/0
102 setup: cwd: $TRASH_DIRECTORY/0
103 setup: prefix: sub/
104 EOF
105 test_repo 0/sub
106 '
108 #
109 # case #1
110 #
111 ############################################################
112 #
113 # Input:
114 #
115 # - GIT_WORK_TREE is set
116 # - GIT_DIR is not set
117 # - core.worktree is not set
118 # - .git is a directory
119 # - core.bare is not set, cwd is outside .git
120 #
121 # Output:
122 #
123 # GIT_WORK_TREE is ignored -> #0
125 test_expect_success '#1: setup' '
126 unset GIT_DIR GIT_WORK_TREE &&
127 mkdir 1 1/sub 1.wt 1.wt/sub 1/wt 1/wt/sub &&
128 cd 1 &&
129 git init &&
130 GIT_WORK_TREE=non-existent &&
131 export GIT_WORK_TREE &&
132 cd ..
133 '
135 test_expect_failure '#1: at root' '
136 cat >1/expected <<EOF &&
137 setup: git_dir: .git
138 setup: worktree: $TRASH_DIRECTORY/1
139 setup: cwd: $TRASH_DIRECTORY/1
140 setup: prefix: (null)
141 EOF
142 test_repo 1
143 '
145 test_expect_failure '#1: in subdir' '
146 cat >1/sub/expected <<EOF &&
147 setup: git_dir: .git
148 setup: worktree: $TRASH_DIRECTORY/1
149 setup: cwd: $TRASH_DIRECTORY/1
150 setup: prefix: sub/
151 EOF
152 test_repo 1/sub
153 '
155 #
156 # case #2
157 #
158 ############################################################
159 #
160 # Input:
161 #
162 # - GIT_WORK_TREE is not set
163 # - GIT_DIR is set
164 # - core.worktree is not set
165 # - .git is a directory
166 # - core.bare is not set, cwd is outside .git
167 #
168 # Output:
169 #
170 # - worktree is at original cwd
171 # - cwd is unchanged
172 # - prefix is NULL
173 # - git_dir is set to $GIT_DIR
174 # - cwd can't be outside worktree
176 test_expect_success '#2: setup' '
177 unset GIT_DIR GIT_WORK_TREE &&
178 mkdir 2 2/sub &&
179 cd 2 && git init && cd ..
180 '
182 test_expect_success '#2: at root' '
183 cat >2/expected <<EOF &&
184 setup: git_dir: $TRASH_DIRECTORY/2/.git
185 setup: worktree: $TRASH_DIRECTORY/2
186 setup: cwd: $TRASH_DIRECTORY/2
187 setup: prefix: (null)
188 EOF
189 test_repo 2 "$TRASH_DIRECTORY/2/.git"
190 '
192 test_expect_success '#2: in subdir' '
193 cat >2/sub/expected <<EOF &&
194 setup: git_dir: $TRASH_DIRECTORY/2/.git
195 setup: worktree: $TRASH_DIRECTORY/2/sub
196 setup: cwd: $TRASH_DIRECTORY/2/sub
197 setup: prefix: (null)
198 EOF
199 test_repo 2/sub "$TRASH_DIRECTORY/2/.git"
200 '
202 test_expect_success '#2: relative GIT_DIR at root' '
203 cat >2/expected <<EOF &&
204 setup: git_dir: .git
205 setup: worktree: $TRASH_DIRECTORY/2
206 setup: cwd: $TRASH_DIRECTORY/2
207 setup: prefix: (null)
208 EOF
209 test_repo 2 .git
210 '
212 test_expect_success '#2: relative GIT_DIR in subdir' '
213 cat >2/sub/expected <<EOF &&
214 setup: git_dir: ../.git
215 setup: worktree: $TRASH_DIRECTORY/2/sub
216 setup: cwd: $TRASH_DIRECTORY/2/sub
217 setup: prefix: (null)
218 EOF
219 test_repo 2/sub ../.git
220 '
222 #
223 # case #3
224 #
225 ############################################################
226 #
227 # Input:
228 #
229 # - GIT_WORK_TREE is set
230 # - GIT_DIR is set
231 # - core.worktree is not set
232 # - .git is a directory
233 # - core.bare is not set, cwd is outside .git
234 #
235 # Output:
236 #
237 # - worktree is set to $GIT_WORK_TREE
238 # - cwd is at worktree root
239 # - prefix is calculated
240 # - git_dir is set to $GIT_DIR
241 # - cwd can be outside worktree
243 test_expect_success '#3: setup' '
244 unset GIT_DIR GIT_WORK_TREE &&
245 mkdir 3 3/sub 3/sub/sub 3.wt 3.wt/sub 3/wt 3/wt/sub &&
246 cd 3 && git init && cd ..
247 '
249 test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=root at root' '
250 cat >3/expected <<EOF &&
251 setup: git_dir: .git
252 setup: worktree: $TRASH_DIRECTORY/3
253 setup: cwd: $TRASH_DIRECTORY/3
254 setup: prefix: (null)
255 EOF
256 test_repo 3 .git "$TRASH_DIRECTORY/3"
257 '
259 test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=root(rel) at root' '
260 cat >3/expected <<EOF &&
261 setup: git_dir: .git
262 setup: worktree: $TRASH_DIRECTORY/3
263 setup: cwd: $TRASH_DIRECTORY/3
264 setup: prefix: (null)
265 EOF
266 test_repo 3 .git .
267 '
269 test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=root at root' '
270 cat >3/expected <<EOF &&
271 setup: git_dir: $TRASH_DIRECTORY/3/.git
272 setup: worktree: $TRASH_DIRECTORY/3
273 setup: cwd: $TRASH_DIRECTORY/3
274 setup: prefix: (null)
275 EOF
276 test_repo 3 "$TRASH_DIRECTORY/3/.git" "$TRASH_DIRECTORY/3"
277 '
279 test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=root(rel) at root' '
280 cat >3/expected <<EOF &&
281 setup: git_dir: $TRASH_DIRECTORY/3/.git
282 setup: worktree: $TRASH_DIRECTORY/3
283 setup: cwd: $TRASH_DIRECTORY/3
284 setup: prefix: (null)
285 EOF
286 test_repo 3 "$TRASH_DIRECTORY/3/.git" .
287 '
289 test_expect_success '#3: GIT_DIR(rel), GIT_WORKTREE=root in subdir' '
290 cat >3/sub/sub/expected <<EOF &&
291 setup: git_dir: $TRASH_DIRECTORY/3/.git
292 setup: worktree: $TRASH_DIRECTORY/3
293 setup: cwd: $TRASH_DIRECTORY/3
294 setup: prefix: sub/sub/
295 EOF
296 test_repo 3/sub/sub ../../.git "$TRASH_DIRECTORY/3"
297 '
299 test_expect_success '#3: GIT_DIR(rel), GIT_WORKTREE=root(rel) in subdir' '
300 cat >3/sub/sub/expected <<EOF &&
301 setup: git_dir: $TRASH_DIRECTORY/3/.git
302 setup: worktree: $TRASH_DIRECTORY/3
303 setup: cwd: $TRASH_DIRECTORY/3
304 setup: prefix: sub/sub/
305 EOF
306 test_repo 3/sub/sub ../../.git ../..
307 '
309 test_expect_success '#3: GIT_DIR, GIT_WORKTREE=root in subdir' '
310 cat >3/sub/expected <<EOF &&
311 setup: git_dir: $TRASH_DIRECTORY/3/.git
312 setup: worktree: $TRASH_DIRECTORY/3
313 setup: cwd: $TRASH_DIRECTORY/3
314 setup: prefix: sub/
315 EOF
316 test_repo 3/sub "$TRASH_DIRECTORY/3/.git" "$TRASH_DIRECTORY/3"
317 '
319 test_expect_success '#3: GIT_DIR, GIT_WORKTREE=root(rel) in subdir' '
320 cat >3/sub/sub/expected <<EOF &&
321 setup: git_dir: $TRASH_DIRECTORY/3/.git
322 setup: worktree: $TRASH_DIRECTORY/3
323 setup: cwd: $TRASH_DIRECTORY/3
324 setup: prefix: sub/sub/
325 EOF
326 test_repo 3/sub/sub "$TRASH_DIRECTORY/3/.git" ../..
327 '
329 test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=wt at root' '
330 cat >3/expected <<EOF &&
331 setup: git_dir: .git
332 setup: worktree: $TRASH_DIRECTORY/3/wt
333 setup: cwd: $TRASH_DIRECTORY/3
334 setup: prefix: (null)
335 EOF
336 test_repo 3 .git "$TRASH_DIRECTORY/3/wt"
337 '
339 test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) at root' '
340 cat >3/expected <<EOF &&
341 setup: git_dir: .git
342 setup: worktree: $TRASH_DIRECTORY/3/wt
343 setup: cwd: $TRASH_DIRECTORY/3
344 setup: prefix: (null)
345 EOF
346 test_repo 3 .git wt
347 '
349 test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=wt(rel) at root' '
350 cat >3/expected <<EOF &&
351 setup: git_dir: $TRASH_DIRECTORY/3/.git
352 setup: worktree: $TRASH_DIRECTORY/3/wt
353 setup: cwd: $TRASH_DIRECTORY/3
354 setup: prefix: (null)
355 EOF
356 test_repo 3 "$TRASH_DIRECTORY/3/.git" wt
357 '
359 test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=wt at root' '
360 cat >3/expected <<EOF &&
361 setup: git_dir: $TRASH_DIRECTORY/3/.git
362 setup: worktree: $TRASH_DIRECTORY/3/wt
363 setup: cwd: $TRASH_DIRECTORY/3
364 setup: prefix: (null)
365 EOF
366 test_repo 3 "$TRASH_DIRECTORY/3/.git" "$TRASH_DIRECTORY/3/wt"
367 '
369 test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=wt in subdir' '
370 cat >3/sub/sub/expected <<EOF &&
371 setup: git_dir: ../../.git
372 setup: worktree: $TRASH_DIRECTORY/3/wt
373 setup: cwd: $TRASH_DIRECTORY/3/sub/sub
374 setup: prefix: (null)
375 EOF
376 test_repo 3/sub/sub ../../.git "$TRASH_DIRECTORY/3/wt"
377 '
379 test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=wt(rel) in subdir' '
380 cat >3/sub/sub/expected <<EOF &&
381 setup: git_dir: ../../.git
382 setup: worktree: $TRASH_DIRECTORY/3/wt
383 setup: cwd: $TRASH_DIRECTORY/3/sub/sub
384 setup: prefix: (null)
385 EOF
386 test_repo 3/sub/sub ../../.git ../../wt
387 '
389 test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=wt(rel) in subdir' '
390 cat >3/sub/sub/expected <<EOF &&
391 setup: git_dir: $TRASH_DIRECTORY/3/.git
392 setup: worktree: $TRASH_DIRECTORY/3/wt
393 setup: cwd: $TRASH_DIRECTORY/3/sub/sub
394 setup: prefix: (null)
395 EOF
396 test_repo 3/sub/sub "$TRASH_DIRECTORY/3/.git" ../../wt
397 '
399 test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=wt in subdir' '
400 cat >3/sub/sub/expected <<EOF &&
401 setup: git_dir: $TRASH_DIRECTORY/3/.git
402 setup: worktree: $TRASH_DIRECTORY/3/wt
403 setup: cwd: $TRASH_DIRECTORY/3/sub/sub
404 setup: prefix: (null)
405 EOF
406 test_repo 3/sub/sub "$TRASH_DIRECTORY/3/.git" "$TRASH_DIRECTORY/3/wt"
407 '
409 test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=.. at root' '
410 cat >3/expected <<EOF &&
411 setup: git_dir: $TRASH_DIRECTORY/3/.git
412 setup: worktree: $TRASH_DIRECTORY
413 setup: cwd: $TRASH_DIRECTORY
414 setup: prefix: 3/
415 EOF
416 test_repo 3 .git "$TRASH_DIRECTORY"
417 '
419 test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=..(rel) at root' '
420 cat >3/expected <<EOF &&
421 setup: git_dir: $TRASH_DIRECTORY/3/.git
422 setup: worktree: $TRASH_DIRECTORY
423 setup: cwd: $TRASH_DIRECTORY
424 setup: prefix: 3/
425 EOF
426 test_repo 3 .git ..
427 '
429 test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=..(rel) at root' '
430 cat >3/expected <<EOF &&
431 setup: git_dir: $TRASH_DIRECTORY/3/.git
432 setup: worktree: $TRASH_DIRECTORY
433 setup: cwd: $TRASH_DIRECTORY
434 setup: prefix: 3/
435 EOF
436 test_repo 3 "$TRASH_DIRECTORY/3/.git" ..
437 '
439 test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=.. at root' '
440 cat >3/expected <<EOF &&
441 setup: git_dir: $TRASH_DIRECTORY/3/.git
442 setup: worktree: $TRASH_DIRECTORY
443 setup: cwd: $TRASH_DIRECTORY
444 setup: prefix: 3/
445 EOF
446 test_repo 3 "$TRASH_DIRECTORY/3/.git" "$TRASH_DIRECTORY"
447 '
449 test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=.. in subdir' '
450 cat >3/sub/sub/expected <<EOF &&
451 setup: git_dir: $TRASH_DIRECTORY/3/.git
452 setup: worktree: $TRASH_DIRECTORY
453 setup: cwd: $TRASH_DIRECTORY
454 setup: prefix: 3/sub/sub/
455 EOF
456 test_repo 3/sub/sub ../../.git "$TRASH_DIRECTORY"
457 '
459 test_expect_success '#3: GIT_DIR(rel), GIT_WORK_TREE=..(rel) in subdir' '
460 cat >3/sub/sub/expected <<EOF &&
461 setup: git_dir: $TRASH_DIRECTORY/3/.git
462 setup: worktree: $TRASH_DIRECTORY
463 setup: cwd: $TRASH_DIRECTORY
464 setup: prefix: 3/sub/sub/
465 EOF
466 test_repo 3/sub/sub ../../.git ../../..
467 '
469 test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=..(rel) in subdir' '
470 cat >3/sub/sub/expected <<EOF &&
471 setup: git_dir: $TRASH_DIRECTORY/3/.git
472 setup: worktree: $TRASH_DIRECTORY
473 setup: cwd: $TRASH_DIRECTORY
474 setup: prefix: 3/sub/sub/
475 EOF
476 test_repo 3/sub/sub "$TRASH_DIRECTORY/3/.git" ../../../
477 '
479 test_expect_success '#3: GIT_DIR, GIT_WORK_TREE=.. in subdir' '
480 cat >3/sub/sub/expected <<EOF &&
481 setup: git_dir: $TRASH_DIRECTORY/3/.git
482 setup: worktree: $TRASH_DIRECTORY
483 setup: cwd: $TRASH_DIRECTORY
484 setup: prefix: 3/sub/sub/
485 EOF
486 test_repo 3/sub/sub "$TRASH_DIRECTORY/3/.git" "$TRASH_DIRECTORY"
487 '
489 #
490 # case #4
491 #
492 ############################################################
493 #
494 # Input:
495 #
496 # - GIT_WORK_TREE is not set
497 # - GIT_DIR is not set
498 # - core.worktree is set
499 # - .git is a directory
500 # - core.bare is not set, cwd is outside .git
501 #
502 # Output:
503 #
504 # core.worktree is ignored -> #0
506 test_expect_success '#4: setup' '
507 unset GIT_DIR GIT_WORK_TREE &&
508 mkdir 4 4/sub &&
509 cd 4 &&
510 git init &&
511 git config core.worktree non-existent &&
512 cd ..
513 '
515 test_expect_failure '#4: at root' '
516 cat >4/expected <<EOF &&
517 setup: git_dir: .git
518 setup: worktree: $TRASH_DIRECTORY/4
519 setup: cwd: $TRASH_DIRECTORY/4
520 setup: prefix: (null)
521 EOF
522 test_repo 4
523 '
525 test_expect_failure '#4: in subdir' '
526 cat >4/sub/expected <<EOF &&
527 setup: git_dir: .git
528 setup: worktree: $TRASH_DIRECTORY/4
529 setup: cwd: $TRASH_DIRECTORY/4
530 setup: prefix: sub/
531 EOF
532 test_repo 4/sub
533 '
535 #
536 # case #5
537 #
538 ############################################################
539 #
540 # Input:
541 #
542 # - GIT_WORK_TREE is set
543 # - GIT_DIR is not set
544 # - core.worktree is set
545 # - .git is a directory
546 # - core.bare is not set, cwd is outside .git
547 #
548 # Output:
549 #
550 # GIT_WORK_TREE/core.worktree are ignored -> #0
552 test_expect_success '#5: setup' '
553 unset GIT_DIR GIT_WORK_TREE &&
554 mkdir 5 5/sub &&
555 cd 5 &&
556 git init &&
557 git config core.worktree non-existent &&
558 GIT_WORK_TREE=non-existent-too &&
559 export GIT_WORK_TREE &&
560 cd ..
561 '
563 test_expect_failure '#5: at root' '
564 cat >5/expected <<EOF &&
565 setup: git_dir: .git
566 setup: worktree: $TRASH_DIRECTORY/5
567 setup: cwd: $TRASH_DIRECTORY/5
568 setup: prefix: (null)
569 EOF
570 test_repo 5
571 '
573 test_expect_failure '#5: in subdir' '
574 cat >5/sub/expected <<EOF &&
575 setup: git_dir: .git
576 setup: worktree: $TRASH_DIRECTORY/5
577 setup: cwd: $TRASH_DIRECTORY/5
578 setup: prefix: sub/
579 EOF
580 test_repo 5/sub
581 '
583 #
584 # case #6
585 #
586 ############################################################
587 #
588 # Input:
589 #
590 # - GIT_WORK_TREE is not set
591 # - GIT_DIR is set
592 # - core.worktree is set
593 # - .git is a directory
594 # - core.bare is not set, cwd is outside .git
595 #
596 # Output:
597 #
598 # - worktree is at core.worktree
599 # - cwd is at worktree root
600 # - prefix is calculated
601 # - git_dir is at $GIT_DIR
602 # - cwd can be outside worktree
604 test_expect_success '#6: setup' '
605 unset GIT_DIR GIT_WORK_TREE &&
606 mkdir 6 6/sub 6/sub/sub 6.wt 6.wt/sub 6/wt 6/wt/sub &&
607 cd 6 && git init && cd ..
608 '
610 test_expect_success '#6: GIT_DIR(rel), core.worktree=.. at root' '
611 cat >6/expected <<EOF &&
612 setup: git_dir: .git
613 setup: worktree: $TRASH_DIRECTORY/6
614 setup: cwd: $TRASH_DIRECTORY/6
615 setup: prefix: (null)
616 EOF
617 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY/6" &&
618 test_repo 6 .git
619 '
621 test_expect_success '#6: GIT_DIR(rel), core.worktree=..(rel) at root' '
622 cat >6/expected <<EOF &&
623 setup: git_dir: .git
624 setup: worktree: $TRASH_DIRECTORY/6
625 setup: cwd: $TRASH_DIRECTORY/6
626 setup: prefix: (null)
627 EOF
628 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree .. &&
629 test_repo 6 .git
630 '
632 test_expect_success '#6: GIT_DIR, core.worktree=.. at root' '
633 cat >6/expected <<EOF &&
634 setup: git_dir: $TRASH_DIRECTORY/6/.git
635 setup: worktree: $TRASH_DIRECTORY/6
636 setup: cwd: $TRASH_DIRECTORY/6
637 setup: prefix: (null)
638 EOF
639 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY/6" &&
640 test_repo 6 "$TRASH_DIRECTORY/6/.git"
641 '
643 test_expect_success '#6: GIT_DIR, core.worktree=..(rel) at root' '
644 cat >6/expected <<EOF &&
645 setup: git_dir: $TRASH_DIRECTORY/6/.git
646 setup: worktree: $TRASH_DIRECTORY/6
647 setup: cwd: $TRASH_DIRECTORY/6
648 setup: prefix: (null)
649 EOF
650 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree .. &&
651 test_repo 6 "$TRASH_DIRECTORY/6/.git"
652 '
654 test_expect_failure '#6: GIT_DIR(rel), core.worktree=.. in subdir' '
655 cat >6/sub/sub/expected <<EOF &&
656 setup: git_dir: $TRASH_DIRECTORY/6/.git
657 setup: worktree: $TRASH_DIRECTORY/6
658 setup: cwd: $TRASH_DIRECTORY/6
659 setup: prefix: sub/sub/
660 EOF
661 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY/6" &&
662 test_repo 6/sub/sub ../../.git
663 '
665 test_expect_failure '#6: GIT_DIR(rel), core.worktree=..(rel) in subdir' '
666 cat >6/sub/sub/expected <<EOF &&
667 setup: git_dir: $TRASH_DIRECTORY/6/.git
668 setup: worktree: $TRASH_DIRECTORY/6
669 setup: cwd: $TRASH_DIRECTORY/6
670 setup: prefix: sub/sub/
671 EOF
672 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree .. &&
673 test_repo 6/sub/sub ../../.git
674 '
676 test_expect_success '#6: GIT_DIR, core.worktree=.. in subdir' '
677 cat >6/sub/expected <<EOF &&
678 setup: git_dir: $TRASH_DIRECTORY/6/.git
679 setup: worktree: $TRASH_DIRECTORY/6
680 setup: cwd: $TRASH_DIRECTORY/6
681 setup: prefix: sub/
682 EOF
683 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY/6" &&
684 test_repo 6/sub "$TRASH_DIRECTORY/6/.git"
685 '
687 test_expect_success '#6: GIT_DIR, core.worktree=..(rel) in subdir' '
688 cat >6/sub/sub/expected <<EOF &&
689 setup: git_dir: $TRASH_DIRECTORY/6/.git
690 setup: worktree: $TRASH_DIRECTORY/6
691 setup: cwd: $TRASH_DIRECTORY/6
692 setup: prefix: sub/sub/
693 EOF
694 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree .. &&
695 test_repo 6/sub/sub "$TRASH_DIRECTORY/6/.git"
696 '
698 test_expect_success '#6: GIT_DIR(rel), core.worktree=../wt at root' '
699 cat >6/expected <<EOF &&
700 setup: git_dir: .git
701 setup: worktree: $TRASH_DIRECTORY/6/wt
702 setup: cwd: $TRASH_DIRECTORY/6
703 setup: prefix: (null)
704 EOF
705 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY/6/wt" &&
706 test_repo 6 .git
707 '
709 test_expect_success '#6: GIT_DIR(rel), core.worktree=../wt(rel) at root' '
710 cat >6/expected <<EOF &&
711 setup: git_dir: .git
712 setup: worktree: $TRASH_DIRECTORY/6/wt
713 setup: cwd: $TRASH_DIRECTORY/6
714 setup: prefix: (null)
715 EOF
716 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree ../wt &&
717 test_repo 6 .git
718 '
720 test_expect_success '#6: GIT_DIR, core.worktree=../wt(rel) at root' '
721 cat >6/expected <<EOF &&
722 setup: git_dir: $TRASH_DIRECTORY/6/.git
723 setup: worktree: $TRASH_DIRECTORY/6/wt
724 setup: cwd: $TRASH_DIRECTORY/6
725 setup: prefix: (null)
726 EOF
727 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree ../wt &&
728 test_repo 6 "$TRASH_DIRECTORY/6/.git"
729 '
731 test_expect_success '#6: GIT_DIR, core.worktree=../wt at root' '
732 cat >6/expected <<EOF &&
733 setup: git_dir: $TRASH_DIRECTORY/6/.git
734 setup: worktree: $TRASH_DIRECTORY/6/wt
735 setup: cwd: $TRASH_DIRECTORY/6
736 setup: prefix: (null)
737 EOF
738 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY/6/wt" &&
739 test_repo 6 "$TRASH_DIRECTORY/6/.git"
740 '
742 test_expect_success '#6: GIT_DIR(rel), core.worktree=../wt in subdir' '
743 cat >6/sub/sub/expected <<EOF &&
744 setup: git_dir: ../../.git
745 setup: worktree: $TRASH_DIRECTORY/6/wt
746 setup: cwd: $TRASH_DIRECTORY/6/sub/sub
747 setup: prefix: (null)
748 EOF
749 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY/6/wt" &&
750 test_repo 6/sub/sub ../../.git
751 '
753 test_expect_success '#6: GIT_DIR(rel), core.worktree=../wt(rel) in subdir' '
754 cat >6/sub/sub/expected <<EOF &&
755 setup: git_dir: ../../.git
756 setup: worktree: $TRASH_DIRECTORY/6/wt
757 setup: cwd: $TRASH_DIRECTORY/6/sub/sub
758 setup: prefix: (null)
759 EOF
760 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree ../wt &&
761 test_repo 6/sub/sub ../../.git
762 '
764 test_expect_success '#6: GIT_DIR, core.worktree=../wt(rel) in subdir' '
765 cat >6/sub/sub/expected <<EOF &&
766 setup: git_dir: $TRASH_DIRECTORY/6/.git
767 setup: worktree: $TRASH_DIRECTORY/6/wt
768 setup: cwd: $TRASH_DIRECTORY/6/sub/sub
769 setup: prefix: (null)
770 EOF
771 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree ../wt &&
772 test_repo 6/sub/sub "$TRASH_DIRECTORY/6/.git"
773 '
775 test_expect_success '#6: GIT_DIR, core.worktree=../wt in subdir' '
776 cat >6/sub/sub/expected <<EOF &&
777 setup: git_dir: $TRASH_DIRECTORY/6/.git
778 setup: worktree: $TRASH_DIRECTORY/6/wt
779 setup: cwd: $TRASH_DIRECTORY/6/sub/sub
780 setup: prefix: (null)
781 EOF
782 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY/6/wt" &&
783 test_repo 6/sub/sub "$TRASH_DIRECTORY/6/.git"
784 '
786 test_expect_failure '#6: GIT_DIR(rel), core.worktree=../.. at root' '
787 cat >6/expected <<EOF &&
788 setup: git_dir: $TRASH_DIRECTORY/6/.git
789 setup: worktree: $TRASH_DIRECTORY
790 setup: cwd: $TRASH_DIRECTORY
791 setup: prefix: 6/
792 EOF
793 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY" &&
794 test_repo 6 .git
795 '
797 test_expect_failure '#6: GIT_DIR(rel), core.worktree=../..(rel) at root' '
798 cat >6/expected <<EOF &&
799 setup: git_dir: $TRASH_DIRECTORY/6/.git
800 setup: worktree: $TRASH_DIRECTORY
801 setup: cwd: $TRASH_DIRECTORY
802 setup: prefix: 6/
803 EOF
804 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree ../../ &&
805 test_repo 6 .git
806 '
808 test_expect_success '#6: GIT_DIR, core.worktree=../..(rel) at root' '
809 cat >6/expected <<EOF &&
810 setup: git_dir: $TRASH_DIRECTORY/6/.git
811 setup: worktree: $TRASH_DIRECTORY
812 setup: cwd: $TRASH_DIRECTORY
813 setup: prefix: 6/
814 EOF
815 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree ../../ &&
816 test_repo 6 "$TRASH_DIRECTORY/6/.git"
817 '
819 test_expect_success '#6: GIT_DIR, core.worktree=../.. at root' '
820 cat >6/expected <<EOF &&
821 setup: git_dir: $TRASH_DIRECTORY/6/.git
822 setup: worktree: $TRASH_DIRECTORY
823 setup: cwd: $TRASH_DIRECTORY
824 setup: prefix: 6/
825 EOF
826 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY" &&
827 test_repo 6 "$TRASH_DIRECTORY/6/.git"
828 '
830 test_expect_failure '#6: GIT_DIR(rel), core.worktree=../.. in subdir' '
831 cat >6/sub/sub/expected <<EOF &&
832 setup: git_dir: $TRASH_DIRECTORY/6/.git
833 setup: worktree: $TRASH_DIRECTORY
834 setup: cwd: $TRASH_DIRECTORY
835 setup: prefix: 6/sub/sub/
836 EOF
837 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY" &&
838 test_repo 6/sub/sub ../../.git
839 '
841 test_expect_failure '#6: GIT_DIR(rel), core.worktree=../..(rel) in subdir' '
842 cat >6/sub/sub/expected <<EOF &&
843 setup: git_dir: $TRASH_DIRECTORY/6/.git
844 setup: worktree: $TRASH_DIRECTORY
845 setup: cwd: $TRASH_DIRECTORY
846 setup: prefix: 6/sub/sub/
847 EOF
848 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree ../.. &&
849 test_repo 6/sub/sub ../../.git
850 '
852 test_expect_success '#6: GIT_DIR, core.worktree=../..(rel) in subdir' '
853 cat >6/sub/sub/expected <<EOF &&
854 setup: git_dir: $TRASH_DIRECTORY/6/.git
855 setup: worktree: $TRASH_DIRECTORY
856 setup: cwd: $TRASH_DIRECTORY
857 setup: prefix: 6/sub/sub/
858 EOF
859 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree ../.. &&
860 test_repo 6/sub/sub "$TRASH_DIRECTORY/6/.git"
861 '
863 test_expect_success '#6: GIT_DIR, core.worktree=../.. in subdir' '
864 cat >6/sub/sub/expected <<EOF &&
865 setup: git_dir: $TRASH_DIRECTORY/6/.git
866 setup: worktree: $TRASH_DIRECTORY
867 setup: cwd: $TRASH_DIRECTORY
868 setup: prefix: 6/sub/sub/
869 EOF
870 git config --file="$TRASH_DIRECTORY/6/.git/config" core.worktree "$TRASH_DIRECTORY" &&
871 test_repo 6/sub/sub "$TRASH_DIRECTORY/6/.git"
872 '
874 test_done