convert: clarify line ending conversion warning
[git/debian.git] / t / t1510-repo-setup.sh
blob591505a39c02786962a02161d533f28dca16951e
1 #!/bin/sh
3 test_description="Tests of cwd/prefix/worktree/gitdir setup in all cases
5 A few rules for repo setup:
7 1. GIT_DIR is relative to user's cwd. --git-dir is equivalent to
8 GIT_DIR.
10 2. .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.
14 3. core.worktree is relative to git_dir.
16 4. GIT_WORK_TREE is relative to user's cwd. --work-tree is
17 equivalent to GIT_WORK_TREE.
19 5. GIT_WORK_TREE/core.worktree was originally meant to work only if
20 GIT_DIR is set, but earlier git didn't enforce it, and some scripts
21 depend on the implementation that happened to first discover .git by
22 going up from the users $cwd and then using the specified working tree
23 that may or may not have any relation to where .git was found in. This
24 historical behaviour must be kept.
26 6. Effective GIT_WORK_TREE overrides core.worktree and core.bare
28 7. Effective core.worktree conflicts with core.bare
30 8. If GIT_DIR is set but neither worktree nor bare setting is given,
31 original cwd becomes worktree.
33 9. If .git discovery is done inside a repo, the repo becomes a bare
34 repo. .git discovery is performed if GIT_DIR is not set.
36 10. If no worktree is available, cwd remains unchanged, prefix is
37 NULL.
39 11. When user's cwd is outside worktree, cwd remains unchanged,
40 prefix is NULL.
43 # This test heavily relies on the standard error of nested function calls.
44 test_untraceable=UnfortunatelyYes
46 TEST_PASSES_SANITIZE_LEAK=true
47 . ./test-lib.sh
49 here=$(pwd)
51 test_repo () {
53 cd "$1" &&
54 if test -n "$2"
55 then
56 GIT_DIR="$2" &&
57 export GIT_DIR
58 fi &&
59 if test -n "$3"
60 then
61 GIT_WORK_TREE="$3" &&
62 export GIT_WORK_TREE
63 fi &&
64 rm -f trace &&
65 GIT_TRACE_SETUP="$(pwd)/trace" git symbolic-ref HEAD >/dev/null &&
66 grep '^setup: ' trace >result &&
67 test_cmp expected result
71 maybe_config () {
72 file=$1 var=$2 value=$3 &&
73 if test "$value" != unset
74 then
75 git config --file="$file" "$var" "$value"
79 setup_repo () {
80 name=$1 worktreecfg=$2 gitfile=$3 barecfg=$4 &&
81 sane_unset GIT_DIR GIT_WORK_TREE &&
83 git -c init.defaultBranch=initial init "$name" &&
84 maybe_config "$name/.git/config" core.worktree "$worktreecfg" &&
85 maybe_config "$name/.git/config" core.bare "$barecfg" &&
86 mkdir -p "$name/sub/sub" &&
88 if test "${gitfile:+set}"
89 then
90 mv "$name/.git" "$name.git" &&
91 echo "gitdir: ../$name.git" >"$name/.git"
95 maybe_set () {
96 var=$1 value=$2 &&
97 if test "$value" != unset
98 then
99 eval "$var=\$value" &&
100 export $var
104 setup_env () {
105 worktreenv=$1 gitdirenv=$2 &&
106 sane_unset GIT_DIR GIT_WORK_TREE &&
107 maybe_set GIT_DIR "$gitdirenv" &&
108 maybe_set GIT_WORK_TREE "$worktreeenv"
111 expect () {
112 cat >"$1/expected" <<-EOF
113 setup: git_dir: $2
114 setup: git_common_dir: $2
115 setup: worktree: $3
116 setup: cwd: $4
117 setup: prefix: $5
121 try_case () {
122 name=$1 worktreeenv=$2 gitdirenv=$3 &&
123 setup_env "$worktreeenv" "$gitdirenv" &&
124 expect "$name" "$4" "$5" "$6" "$7" &&
125 test_repo "$name"
128 run_wt_tests () {
129 N=$1 gitfile=$2
131 absgit="$here/$N/.git"
132 dotgit=.git
133 dotdotgit=../../.git
135 if test "$gitfile"
136 then
137 absgit="$here/$N.git"
138 dotgit=$absgit dotdotgit=$absgit
141 test_expect_success "#$N: explicit GIT_WORK_TREE and GIT_DIR at toplevel" '
142 try_case $N "$here/$N" .git \
143 "$dotgit" "$here/$N" "$here/$N" "(null)" &&
144 try_case $N . .git \
145 "$dotgit" "$here/$N" "$here/$N" "(null)" &&
146 try_case $N "$here/$N" "$here/$N/.git" \
147 "$absgit" "$here/$N" "$here/$N" "(null)" &&
148 try_case $N . "$here/$N/.git" \
149 "$absgit" "$here/$N" "$here/$N" "(null)"
152 test_expect_success "#$N: explicit GIT_WORK_TREE and GIT_DIR in subdir" '
153 try_case $N/sub/sub "$here/$N" ../../.git \
154 "$absgit" "$here/$N" "$here/$N" sub/sub/ &&
155 try_case $N/sub/sub ../.. ../../.git \
156 "$absgit" "$here/$N" "$here/$N" sub/sub/ &&
157 try_case $N/sub/sub "$here/$N" "$here/$N/.git" \
158 "$absgit" "$here/$N" "$here/$N" sub/sub/ &&
159 try_case $N/sub/sub ../.. "$here/$N/.git" \
160 "$absgit" "$here/$N" "$here/$N" sub/sub/
163 test_expect_success "#$N: explicit GIT_WORK_TREE from parent of worktree" '
164 try_case $N "$here/$N/wt" .git \
165 "$dotgit" "$here/$N/wt" "$here/$N" "(null)" &&
166 try_case $N wt .git \
167 "$dotgit" "$here/$N/wt" "$here/$N" "(null)" &&
168 try_case $N wt "$here/$N/.git" \
169 "$absgit" "$here/$N/wt" "$here/$N" "(null)" &&
170 try_case $N "$here/$N/wt" "$here/$N/.git" \
171 "$absgit" "$here/$N/wt" "$here/$N" "(null)"
174 test_expect_success "#$N: explicit GIT_WORK_TREE from nephew of worktree" '
175 try_case $N/sub/sub "$here/$N/wt" ../../.git \
176 "$dotdotgit" "$here/$N/wt" "$here/$N/sub/sub" "(null)" &&
177 try_case $N/sub/sub ../../wt ../../.git \
178 "$dotdotgit" "$here/$N/wt" "$here/$N/sub/sub" "(null)" &&
179 try_case $N/sub/sub ../../wt "$here/$N/.git" \
180 "$absgit" "$here/$N/wt" "$here/$N/sub/sub" "(null)" &&
181 try_case $N/sub/sub "$here/$N/wt" "$here/$N/.git" \
182 "$absgit" "$here/$N/wt" "$here/$N/sub/sub" "(null)"
185 test_expect_success "#$N: chdir_to_toplevel uses worktree, not git dir" '
186 try_case $N "$here" .git \
187 "$absgit" "$here" "$here" $N/ &&
188 try_case $N .. .git \
189 "$absgit" "$here" "$here" $N/ &&
190 try_case $N .. "$here/$N/.git" \
191 "$absgit" "$here" "$here" $N/ &&
192 try_case $N "$here" "$here/$N/.git" \
193 "$absgit" "$here" "$here" $N/
196 test_expect_success "#$N: chdir_to_toplevel uses worktree (from subdir)" '
197 try_case $N/sub/sub "$here" ../../.git \
198 "$absgit" "$here" "$here" $N/sub/sub/ &&
199 try_case $N/sub/sub ../../.. ../../.git \
200 "$absgit" "$here" "$here" $N/sub/sub/ &&
201 try_case $N/sub/sub ../../../ "$here/$N/.git" \
202 "$absgit" "$here" "$here" $N/sub/sub/ &&
203 try_case $N/sub/sub "$here" "$here/$N/.git" \
204 "$absgit" "$here" "$here" $N/sub/sub/
208 # try_repo #c GIT_WORK_TREE GIT_DIR core.worktree .gitfile? core.bare \
209 # (git dir) (work tree) (cwd) (prefix) \ <-- at toplevel
210 # (git dir) (work tree) (cwd) (prefix) <-- from subdir
211 try_repo () {
212 name=$1 worktreeenv=$2 gitdirenv=$3 &&
213 setup_repo "$name" "$4" "$5" "$6" &&
214 shift 6 &&
215 try_case "$name" "$worktreeenv" "$gitdirenv" \
216 "$1" "$2" "$3" "$4" &&
217 shift 4 &&
218 case "$gitdirenv" in
219 /* | ?:/* | unset) ;;
221 gitdirenv=../$gitdirenv ;;
222 esac &&
223 try_case "$name/sub" "$worktreeenv" "$gitdirenv" \
224 "$1" "$2" "$3" "$4"
227 # Bit 0 = GIT_WORK_TREE
228 # Bit 1 = GIT_DIR
229 # Bit 2 = core.worktree
230 # Bit 3 = .git is a file
231 # Bit 4 = bare repo
232 # Case# = encoding of the above 5 bits
234 test_expect_success '#0: nonbare repo, no explicit configuration' '
235 try_repo 0 unset unset unset "" unset \
236 .git "$here/0" "$here/0" "(null)" \
237 .git "$here/0" "$here/0" sub/ 2>message &&
238 test_must_be_empty message
241 test_expect_success '#1: GIT_WORK_TREE without explicit GIT_DIR is accepted' '
242 try_repo 1 "$here" unset unset "" unset \
243 "$here/1/.git" "$here" "$here" 1/ \
244 "$here/1/.git" "$here" "$here" 1/sub/ 2>message &&
245 test_must_be_empty message
248 test_expect_success '#2: worktree defaults to cwd with explicit GIT_DIR' '
249 try_repo 2 unset "$here/2/.git" unset "" unset \
250 "$here/2/.git" "$here/2" "$here/2" "(null)" \
251 "$here/2/.git" "$here/2/sub" "$here/2/sub" "(null)"
254 test_expect_success '#2b: relative GIT_DIR' '
255 try_repo 2b unset ".git" unset "" unset \
256 ".git" "$here/2b" "$here/2b" "(null)" \
257 "../.git" "$here/2b/sub" "$here/2b/sub" "(null)"
260 test_expect_success '#3: setup' '
261 setup_repo 3 unset "" unset &&
262 mkdir -p 3/sub/sub 3/wt/sub
264 run_wt_tests 3
266 test_expect_success '#4: core.worktree without GIT_DIR set is accepted' '
267 setup_repo 4 ../sub "" unset &&
268 mkdir -p 4/sub sub &&
269 try_case 4 unset unset \
270 .git "$here/4/sub" "$here/4" "(null)" \
271 "$here/4/.git" "$here/4/sub" "$here/4/sub" "(null)" 2>message &&
272 test_must_be_empty message
275 test_expect_success '#5: core.worktree + GIT_WORK_TREE is accepted' '
276 # or: you cannot intimidate away the lack of GIT_DIR setting
277 try_repo 5 "$here" unset "$here/5" "" unset \
278 "$here/5/.git" "$here" "$here" 5/ \
279 "$here/5/.git" "$here" "$here" 5/sub/ 2>message &&
280 try_repo 5a .. unset "$here/5a" "" unset \
281 "$here/5a/.git" "$here" "$here" 5a/ \
282 "$here/5a/.git" "$here/5a" "$here/5a" sub/ &&
283 test_must_be_empty message
286 test_expect_success '#6: setting GIT_DIR brings core.worktree to life' '
287 setup_repo 6 "$here/6" "" unset &&
288 try_case 6 unset .git \
289 .git "$here/6" "$here/6" "(null)" &&
290 try_case 6 unset "$here/6/.git" \
291 "$here/6/.git" "$here/6" "$here/6" "(null)" &&
292 try_case 6/sub/sub unset ../../.git \
293 "$here/6/.git" "$here/6" "$here/6" sub/sub/ &&
294 try_case 6/sub/sub unset "$here/6/.git" \
295 "$here/6/.git" "$here/6" "$here/6" sub/sub/
298 test_expect_success '#6b: GIT_DIR set, core.worktree relative' '
299 setup_repo 6b .. "" unset &&
300 try_case 6b unset .git \
301 .git "$here/6b" "$here/6b" "(null)" &&
302 try_case 6b unset "$here/6b/.git" \
303 "$here/6b/.git" "$here/6b" "$here/6b" "(null)" &&
304 try_case 6b/sub/sub unset ../../.git \
305 "$here/6b/.git" "$here/6b" "$here/6b" sub/sub/ &&
306 try_case 6b/sub/sub unset "$here/6b/.git" \
307 "$here/6b/.git" "$here/6b" "$here/6b" sub/sub/
310 test_expect_success '#6c: GIT_DIR set, core.worktree=../wt (absolute)' '
311 setup_repo 6c "$here/6c/wt" "" unset &&
312 mkdir -p 6c/wt/sub &&
314 try_case 6c unset .git \
315 .git "$here/6c/wt" "$here/6c" "(null)" &&
316 try_case 6c unset "$here/6c/.git" \
317 "$here/6c/.git" "$here/6c/wt" "$here/6c" "(null)" &&
318 try_case 6c/sub/sub unset ../../.git \
319 ../../.git "$here/6c/wt" "$here/6c/sub/sub" "(null)" &&
320 try_case 6c/sub/sub unset "$here/6c/.git" \
321 "$here/6c/.git" "$here/6c/wt" "$here/6c/sub/sub" "(null)"
324 test_expect_success '#6d: GIT_DIR set, core.worktree=../wt (relative)' '
325 setup_repo 6d "$here/6d/wt" "" unset &&
326 mkdir -p 6d/wt/sub &&
328 try_case 6d unset .git \
329 .git "$here/6d/wt" "$here/6d" "(null)" &&
330 try_case 6d unset "$here/6d/.git" \
331 "$here/6d/.git" "$here/6d/wt" "$here/6d" "(null)" &&
332 try_case 6d/sub/sub unset ../../.git \
333 ../../.git "$here/6d/wt" "$here/6d/sub/sub" "(null)" &&
334 try_case 6d/sub/sub unset "$here/6d/.git" \
335 "$here/6d/.git" "$here/6d/wt" "$here/6d/sub/sub" "(null)"
338 test_expect_success '#6e: GIT_DIR set, core.worktree=../.. (absolute)' '
339 setup_repo 6e "$here" "" unset &&
340 try_case 6e unset .git \
341 "$here/6e/.git" "$here" "$here" 6e/ &&
342 try_case 6e unset "$here/6e/.git" \
343 "$here/6e/.git" "$here" "$here" 6e/ &&
344 try_case 6e/sub/sub unset ../../.git \
345 "$here/6e/.git" "$here" "$here" 6e/sub/sub/ &&
346 try_case 6e/sub/sub unset "$here/6e/.git" \
347 "$here/6e/.git" "$here" "$here" 6e/sub/sub/
350 test_expect_success '#6f: GIT_DIR set, core.worktree=../.. (relative)' '
351 setup_repo 6f ../../ "" unset &&
352 try_case 6f unset .git \
353 "$here/6f/.git" "$here" "$here" 6f/ &&
354 try_case 6f unset "$here/6f/.git" \
355 "$here/6f/.git" "$here" "$here" 6f/ &&
356 try_case 6f/sub/sub unset ../../.git \
357 "$here/6f/.git" "$here" "$here" 6f/sub/sub/ &&
358 try_case 6f/sub/sub unset "$here/6f/.git" \
359 "$here/6f/.git" "$here" "$here" 6f/sub/sub/
362 # case #7: GIT_WORK_TREE overrides core.worktree.
363 test_expect_success '#7: setup' '
364 setup_repo 7 non-existent "" unset &&
365 mkdir -p 7/sub/sub 7/wt/sub
367 run_wt_tests 7
369 test_expect_success '#8: gitfile, easy case' '
370 try_repo 8 unset unset unset gitfile unset \
371 "$here/8.git" "$here/8" "$here/8" "(null)" \
372 "$here/8.git" "$here/8" "$here/8" sub/
375 test_expect_success '#9: GIT_WORK_TREE accepted with gitfile' '
376 mkdir -p 9/wt &&
377 try_repo 9 wt unset unset gitfile unset \
378 "$here/9.git" "$here/9/wt" "$here/9" "(null)" \
379 "$here/9.git" "$here/9/sub/wt" "$here/9/sub" "(null)" 2>message &&
380 test_must_be_empty message
383 test_expect_success '#10: GIT_DIR can point to gitfile' '
384 try_repo 10 unset "$here/10/.git" unset gitfile unset \
385 "$here/10.git" "$here/10" "$here/10" "(null)" \
386 "$here/10.git" "$here/10/sub" "$here/10/sub" "(null)"
389 test_expect_success '#10b: relative GIT_DIR can point to gitfile' '
390 try_repo 10b unset .git unset gitfile unset \
391 "$here/10b.git" "$here/10b" "$here/10b" "(null)" \
392 "$here/10b.git" "$here/10b/sub" "$here/10b/sub" "(null)"
395 # case #11: GIT_WORK_TREE works, gitfile case.
396 test_expect_success '#11: setup' '
397 setup_repo 11 unset gitfile unset &&
398 mkdir -p 11/sub/sub 11/wt/sub
400 run_wt_tests 11 gitfile
402 test_expect_success '#12: core.worktree with gitfile is accepted' '
403 try_repo 12 unset unset "$here/12" gitfile unset \
404 "$here/12.git" "$here/12" "$here/12" "(null)" \
405 "$here/12.git" "$here/12" "$here/12" sub/ 2>message &&
406 test_must_be_empty message
409 test_expect_success '#13: core.worktree+GIT_WORK_TREE accepted (with gitfile)' '
410 # or: you cannot intimidate away the lack of GIT_DIR setting
411 try_repo 13 non-existent-too unset non-existent gitfile unset \
412 "$here/13.git" "$here/13/non-existent-too" "$here/13" "(null)" \
413 "$here/13.git" "$here/13/sub/non-existent-too" "$here/13/sub" "(null)" 2>message &&
414 test_must_be_empty message
417 # case #14.
418 # If this were more table-driven, it could share code with case #6.
420 test_expect_success '#14: core.worktree with GIT_DIR pointing to gitfile' '
421 setup_repo 14 "$here/14" gitfile unset &&
422 try_case 14 unset .git \
423 "$here/14.git" "$here/14" "$here/14" "(null)" &&
424 try_case 14 unset "$here/14/.git" \
425 "$here/14.git" "$here/14" "$here/14" "(null)" &&
426 try_case 14/sub/sub unset ../../.git \
427 "$here/14.git" "$here/14" "$here/14" sub/sub/ &&
428 try_case 14/sub/sub unset "$here/14/.git" \
429 "$here/14.git" "$here/14" "$here/14" sub/sub/ &&
431 setup_repo 14c "$here/14c/wt" gitfile unset &&
432 mkdir -p 14c/wt/sub &&
434 try_case 14c unset .git \
435 "$here/14c.git" "$here/14c/wt" "$here/14c" "(null)" &&
436 try_case 14c unset "$here/14c/.git" \
437 "$here/14c.git" "$here/14c/wt" "$here/14c" "(null)" &&
438 try_case 14c/sub/sub unset ../../.git \
439 "$here/14c.git" "$here/14c/wt" "$here/14c/sub/sub" "(null)" &&
440 try_case 14c/sub/sub unset "$here/14c/.git" \
441 "$here/14c.git" "$here/14c/wt" "$here/14c/sub/sub" "(null)" &&
443 setup_repo 14d "$here/14d/wt" gitfile unset &&
444 mkdir -p 14d/wt/sub &&
446 try_case 14d unset .git \
447 "$here/14d.git" "$here/14d/wt" "$here/14d" "(null)" &&
448 try_case 14d unset "$here/14d/.git" \
449 "$here/14d.git" "$here/14d/wt" "$here/14d" "(null)" &&
450 try_case 14d/sub/sub unset ../../.git \
451 "$here/14d.git" "$here/14d/wt" "$here/14d/sub/sub" "(null)" &&
452 try_case 14d/sub/sub unset "$here/14d/.git" \
453 "$here/14d.git" "$here/14d/wt" "$here/14d/sub/sub" "(null)" &&
455 setup_repo 14e "$here" gitfile unset &&
456 try_case 14e unset .git \
457 "$here/14e.git" "$here" "$here" 14e/ &&
458 try_case 14e unset "$here/14e/.git" \
459 "$here/14e.git" "$here" "$here" 14e/ &&
460 try_case 14e/sub/sub unset ../../.git \
461 "$here/14e.git" "$here" "$here" 14e/sub/sub/ &&
462 try_case 14e/sub/sub unset "$here/14e/.git" \
463 "$here/14e.git" "$here" "$here" 14e/sub/sub/
466 test_expect_success '#14b: core.worktree is relative to actual git dir' '
467 setup_repo 14b ../14b gitfile unset &&
468 try_case 14b unset .git \
469 "$here/14b.git" "$here/14b" "$here/14b" "(null)" &&
470 try_case 14b unset "$here/14b/.git" \
471 "$here/14b.git" "$here/14b" "$here/14b" "(null)" &&
472 try_case 14b/sub/sub unset ../../.git \
473 "$here/14b.git" "$here/14b" "$here/14b" sub/sub/ &&
474 try_case 14b/sub/sub unset "$here/14b/.git" \
475 "$here/14b.git" "$here/14b" "$here/14b" sub/sub/ &&
477 setup_repo 14f ../ gitfile unset &&
478 try_case 14f unset .git \
479 "$here/14f.git" "$here" "$here" 14f/ &&
480 try_case 14f unset "$here/14f/.git" \
481 "$here/14f.git" "$here" "$here" 14f/ &&
482 try_case 14f/sub/sub unset ../../.git \
483 "$here/14f.git" "$here" "$here" 14f/sub/sub/ &&
484 try_case 14f/sub/sub unset "$here/14f/.git" \
485 "$here/14f.git" "$here" "$here" 14f/sub/sub/
488 # case #15: GIT_WORK_TREE overrides core.worktree (gitfile case).
489 test_expect_success '#15: setup' '
490 setup_repo 15 non-existent gitfile unset &&
491 mkdir -p 15/sub/sub 15/wt/sub
493 run_wt_tests 15 gitfile
495 test_expect_success '#16a: implicitly bare repo (cwd inside .git dir)' '
496 setup_repo 16a unset "" unset &&
497 mkdir -p 16a/.git/wt/sub &&
499 try_case 16a/.git unset unset \
500 . "(null)" "$here/16a/.git" "(null)" &&
501 try_case 16a/.git/wt unset unset \
502 "$here/16a/.git" "(null)" "$here/16a/.git/wt" "(null)" &&
503 try_case 16a/.git/wt/sub unset unset \
504 "$here/16a/.git" "(null)" "$here/16a/.git/wt/sub" "(null)"
507 test_expect_success '#16b: bare .git (cwd inside .git dir)' '
508 setup_repo 16b unset "" true &&
509 mkdir -p 16b/.git/wt/sub &&
511 try_case 16b/.git unset unset \
512 . "(null)" "$here/16b/.git" "(null)" &&
513 try_case 16b/.git/wt unset unset \
514 "$here/16b/.git" "(null)" "$here/16b/.git/wt" "(null)" &&
515 try_case 16b/.git/wt/sub unset unset \
516 "$here/16b/.git" "(null)" "$here/16b/.git/wt/sub" "(null)"
519 test_expect_success '#16c: bare .git has no worktree' '
520 try_repo 16c unset unset unset "" true \
521 .git "(null)" "$here/16c" "(null)" \
522 "$here/16c/.git" "(null)" "$here/16c/sub" "(null)"
525 test_expect_success '#16d: bareness preserved across alias' '
526 setup_repo 16d unset "" unset &&
528 cd 16d/.git &&
529 test_must_fail git status &&
530 git config alias.st status &&
531 test_must_fail git st
535 test_expect_success '#16e: bareness preserved by --bare' '
536 setup_repo 16e unset "" unset &&
538 cd 16e/.git &&
539 test_must_fail git status &&
540 test_must_fail git --bare status
544 test_expect_success '#17: GIT_WORK_TREE without explicit GIT_DIR is accepted (bare case)' '
545 # Just like #16.
546 setup_repo 17a unset "" true &&
547 setup_repo 17b unset "" true &&
548 mkdir -p 17a/.git/wt/sub &&
549 mkdir -p 17b/.git/wt/sub &&
551 try_case 17a/.git "$here/17a" unset \
552 "$here/17a/.git" "$here/17a" "$here/17a" .git/ \
553 2>message &&
554 try_case 17a/.git/wt "$here/17a" unset \
555 "$here/17a/.git" "$here/17a" "$here/17a" .git/wt/ &&
556 try_case 17a/.git/wt/sub "$here/17a" unset \
557 "$here/17a/.git" "$here/17a" "$here/17a" .git/wt/sub/ &&
559 try_case 17b/.git "$here/17b" unset \
560 "$here/17b/.git" "$here/17b" "$here/17b" .git/ &&
561 try_case 17b/.git/wt "$here/17b" unset \
562 "$here/17b/.git" "$here/17b" "$here/17b" .git/wt/ &&
563 try_case 17b/.git/wt/sub "$here/17b" unset \
564 "$here/17b/.git" "$here/17b" "$here/17b" .git/wt/sub/ &&
566 try_repo 17c "$here/17c" unset unset "" true \
567 .git "$here/17c" "$here/17c" "(null)" \
568 "$here/17c/.git" "$here/17c" "$here/17c" sub/ 2>message &&
569 test_must_be_empty message
572 test_expect_success '#18: bare .git named by GIT_DIR has no worktree' '
573 try_repo 18 unset .git unset "" true \
574 .git "(null)" "$here/18" "(null)" \
575 ../.git "(null)" "$here/18/sub" "(null)" &&
576 try_repo 18b unset "$here/18b/.git" unset "" true \
577 "$here/18b/.git" "(null)" "$here/18b" "(null)" \
578 "$here/18b/.git" "(null)" "$here/18b/sub" "(null)"
581 # Case #19: GIT_DIR + GIT_WORK_TREE suppresses bareness.
582 test_expect_success '#19: setup' '
583 setup_repo 19 unset "" true &&
584 mkdir -p 19/sub/sub 19/wt/sub
586 run_wt_tests 19
588 test_expect_success '#20a: core.worktree without GIT_DIR accepted (inside .git)' '
589 # Unlike case #16a.
590 setup_repo 20a "$here/20a" "" unset &&
591 mkdir -p 20a/.git/wt/sub &&
592 try_case 20a/.git unset unset \
593 "$here/20a/.git" "$here/20a" "$here/20a" .git/ 2>message &&
594 try_case 20a/.git/wt unset unset \
595 "$here/20a/.git" "$here/20a" "$here/20a" .git/wt/ &&
596 try_case 20a/.git/wt/sub unset unset \
597 "$here/20a/.git" "$here/20a" "$here/20a" .git/wt/sub/ &&
598 test_must_be_empty message
601 test_expect_success '#20b/c: core.worktree and core.bare conflict' '
602 setup_repo 20b non-existent "" true &&
603 mkdir -p 20b/.git/wt/sub &&
605 cd 20b/.git &&
606 test_must_fail git status >/dev/null
607 ) 2>message &&
608 grep "core.bare and core.worktree" message
611 test_expect_success '#20d: core.worktree and core.bare OK when working tree not needed' '
612 setup_repo 20d non-existent "" true &&
613 mkdir -p 20d/.git/wt/sub &&
615 cd 20d/.git &&
616 git config foo.bar value
620 # Case #21: core.worktree/GIT_WORK_TREE overrides core.bare' '
621 test_expect_success '#21: setup, core.worktree warns before overriding core.bare' '
622 setup_repo 21 non-existent "" unset &&
623 mkdir -p 21/.git/wt/sub &&
625 cd 21/.git &&
626 GIT_WORK_TREE="$here/21" &&
627 export GIT_WORK_TREE &&
628 git status >/dev/null
629 ) 2>message &&
630 test_must_be_empty message
633 run_wt_tests 21
635 test_expect_success '#22a: core.worktree = GIT_DIR = .git dir' '
636 # like case #6.
638 setup_repo 22a "$here/22a/.git" "" unset &&
639 setup_repo 22ab . "" unset &&
640 mkdir -p 22a/.git/sub 22a/sub &&
641 mkdir -p 22ab/.git/sub 22ab/sub &&
642 try_case 22a/.git unset . \
643 . "$here/22a/.git" "$here/22a/.git" "(null)" &&
644 try_case 22a/.git unset "$here/22a/.git" \
645 "$here/22a/.git" "$here/22a/.git" "$here/22a/.git" "(null)" &&
646 try_case 22a/.git/sub unset .. \
647 "$here/22a/.git" "$here/22a/.git" "$here/22a/.git" sub/ &&
648 try_case 22a/.git/sub unset "$here/22a/.git" \
649 "$here/22a/.git" "$here/22a/.git" "$here/22a/.git" sub/ &&
651 try_case 22ab/.git unset . \
652 . "$here/22ab/.git" "$here/22ab/.git" "(null)" &&
653 try_case 22ab/.git unset "$here/22ab/.git" \
654 "$here/22ab/.git" "$here/22ab/.git" "$here/22ab/.git" "(null)" &&
655 try_case 22ab/.git/sub unset .. \
656 "$here/22ab/.git" "$here/22ab/.git" "$here/22ab/.git" sub/ &&
657 try_case 22ab/.git unset "$here/22ab/.git" \
658 "$here/22ab/.git" "$here/22ab/.git" "$here/22ab/.git" "(null)"
661 test_expect_success '#22b: core.worktree child of .git, GIT_DIR=.git' '
662 setup_repo 22b "$here/22b/.git/wt" "" unset &&
663 setup_repo 22bb wt "" unset &&
664 mkdir -p 22b/.git/sub 22b/sub 22b/.git/wt/sub 22b/wt/sub &&
665 mkdir -p 22bb/.git/sub 22bb/sub 22bb/.git/wt 22bb/wt &&
667 try_case 22b/.git unset . \
668 . "$here/22b/.git/wt" "$here/22b/.git" "(null)" &&
669 try_case 22b/.git unset "$here/22b/.git" \
670 "$here/22b/.git" "$here/22b/.git/wt" "$here/22b/.git" "(null)" &&
671 try_case 22b/.git/sub unset .. \
672 .. "$here/22b/.git/wt" "$here/22b/.git/sub" "(null)" &&
673 try_case 22b/.git/sub unset "$here/22b/.git" \
674 "$here/22b/.git" "$here/22b/.git/wt" "$here/22b/.git/sub" "(null)" &&
676 try_case 22bb/.git unset . \
677 . "$here/22bb/.git/wt" "$here/22bb/.git" "(null)" &&
678 try_case 22bb/.git unset "$here/22bb/.git" \
679 "$here/22bb/.git" "$here/22bb/.git/wt" "$here/22bb/.git" "(null)" &&
680 try_case 22bb/.git/sub unset .. \
681 .. "$here/22bb/.git/wt" "$here/22bb/.git/sub" "(null)" &&
682 try_case 22bb/.git/sub unset "$here/22bb/.git" \
683 "$here/22bb/.git" "$here/22bb/.git/wt" "$here/22bb/.git/sub" "(null)"
686 test_expect_success '#22c: core.worktree = .git/.., GIT_DIR=.git' '
687 setup_repo 22c "$here/22c" "" unset &&
688 setup_repo 22cb .. "" unset &&
689 mkdir -p 22c/.git/sub 22c/sub &&
690 mkdir -p 22cb/.git/sub 22cb/sub &&
692 try_case 22c/.git unset . \
693 "$here/22c/.git" "$here/22c" "$here/22c" .git/ &&
694 try_case 22c/.git unset "$here/22c/.git" \
695 "$here/22c/.git" "$here/22c" "$here/22c" .git/ &&
696 try_case 22c/.git/sub unset .. \
697 "$here/22c/.git" "$here/22c" "$here/22c" .git/sub/ &&
698 try_case 22c/.git/sub unset "$here/22c/.git" \
699 "$here/22c/.git" "$here/22c" "$here/22c" .git/sub/ &&
701 try_case 22cb/.git unset . \
702 "$here/22cb/.git" "$here/22cb" "$here/22cb" .git/ &&
703 try_case 22cb/.git unset "$here/22cb/.git" \
704 "$here/22cb/.git" "$here/22cb" "$here/22cb" .git/ &&
705 try_case 22cb/.git/sub unset .. \
706 "$here/22cb/.git" "$here/22cb" "$here/22cb" .git/sub/ &&
707 try_case 22cb/.git/sub unset "$here/22cb/.git" \
708 "$here/22cb/.git" "$here/22cb" "$here/22cb" .git/sub/
711 test_expect_success '#22.2: core.worktree and core.bare conflict' '
712 setup_repo 22 "$here/22" "" true &&
714 cd 22/.git &&
715 GIT_DIR=. &&
716 export GIT_DIR &&
717 test_must_fail git status 2>result
718 ) &&
720 cd 22 &&
721 GIT_DIR=.git &&
722 export GIT_DIR &&
723 test_must_fail git status 2>result
724 ) &&
725 grep "core.bare and core.worktree" 22/.git/result &&
726 grep "core.bare and core.worktree" 22/result
729 # Case #23: GIT_DIR + GIT_WORK_TREE(+core.worktree) suppresses bareness.
730 test_expect_success '#23: setup' '
731 setup_repo 23 non-existent "" true &&
732 mkdir -p 23/sub/sub 23/wt/sub
734 run_wt_tests 23
736 test_expect_success '#24: bare repo has no worktree (gitfile case)' '
737 try_repo 24 unset unset unset gitfile true \
738 "$here/24.git" "(null)" "$here/24" "(null)" \
739 "$here/24.git" "(null)" "$here/24/sub" "(null)"
742 test_expect_success '#25: GIT_WORK_TREE accepted if GIT_DIR unset (bare gitfile case)' '
743 try_repo 25 "$here/25" unset unset gitfile true \
744 "$here/25.git" "$here/25" "$here/25" "(null)" \
745 "$here/25.git" "$here/25" "$here/25" "sub/" 2>message &&
746 test_must_be_empty message
749 test_expect_success '#26: bare repo has no worktree (GIT_DIR -> gitfile case)' '
750 try_repo 26 unset "$here/26/.git" unset gitfile true \
751 "$here/26.git" "(null)" "$here/26" "(null)" \
752 "$here/26.git" "(null)" "$here/26/sub" "(null)" &&
753 try_repo 26b unset .git unset gitfile true \
754 "$here/26b.git" "(null)" "$here/26b" "(null)" \
755 "$here/26b.git" "(null)" "$here/26b/sub" "(null)"
758 # Case #27: GIT_DIR + GIT_WORK_TREE suppresses bareness (with gitfile).
759 test_expect_success '#27: setup' '
760 setup_repo 27 unset gitfile true &&
761 mkdir -p 27/sub/sub 27/wt/sub
763 run_wt_tests 27 gitfile
765 test_expect_success '#28: core.worktree and core.bare conflict (gitfile case)' '
766 setup_repo 28 "$here/28" gitfile true &&
768 cd 28 &&
769 test_must_fail git status
770 ) 2>message &&
771 grep "core.bare and core.worktree" message
774 # Case #29: GIT_WORK_TREE(+core.worktree) overrides core.bare (gitfile case).
775 test_expect_success '#29: setup' '
776 setup_repo 29 non-existent gitfile true &&
777 mkdir -p 29/sub/sub 29/wt/sub &&
779 cd 29 &&
780 GIT_WORK_TREE="$here/29" &&
781 export GIT_WORK_TREE &&
782 git status
783 ) 2>message &&
784 test_must_be_empty message
786 run_wt_tests 29 gitfile
788 test_expect_success '#30: core.worktree and core.bare conflict (gitfile version)' '
789 # Just like case #22.
790 setup_repo 30 "$here/30" gitfile true &&
792 cd 30 &&
793 test_must_fail env GIT_DIR=.git git status 2>result
794 ) &&
795 grep "core.bare and core.worktree" 30/result
798 # Case #31: GIT_DIR + GIT_WORK_TREE(+core.worktree) suppresses
799 # bareness (gitfile version).
800 test_expect_success '#31: setup' '
801 setup_repo 31 non-existent gitfile true &&
802 mkdir -p 31/sub/sub 31/wt/sub
804 run_wt_tests 31 gitfile
806 test_done