blob: bbfe05b8e4a5c4c13e531647bfa460c0a552de2e [file] [log] [blame]
Nguyễn Thái Ngọc Duy03a2b6e2010-11-26 22:31:58 +07001#!/bin/sh
2
Jonathan Nieder91c031d2011-01-19 06:38:22 -06003test_description="Tests of cwd/prefix/worktree/gitdir setup in all cases
Nguyễn Thái Ngọc Duy03a2b6e2010-11-26 22:31:58 +07004
Jonathan Nieder91c031d2011-01-19 06:38:22 -06005A 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
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600195. 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.
Jonathan Nieder91c031d2011-01-19 06:38:22 -060025
266. Effective GIT_WORK_TREE overrides core.worktree and core.bare
27
287. Effective core.worktree conflicts with core.bare
29
308. If GIT_DIR is set but neither worktree nor bare setting is given,
31 original cwd becomes worktree.
32
339. 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.
35
3610. If no worktree is available, cwd remains unchanged, prefix is
37 NULL.
38
3911. When user's cwd is outside worktree, cwd remains unchanged,
40 prefix is NULL.
41"
SZEDER Gábor58275062018-02-24 00:39:49 +010042
43# This test heavily relies on the standard error of nested function calls.
44test_untraceable=UnfortunatelyYes
45
Nguyễn Thái Ngọc Duy03a2b6e2010-11-26 22:31:58 +070046. ./test-lib.sh
47
Jonathan Nieder786dabe2011-01-19 06:40:51 -060048here=$(pwd)
49
Jonathan Nieder91c031d2011-01-19 06:38:22 -060050test_repo () {
Nguyễn Thái Ngọc Duy03a2b6e2010-11-26 22:31:58 +070051 (
Jonathan Nieder91c031d2011-01-19 06:38:22 -060052 cd "$1" &&
53 if test -n "$2"
54 then
55 GIT_DIR="$2" &&
56 export GIT_DIR
57 fi &&
58 if test -n "$3"
59 then
60 GIT_WORK_TREE="$3" &&
61 export GIT_WORK_TREE
62 fi &&
63 rm -f trace &&
Jeff King7e2342d2011-02-24 09:30:30 -050064 GIT_TRACE_SETUP="$(pwd)/trace" git symbolic-ref HEAD >/dev/null &&
Jonathan Nieder91c031d2011-01-19 06:38:22 -060065 grep '^setup: ' trace >result &&
66 test_cmp expected result
Nguyễn Thái Ngọc Duy03a2b6e2010-11-26 22:31:58 +070067 )
68}
69
Jonathan Nieder786dabe2011-01-19 06:40:51 -060070maybe_config () {
71 file=$1 var=$2 value=$3 &&
72 if test "$value" != unset
73 then
74 git config --file="$file" "$var" "$value"
75 fi
76}
77
78setup_repo () {
79 name=$1 worktreecfg=$2 gitfile=$3 barecfg=$4 &&
80 sane_unset GIT_DIR GIT_WORK_TREE &&
81
Johannes Schindelin675704c2020-12-11 11:36:57 +000082 git -c init.defaultBranch=initial init "$name" &&
Jonathan Nieder786dabe2011-01-19 06:40:51 -060083 maybe_config "$name/.git/config" core.worktree "$worktreecfg" &&
84 maybe_config "$name/.git/config" core.bare "$barecfg" &&
85 mkdir -p "$name/sub/sub" &&
86
87 if test "${gitfile:+set}"
88 then
89 mv "$name/.git" "$name.git" &&
90 echo "gitdir: ../$name.git" >"$name/.git"
91 fi
92}
93
94maybe_set () {
95 var=$1 value=$2 &&
96 if test "$value" != unset
97 then
98 eval "$var=\$value" &&
99 export $var
100 fi
101}
102
103setup_env () {
104 worktreenv=$1 gitdirenv=$2 &&
105 sane_unset GIT_DIR GIT_WORK_TREE &&
106 maybe_set GIT_DIR "$gitdirenv" &&
107 maybe_set GIT_WORK_TREE "$worktreeenv"
108}
109
110expect () {
111 cat >"$1/expected" <<-EOF
112 setup: git_dir: $2
Nguyễn Thái Ngọc Duy31e26eb2014-11-30 15:24:44 +0700113 setup: git_common_dir: $2
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600114 setup: worktree: $3
115 setup: cwd: $4
116 setup: prefix: $5
117 EOF
118}
119
120try_case () {
121 name=$1 worktreeenv=$2 gitdirenv=$3 &&
122 setup_env "$worktreeenv" "$gitdirenv" &&
123 expect "$name" "$4" "$5" "$6" "$7" &&
124 test_repo "$name"
125}
126
127run_wt_tests () {
128 N=$1 gitfile=$2
129
130 absgit="$here/$N/.git"
131 dotgit=.git
132 dotdotgit=../../.git
133
134 if test "$gitfile"
135 then
136 absgit="$here/$N.git"
137 dotgit=$absgit dotdotgit=$absgit
138 fi
139
140 test_expect_success "#$N: explicit GIT_WORK_TREE and GIT_DIR at toplevel" '
141 try_case $N "$here/$N" .git \
142 "$dotgit" "$here/$N" "$here/$N" "(null)" &&
143 try_case $N . .git \
144 "$dotgit" "$here/$N" "$here/$N" "(null)" &&
145 try_case $N "$here/$N" "$here/$N/.git" \
146 "$absgit" "$here/$N" "$here/$N" "(null)" &&
147 try_case $N . "$here/$N/.git" \
148 "$absgit" "$here/$N" "$here/$N" "(null)"
149 '
150
151 test_expect_success "#$N: explicit GIT_WORK_TREE and GIT_DIR in subdir" '
152 try_case $N/sub/sub "$here/$N" ../../.git \
153 "$absgit" "$here/$N" "$here/$N" sub/sub/ &&
154 try_case $N/sub/sub ../.. ../../.git \
155 "$absgit" "$here/$N" "$here/$N" sub/sub/ &&
156 try_case $N/sub/sub "$here/$N" "$here/$N/.git" \
157 "$absgit" "$here/$N" "$here/$N" sub/sub/ &&
158 try_case $N/sub/sub ../.. "$here/$N/.git" \
159 "$absgit" "$here/$N" "$here/$N" sub/sub/
160 '
161
162 test_expect_success "#$N: explicit GIT_WORK_TREE from parent of worktree" '
163 try_case $N "$here/$N/wt" .git \
164 "$dotgit" "$here/$N/wt" "$here/$N" "(null)" &&
165 try_case $N wt .git \
166 "$dotgit" "$here/$N/wt" "$here/$N" "(null)" &&
167 try_case $N wt "$here/$N/.git" \
168 "$absgit" "$here/$N/wt" "$here/$N" "(null)" &&
169 try_case $N "$here/$N/wt" "$here/$N/.git" \
170 "$absgit" "$here/$N/wt" "$here/$N" "(null)"
171 '
172
173 test_expect_success "#$N: explicit GIT_WORK_TREE from nephew of worktree" '
174 try_case $N/sub/sub "$here/$N/wt" ../../.git \
175 "$dotdotgit" "$here/$N/wt" "$here/$N/sub/sub" "(null)" &&
176 try_case $N/sub/sub ../../wt ../../.git \
177 "$dotdotgit" "$here/$N/wt" "$here/$N/sub/sub" "(null)" &&
178 try_case $N/sub/sub ../../wt "$here/$N/.git" \
179 "$absgit" "$here/$N/wt" "$here/$N/sub/sub" "(null)" &&
180 try_case $N/sub/sub "$here/$N/wt" "$here/$N/.git" \
181 "$absgit" "$here/$N/wt" "$here/$N/sub/sub" "(null)"
182 '
183
184 test_expect_success "#$N: chdir_to_toplevel uses worktree, not git dir" '
185 try_case $N "$here" .git \
186 "$absgit" "$here" "$here" $N/ &&
187 try_case $N .. .git \
188 "$absgit" "$here" "$here" $N/ &&
189 try_case $N .. "$here/$N/.git" \
190 "$absgit" "$here" "$here" $N/ &&
191 try_case $N "$here" "$here/$N/.git" \
192 "$absgit" "$here" "$here" $N/
193 '
194
195 test_expect_success "#$N: chdir_to_toplevel uses worktree (from subdir)" '
196 try_case $N/sub/sub "$here" ../../.git \
197 "$absgit" "$here" "$here" $N/sub/sub/ &&
198 try_case $N/sub/sub ../../.. ../../.git \
199 "$absgit" "$here" "$here" $N/sub/sub/ &&
200 try_case $N/sub/sub ../../../ "$here/$N/.git" \
201 "$absgit" "$here" "$here" $N/sub/sub/ &&
202 try_case $N/sub/sub "$here" "$here/$N/.git" \
203 "$absgit" "$here" "$here" $N/sub/sub/
204 '
205}
206
207# try_repo #c GIT_WORK_TREE GIT_DIR core.worktree .gitfile? core.bare \
208# (git dir) (work tree) (cwd) (prefix) \ <-- at toplevel
209# (git dir) (work tree) (cwd) (prefix) <-- from subdir
210try_repo () {
211 name=$1 worktreeenv=$2 gitdirenv=$3 &&
212 setup_repo "$name" "$4" "$5" "$6" &&
213 shift 6 &&
214 try_case "$name" "$worktreeenv" "$gitdirenv" \
215 "$1" "$2" "$3" "$4" &&
216 shift 4 &&
217 case "$gitdirenv" in
218 /* | ?:/* | unset) ;;
219 *)
220 gitdirenv=../$gitdirenv ;;
221 esac &&
222 try_case "$name/sub" "$worktreeenv" "$gitdirenv" \
223 "$1" "$2" "$3" "$4"
224}
225
Nguyễn Thái Ngọc Duy03a2b6e2010-11-26 22:31:58 +0700226# Bit 0 = GIT_WORK_TREE
227# Bit 1 = GIT_DIR
228# Bit 2 = core.worktree
229# Bit 3 = .git is a file
230# Bit 4 = bare repo
231# Case# = encoding of the above 5 bits
232
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600233test_expect_success '#0: nonbare repo, no explicit configuration' '
234 try_repo 0 unset unset unset "" unset \
235 .git "$here/0" "$here/0" "(null)" \
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600236 .git "$here/0" "$here/0" sub/ 2>message &&
SZEDER Gáborec10b012018-08-19 23:57:22 +0200237 test_must_be_empty message
Nguyễn Thái Ngọc Duyfc4045e2010-11-26 22:31:59 +0700238'
239
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600240test_expect_success '#1: GIT_WORK_TREE without explicit GIT_DIR is accepted' '
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600241 try_repo 1 "$here" unset unset "" unset \
242 "$here/1/.git" "$here" "$here" 1/ \
243 "$here/1/.git" "$here" "$here" 1/sub/ 2>message &&
SZEDER Gáborec10b012018-08-19 23:57:22 +0200244 test_must_be_empty message
Nguyễn Thái Ngọc Duyfc4045e2010-11-26 22:31:59 +0700245'
246
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600247test_expect_success '#2: worktree defaults to cwd with explicit GIT_DIR' '
248 try_repo 2 unset "$here/2/.git" unset "" unset \
249 "$here/2/.git" "$here/2" "$here/2" "(null)" \
250 "$here/2/.git" "$here/2/sub" "$here/2/sub" "(null)"
Nguyễn Thái Ngọc Duyfc4045e2010-11-26 22:31:59 +0700251'
252
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600253test_expect_success '#2b: relative GIT_DIR' '
254 try_repo 2b unset ".git" unset "" unset \
255 ".git" "$here/2b" "$here/2b" "(null)" \
256 "../.git" "$here/2b/sub" "$here/2b/sub" "(null)"
Nguyễn Thái Ngọc Duy8fbee482010-11-26 22:32:00 +0700257'
258
Nguyễn Thái Ngọc Duy8718ed62010-11-26 22:32:02 +0700259test_expect_success '#3: setup' '
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600260 setup_repo 3 unset "" unset &&
261 mkdir -p 3/sub/sub 3/wt/sub
262'
263run_wt_tests 3
264
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600265test_expect_success '#4: core.worktree without GIT_DIR set is accepted' '
266 setup_repo 4 ../sub "" unset &&
267 mkdir -p 4/sub sub &&
268 try_case 4 unset unset \
269 .git "$here/4/sub" "$here/4" "(null)" \
270 "$here/4/.git" "$here/4/sub" "$here/4/sub" "(null)" 2>message &&
SZEDER Gáborec10b012018-08-19 23:57:22 +0200271 test_must_be_empty message
Nguyễn Thái Ngọc Duy8718ed62010-11-26 22:32:02 +0700272'
273
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600274test_expect_success '#5: core.worktree + GIT_WORK_TREE is accepted' '
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600275 # or: you cannot intimidate away the lack of GIT_DIR setting
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600276 try_repo 5 "$here" unset "$here/5" "" unset \
277 "$here/5/.git" "$here" "$here" 5/ \
278 "$here/5/.git" "$here" "$here" 5/sub/ 2>message &&
279 try_repo 5a .. unset "$here/5a" "" unset \
280 "$here/5a/.git" "$here" "$here" 5a/ \
281 "$here/5a/.git" "$here/5a" "$here/5a" sub/ &&
SZEDER Gáborec10b012018-08-19 23:57:22 +0200282 test_must_be_empty message
Nguyễn Thái Ngọc Duy8718ed62010-11-26 22:32:02 +0700283'
284
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600285test_expect_success '#6: setting GIT_DIR brings core.worktree to life' '
286 setup_repo 6 "$here/6" "" unset &&
287 try_case 6 unset .git \
288 .git "$here/6" "$here/6" "(null)" &&
289 try_case 6 unset "$here/6/.git" \
290 "$here/6/.git" "$here/6" "$here/6" "(null)" &&
291 try_case 6/sub/sub unset ../../.git \
292 "$here/6/.git" "$here/6" "$here/6" sub/sub/ &&
293 try_case 6/sub/sub unset "$here/6/.git" \
294 "$here/6/.git" "$here/6" "$here/6" sub/sub/
Nguyễn Thái Ngọc Duy8718ed62010-11-26 22:32:02 +0700295'
296
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600297test_expect_success '#6b: GIT_DIR set, core.worktree relative' '
298 setup_repo 6b .. "" unset &&
299 try_case 6b unset .git \
300 .git "$here/6b" "$here/6b" "(null)" &&
301 try_case 6b unset "$here/6b/.git" \
302 "$here/6b/.git" "$here/6b" "$here/6b" "(null)" &&
303 try_case 6b/sub/sub unset ../../.git \
304 "$here/6b/.git" "$here/6b" "$here/6b" sub/sub/ &&
305 try_case 6b/sub/sub unset "$here/6b/.git" \
306 "$here/6b/.git" "$here/6b" "$here/6b" sub/sub/
Nguyễn Thái Ngọc Duy8718ed62010-11-26 22:32:02 +0700307'
308
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600309test_expect_success '#6c: GIT_DIR set, core.worktree=../wt (absolute)' '
310 setup_repo 6c "$here/6c/wt" "" unset &&
311 mkdir -p 6c/wt/sub &&
312
313 try_case 6c unset .git \
314 .git "$here/6c/wt" "$here/6c" "(null)" &&
315 try_case 6c unset "$here/6c/.git" \
316 "$here/6c/.git" "$here/6c/wt" "$here/6c" "(null)" &&
317 try_case 6c/sub/sub unset ../../.git \
318 ../../.git "$here/6c/wt" "$here/6c/sub/sub" "(null)" &&
319 try_case 6c/sub/sub unset "$here/6c/.git" \
320 "$here/6c/.git" "$here/6c/wt" "$here/6c/sub/sub" "(null)"
Nguyễn Thái Ngọc Duy8718ed62010-11-26 22:32:02 +0700321'
322
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600323test_expect_success '#6d: GIT_DIR set, core.worktree=../wt (relative)' '
324 setup_repo 6d "$here/6d/wt" "" unset &&
325 mkdir -p 6d/wt/sub &&
326
327 try_case 6d unset .git \
328 .git "$here/6d/wt" "$here/6d" "(null)" &&
329 try_case 6d unset "$here/6d/.git" \
330 "$here/6d/.git" "$here/6d/wt" "$here/6d" "(null)" &&
331 try_case 6d/sub/sub unset ../../.git \
332 ../../.git "$here/6d/wt" "$here/6d/sub/sub" "(null)" &&
333 try_case 6d/sub/sub unset "$here/6d/.git" \
334 "$here/6d/.git" "$here/6d/wt" "$here/6d/sub/sub" "(null)"
Nguyễn Thái Ngọc Duy8718ed62010-11-26 22:32:02 +0700335'
336
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600337test_expect_success '#6e: GIT_DIR set, core.worktree=../.. (absolute)' '
338 setup_repo 6e "$here" "" unset &&
339 try_case 6e unset .git \
340 "$here/6e/.git" "$here" "$here" 6e/ &&
341 try_case 6e unset "$here/6e/.git" \
342 "$here/6e/.git" "$here" "$here" 6e/ &&
343 try_case 6e/sub/sub unset ../../.git \
344 "$here/6e/.git" "$here" "$here" 6e/sub/sub/ &&
345 try_case 6e/sub/sub unset "$here/6e/.git" \
346 "$here/6e/.git" "$here" "$here" 6e/sub/sub/
Nguyễn Thái Ngọc Duy8718ed62010-11-26 22:32:02 +0700347'
348
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600349test_expect_success '#6f: GIT_DIR set, core.worktree=../.. (relative)' '
350 setup_repo 6f ../../ "" unset &&
351 try_case 6f unset .git \
352 "$here/6f/.git" "$here" "$here" 6f/ &&
353 try_case 6f unset "$here/6f/.git" \
354 "$here/6f/.git" "$here" "$here" 6f/ &&
355 try_case 6f/sub/sub unset ../../.git \
356 "$here/6f/.git" "$here" "$here" 6f/sub/sub/ &&
357 try_case 6f/sub/sub unset "$here/6f/.git" \
358 "$here/6f/.git" "$here" "$here" 6f/sub/sub/
Nguyễn Thái Ngọc Duy8718ed62010-11-26 22:32:02 +0700359'
360
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600361# case #7: GIT_WORK_TREE overrides core.worktree.
Nguyễn Thái Ngọc Duy561a7e62010-11-26 22:32:06 +0700362test_expect_success '#7: setup' '
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600363 setup_repo 7 non-existent "" unset &&
364 mkdir -p 7/sub/sub 7/wt/sub
365'
366run_wt_tests 7
367
368test_expect_success '#8: gitfile, easy case' '
369 try_repo 8 unset unset unset gitfile unset \
370 "$here/8.git" "$here/8" "$here/8" "(null)" \
371 "$here/8.git" "$here/8" "$here/8" sub/
Nguyễn Thái Ngọc Duy561a7e62010-11-26 22:32:06 +0700372'
373
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600374test_expect_success '#9: GIT_WORK_TREE accepted with gitfile' '
375 mkdir -p 9/wt &&
376 try_repo 9 wt unset unset gitfile unset \
377 "$here/9.git" "$here/9/wt" "$here/9" "(null)" \
378 "$here/9.git" "$here/9/sub/wt" "$here/9/sub" "(null)" 2>message &&
SZEDER Gáborec10b012018-08-19 23:57:22 +0200379 test_must_be_empty message
Nguyễn Thái Ngọc Duy561a7e62010-11-26 22:32:06 +0700380'
381
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600382test_expect_success '#10: GIT_DIR can point to gitfile' '
383 try_repo 10 unset "$here/10/.git" unset gitfile unset \
384 "$here/10.git" "$here/10" "$here/10" "(null)" \
385 "$here/10.git" "$here/10/sub" "$here/10/sub" "(null)"
Nguyễn Thái Ngọc Duy561a7e62010-11-26 22:32:06 +0700386'
387
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600388test_expect_success '#10b: relative GIT_DIR can point to gitfile' '
389 try_repo 10b unset .git unset gitfile unset \
390 "$here/10b.git" "$here/10b" "$here/10b" "(null)" \
391 "$here/10b.git" "$here/10b/sub" "$here/10b/sub" "(null)"
Nguyễn Thái Ngọc Duy561a7e62010-11-26 22:32:06 +0700392'
393
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600394# case #11: GIT_WORK_TREE works, gitfile case.
Nguyễn Thái Ngọc Duy3c3b0a02010-11-26 22:32:10 +0700395test_expect_success '#11: setup' '
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600396 setup_repo 11 unset gitfile unset &&
397 mkdir -p 11/sub/sub 11/wt/sub
398'
399run_wt_tests 11 gitfile
400
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600401test_expect_success '#12: core.worktree with gitfile is accepted' '
402 try_repo 12 unset unset "$here/12" gitfile unset \
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600403 "$here/12.git" "$here/12" "$here/12" "(null)" \
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600404 "$here/12.git" "$here/12" "$here/12" sub/ 2>message &&
SZEDER Gáborec10b012018-08-19 23:57:22 +0200405 test_must_be_empty message
Nguyễn Thái Ngọc Duy3c3b0a02010-11-26 22:32:10 +0700406'
407
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600408test_expect_success '#13: core.worktree+GIT_WORK_TREE accepted (with gitfile)' '
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600409 # or: you cannot intimidate away the lack of GIT_DIR setting
410 try_repo 13 non-existent-too unset non-existent gitfile unset \
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600411 "$here/13.git" "$here/13/non-existent-too" "$here/13" "(null)" \
412 "$here/13.git" "$here/13/sub/non-existent-too" "$here/13/sub" "(null)" 2>message &&
SZEDER Gáborec10b012018-08-19 23:57:22 +0200413 test_must_be_empty message
Nguyễn Thái Ngọc Duy3c3b0a02010-11-26 22:32:10 +0700414'
415
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600416# case #14.
417# If this were more table-driven, it could share code with case #6.
418
419test_expect_success '#14: core.worktree with GIT_DIR pointing to gitfile' '
420 setup_repo 14 "$here/14" gitfile unset &&
421 try_case 14 unset .git \
422 "$here/14.git" "$here/14" "$here/14" "(null)" &&
423 try_case 14 unset "$here/14/.git" \
424 "$here/14.git" "$here/14" "$here/14" "(null)" &&
425 try_case 14/sub/sub unset ../../.git \
426 "$here/14.git" "$here/14" "$here/14" sub/sub/ &&
427 try_case 14/sub/sub unset "$here/14/.git" \
428 "$here/14.git" "$here/14" "$here/14" sub/sub/ &&
429
430 setup_repo 14c "$here/14c/wt" gitfile unset &&
431 mkdir -p 14c/wt/sub &&
432
433 try_case 14c unset .git \
434 "$here/14c.git" "$here/14c/wt" "$here/14c" "(null)" &&
435 try_case 14c unset "$here/14c/.git" \
436 "$here/14c.git" "$here/14c/wt" "$here/14c" "(null)" &&
437 try_case 14c/sub/sub unset ../../.git \
438 "$here/14c.git" "$here/14c/wt" "$here/14c/sub/sub" "(null)" &&
439 try_case 14c/sub/sub unset "$here/14c/.git" \
440 "$here/14c.git" "$here/14c/wt" "$here/14c/sub/sub" "(null)" &&
441
442 setup_repo 14d "$here/14d/wt" gitfile unset &&
443 mkdir -p 14d/wt/sub &&
444
445 try_case 14d unset .git \
446 "$here/14d.git" "$here/14d/wt" "$here/14d" "(null)" &&
447 try_case 14d unset "$here/14d/.git" \
448 "$here/14d.git" "$here/14d/wt" "$here/14d" "(null)" &&
449 try_case 14d/sub/sub unset ../../.git \
450 "$here/14d.git" "$here/14d/wt" "$here/14d/sub/sub" "(null)" &&
451 try_case 14d/sub/sub unset "$here/14d/.git" \
452 "$here/14d.git" "$here/14d/wt" "$here/14d/sub/sub" "(null)" &&
453
454 setup_repo 14e "$here" gitfile unset &&
455 try_case 14e unset .git \
456 "$here/14e.git" "$here" "$here" 14e/ &&
457 try_case 14e unset "$here/14e/.git" \
458 "$here/14e.git" "$here" "$here" 14e/ &&
459 try_case 14e/sub/sub unset ../../.git \
460 "$here/14e.git" "$here" "$here" 14e/sub/sub/ &&
461 try_case 14e/sub/sub unset "$here/14e/.git" \
462 "$here/14e.git" "$here" "$here" 14e/sub/sub/
Nguyễn Thái Ngọc Duy3c3b0a02010-11-26 22:32:10 +0700463'
464
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600465test_expect_success '#14b: core.worktree is relative to actual git dir' '
466 setup_repo 14b ../14b gitfile unset &&
467 try_case 14b unset .git \
468 "$here/14b.git" "$here/14b" "$here/14b" "(null)" &&
469 try_case 14b unset "$here/14b/.git" \
470 "$here/14b.git" "$here/14b" "$here/14b" "(null)" &&
471 try_case 14b/sub/sub unset ../../.git \
472 "$here/14b.git" "$here/14b" "$here/14b" sub/sub/ &&
473 try_case 14b/sub/sub unset "$here/14b/.git" \
474 "$here/14b.git" "$here/14b" "$here/14b" sub/sub/ &&
475
476 setup_repo 14f ../ gitfile unset &&
477 try_case 14f unset .git \
478 "$here/14f.git" "$here" "$here" 14f/ &&
479 try_case 14f unset "$here/14f/.git" \
480 "$here/14f.git" "$here" "$here" 14f/ &&
481 try_case 14f/sub/sub unset ../../.git \
482 "$here/14f.git" "$here" "$here" 14f/sub/sub/ &&
483 try_case 14f/sub/sub unset "$here/14f/.git" \
484 "$here/14f.git" "$here" "$here" 14f/sub/sub/
Nguyễn Thái Ngọc Duy3c3b0a02010-11-26 22:32:10 +0700485'
486
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600487# case #15: GIT_WORK_TREE overrides core.worktree (gitfile case).
Nguyễn Thái Ngọc Duyf7c85882010-11-26 22:32:14 +0700488test_expect_success '#15: setup' '
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600489 setup_repo 15 non-existent gitfile unset &&
490 mkdir -p 15/sub/sub 15/wt/sub
491'
492run_wt_tests 15 gitfile
493
494test_expect_success '#16a: implicitly bare repo (cwd inside .git dir)' '
495 setup_repo 16a unset "" unset &&
496 mkdir -p 16a/.git/wt/sub &&
497
498 try_case 16a/.git unset unset \
499 . "(null)" "$here/16a/.git" "(null)" &&
500 try_case 16a/.git/wt unset unset \
501 "$here/16a/.git" "(null)" "$here/16a/.git/wt" "(null)" &&
502 try_case 16a/.git/wt/sub unset unset \
503 "$here/16a/.git" "(null)" "$here/16a/.git/wt/sub" "(null)"
Nguyễn Thái Ngọc Duyf7c85882010-11-26 22:32:14 +0700504'
505
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600506test_expect_success '#16b: bare .git (cwd inside .git dir)' '
507 setup_repo 16b unset "" true &&
508 mkdir -p 16b/.git/wt/sub &&
509
510 try_case 16b/.git unset unset \
511 . "(null)" "$here/16b/.git" "(null)" &&
512 try_case 16b/.git/wt unset unset \
513 "$here/16b/.git" "(null)" "$here/16b/.git/wt" "(null)" &&
514 try_case 16b/.git/wt/sub unset unset \
515 "$here/16b/.git" "(null)" "$here/16b/.git/wt/sub" "(null)"
Nguyễn Thái Ngọc Duyf7c85882010-11-26 22:32:14 +0700516'
517
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600518test_expect_success '#16c: bare .git has no worktree' '
519 try_repo 16c unset unset unset "" true \
520 .git "(null)" "$here/16c" "(null)" \
521 "$here/16c/.git" "(null)" "$here/16c/sub" "(null)"
Nguyễn Thái Ngọc Duyf7c85882010-11-26 22:32:14 +0700522'
523
Jeff King2cd83d12013-03-08 04:32:22 -0500524test_expect_success '#16d: bareness preserved across alias' '
525 setup_repo 16d unset "" unset &&
526 (
527 cd 16d/.git &&
528 test_must_fail git status &&
529 git config alias.st status &&
530 test_must_fail git st
531 )
532'
533
534test_expect_success '#16e: bareness preserved by --bare' '
535 setup_repo 16e unset "" unset &&
536 (
537 cd 16e/.git &&
538 test_must_fail git status &&
539 test_must_fail git --bare status
540 )
541'
542
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600543test_expect_success '#17: GIT_WORK_TREE without explicit GIT_DIR is accepted (bare case)' '
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600544 # Just like #16.
545 setup_repo 17a unset "" true &&
546 setup_repo 17b unset "" true &&
547 mkdir -p 17a/.git/wt/sub &&
548 mkdir -p 17b/.git/wt/sub &&
549
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600550 try_case 17a/.git "$here/17a" unset \
551 "$here/17a/.git" "$here/17a" "$here/17a" .git/ \
552 2>message &&
553 try_case 17a/.git/wt "$here/17a" unset \
554 "$here/17a/.git" "$here/17a" "$here/17a" .git/wt/ &&
555 try_case 17a/.git/wt/sub "$here/17a" unset \
556 "$here/17a/.git" "$here/17a" "$here/17a" .git/wt/sub/ &&
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600557
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600558 try_case 17b/.git "$here/17b" unset \
559 "$here/17b/.git" "$here/17b" "$here/17b" .git/ &&
560 try_case 17b/.git/wt "$here/17b" unset \
561 "$here/17b/.git" "$here/17b" "$here/17b" .git/wt/ &&
562 try_case 17b/.git/wt/sub "$here/17b" unset \
563 "$here/17b/.git" "$here/17b" "$here/17b" .git/wt/sub/ &&
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600564
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600565 try_repo 17c "$here/17c" unset unset "" true \
566 .git "$here/17c" "$here/17c" "(null)" \
567 "$here/17c/.git" "$here/17c" "$here/17c" sub/ 2>message &&
SZEDER Gáborec10b012018-08-19 23:57:22 +0200568 test_must_be_empty message
Nguyễn Thái Ngọc Duyf7c85882010-11-26 22:32:14 +0700569'
570
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600571test_expect_success '#18: bare .git named by GIT_DIR has no worktree' '
572 try_repo 18 unset .git unset "" true \
573 .git "(null)" "$here/18" "(null)" \
574 ../.git "(null)" "$here/18/sub" "(null)" &&
575 try_repo 18b unset "$here/18b/.git" unset "" true \
576 "$here/18b/.git" "(null)" "$here/18b" "(null)" \
577 "$here/18b/.git" "(null)" "$here/18b/sub" "(null)"
Nguyễn Thái Ngọc Duyf7c85882010-11-26 22:32:14 +0700578'
579
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600580# Case #19: GIT_DIR + GIT_WORK_TREE suppresses bareness.
Nguyễn Thái Ngọc Duy09327fd2010-11-26 22:32:18 +0700581test_expect_success '#19: setup' '
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600582 setup_repo 19 unset "" true &&
583 mkdir -p 19/sub/sub 19/wt/sub
Nguyễn Thái Ngọc Duy09327fd2010-11-26 22:32:18 +0700584'
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600585run_wt_tests 19
Nguyễn Thái Ngọc Duy09327fd2010-11-26 22:32:18 +0700586
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600587test_expect_success '#20a: core.worktree without GIT_DIR accepted (inside .git)' '
588 # Unlike case #16a.
589 setup_repo 20a "$here/20a" "" unset &&
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600590 mkdir -p 20a/.git/wt/sub &&
591 try_case 20a/.git unset unset \
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600592 "$here/20a/.git" "$here/20a" "$here/20a" .git/ 2>message &&
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600593 try_case 20a/.git/wt unset unset \
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600594 "$here/20a/.git" "$here/20a" "$here/20a" .git/wt/ &&
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600595 try_case 20a/.git/wt/sub unset unset \
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600596 "$here/20a/.git" "$here/20a" "$here/20a" .git/wt/sub/ &&
SZEDER Gáborec10b012018-08-19 23:57:22 +0200597 test_must_be_empty message
Nguyễn Thái Ngọc Duy09327fd2010-11-26 22:32:18 +0700598'
599
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600600test_expect_success '#20b/c: core.worktree and core.bare conflict' '
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600601 setup_repo 20b non-existent "" true &&
602 mkdir -p 20b/.git/wt/sub &&
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600603 (
604 cd 20b/.git &&
Jeff Kingfada7672015-05-29 02:49:10 -0400605 test_must_fail git status >/dev/null
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600606 ) 2>message &&
607 grep "core.bare and core.worktree" message
Nguyễn Thái Ngọc Duy09327fd2010-11-26 22:32:18 +0700608'
609
Jeff Kingfada7672015-05-29 02:49:10 -0400610test_expect_success '#20d: core.worktree and core.bare OK when working tree not needed' '
611 setup_repo 20d non-existent "" true &&
612 mkdir -p 20d/.git/wt/sub &&
613 (
614 cd 20d/.git &&
615 git config foo.bar value
616 )
617'
618
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600619# Case #21: core.worktree/GIT_WORK_TREE overrides core.bare' '
620test_expect_success '#21: setup, core.worktree warns before overriding core.bare' '
621 setup_repo 21 non-existent "" unset &&
622 mkdir -p 21/.git/wt/sub &&
623 (
624 cd 21/.git &&
625 GIT_WORK_TREE="$here/21" &&
626 export GIT_WORK_TREE &&
Jeff Kingfada7672015-05-29 02:49:10 -0400627 git status >/dev/null
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600628 ) 2>message &&
SZEDER Gáborec10b012018-08-19 23:57:22 +0200629 test_must_be_empty message
Nguyễn Thái Ngọc Duy09327fd2010-11-26 22:32:18 +0700630
Nguyễn Thái Ngọc Duy09327fd2010-11-26 22:32:18 +0700631'
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600632run_wt_tests 21
Nguyễn Thái Ngọc Duy09327fd2010-11-26 22:32:18 +0700633
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600634test_expect_success '#22a: core.worktree = GIT_DIR = .git dir' '
635 # like case #6.
Nguyễn Thái Ngọc Duy09327fd2010-11-26 22:32:18 +0700636
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600637 setup_repo 22a "$here/22a/.git" "" unset &&
Ramkumar Ramachandra02380382011-12-08 18:40:17 +0530638 setup_repo 22ab . "" unset &&
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600639 mkdir -p 22a/.git/sub 22a/sub &&
640 mkdir -p 22ab/.git/sub 22ab/sub &&
641 try_case 22a/.git unset . \
642 . "$here/22a/.git" "$here/22a/.git" "(null)" &&
643 try_case 22a/.git unset "$here/22a/.git" \
644 "$here/22a/.git" "$here/22a/.git" "$here/22a/.git" "(null)" &&
645 try_case 22a/.git/sub unset .. \
646 "$here/22a/.git" "$here/22a/.git" "$here/22a/.git" sub/ &&
647 try_case 22a/.git/sub unset "$here/22a/.git" \
648 "$here/22a/.git" "$here/22a/.git" "$here/22a/.git" sub/ &&
Nguyễn Thái Ngọc Duy09327fd2010-11-26 22:32:18 +0700649
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600650 try_case 22ab/.git unset . \
651 . "$here/22ab/.git" "$here/22ab/.git" "(null)" &&
652 try_case 22ab/.git unset "$here/22ab/.git" \
653 "$here/22ab/.git" "$here/22ab/.git" "$here/22ab/.git" "(null)" &&
654 try_case 22ab/.git/sub unset .. \
655 "$here/22ab/.git" "$here/22ab/.git" "$here/22ab/.git" sub/ &&
656 try_case 22ab/.git unset "$here/22ab/.git" \
657 "$here/22ab/.git" "$here/22ab/.git" "$here/22ab/.git" "(null)"
Nguyễn Thái Ngọc Duy09327fd2010-11-26 22:32:18 +0700658'
659
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600660test_expect_success '#22b: core.worktree child of .git, GIT_DIR=.git' '
661 setup_repo 22b "$here/22b/.git/wt" "" unset &&
662 setup_repo 22bb wt "" unset &&
663 mkdir -p 22b/.git/sub 22b/sub 22b/.git/wt/sub 22b/wt/sub &&
664 mkdir -p 22bb/.git/sub 22bb/sub 22bb/.git/wt 22bb/wt &&
Nguyễn Thái Ngọc Duy09327fd2010-11-26 22:32:18 +0700665
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600666 try_case 22b/.git unset . \
667 . "$here/22b/.git/wt" "$here/22b/.git" "(null)" &&
668 try_case 22b/.git unset "$here/22b/.git" \
669 "$here/22b/.git" "$here/22b/.git/wt" "$here/22b/.git" "(null)" &&
670 try_case 22b/.git/sub unset .. \
671 .. "$here/22b/.git/wt" "$here/22b/.git/sub" "(null)" &&
672 try_case 22b/.git/sub unset "$here/22b/.git" \
673 "$here/22b/.git" "$here/22b/.git/wt" "$here/22b/.git/sub" "(null)" &&
Nguyễn Thái Ngọc Duy09327fd2010-11-26 22:32:18 +0700674
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600675 try_case 22bb/.git unset . \
676 . "$here/22bb/.git/wt" "$here/22bb/.git" "(null)" &&
677 try_case 22bb/.git unset "$here/22bb/.git" \
678 "$here/22bb/.git" "$here/22bb/.git/wt" "$here/22bb/.git" "(null)" &&
679 try_case 22bb/.git/sub unset .. \
680 .. "$here/22bb/.git/wt" "$here/22bb/.git/sub" "(null)" &&
681 try_case 22bb/.git/sub unset "$here/22bb/.git" \
682 "$here/22bb/.git" "$here/22bb/.git/wt" "$here/22bb/.git/sub" "(null)"
Nguyễn Thái Ngọc Duy09327fd2010-11-26 22:32:18 +0700683'
684
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600685test_expect_success '#22c: core.worktree = .git/.., GIT_DIR=.git' '
686 setup_repo 22c "$here/22c" "" unset &&
687 setup_repo 22cb .. "" unset &&
688 mkdir -p 22c/.git/sub 22c/sub &&
689 mkdir -p 22cb/.git/sub 22cb/sub &&
Nguyễn Thái Ngọc Duy09327fd2010-11-26 22:32:18 +0700690
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600691 try_case 22c/.git unset . \
692 "$here/22c/.git" "$here/22c" "$here/22c" .git/ &&
693 try_case 22c/.git unset "$here/22c/.git" \
694 "$here/22c/.git" "$here/22c" "$here/22c" .git/ &&
695 try_case 22c/.git/sub unset .. \
696 "$here/22c/.git" "$here/22c" "$here/22c" .git/sub/ &&
697 try_case 22c/.git/sub unset "$here/22c/.git" \
698 "$here/22c/.git" "$here/22c" "$here/22c" .git/sub/ &&
Nguyễn Thái Ngọc Duy09327fd2010-11-26 22:32:18 +0700699
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600700 try_case 22cb/.git unset . \
701 "$here/22cb/.git" "$here/22cb" "$here/22cb" .git/ &&
702 try_case 22cb/.git unset "$here/22cb/.git" \
703 "$here/22cb/.git" "$here/22cb" "$here/22cb" .git/ &&
704 try_case 22cb/.git/sub unset .. \
705 "$here/22cb/.git" "$here/22cb" "$here/22cb" .git/sub/ &&
706 try_case 22cb/.git/sub unset "$here/22cb/.git" \
707 "$here/22cb/.git" "$here/22cb" "$here/22cb" .git/sub/
Nguyễn Thái Ngọc Duy09327fd2010-11-26 22:32:18 +0700708'
709
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600710test_expect_success '#22.2: core.worktree and core.bare conflict' '
711 setup_repo 22 "$here/22" "" true &&
Nguyễn Thái Ngọc Duyfd4e1882010-11-26 22:32:21 +0700712 (
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600713 cd 22/.git &&
714 GIT_DIR=. &&
715 export GIT_DIR &&
Jeff Kingfada7672015-05-29 02:49:10 -0400716 test_must_fail git status 2>result
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600717 ) &&
Nguyễn Thái Ngọc Duyfd4e1882010-11-26 22:32:21 +0700718 (
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600719 cd 22 &&
720 GIT_DIR=.git &&
721 export GIT_DIR &&
Jeff Kingfada7672015-05-29 02:49:10 -0400722 test_must_fail git status 2>result
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600723 ) &&
724 grep "core.bare and core.worktree" 22/.git/result &&
725 grep "core.bare and core.worktree" 22/result
Nguyễn Thái Ngọc Duyfd4e1882010-11-26 22:32:21 +0700726'
727
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600728# Case #23: GIT_DIR + GIT_WORK_TREE(+core.worktree) suppresses bareness.
Nguyễn Thái Ngọc Duy5362cbf2010-11-26 22:32:22 +0700729test_expect_success '#23: setup' '
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600730 setup_repo 23 non-existent "" true &&
731 mkdir -p 23/sub/sub 23/wt/sub
732'
733run_wt_tests 23
734
735test_expect_success '#24: bare repo has no worktree (gitfile case)' '
736 try_repo 24 unset unset unset gitfile true \
737 "$here/24.git" "(null)" "$here/24" "(null)" \
738 "$here/24.git" "(null)" "$here/24/sub" "(null)"
Nguyễn Thái Ngọc Duy5362cbf2010-11-26 22:32:22 +0700739'
740
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600741test_expect_success '#25: GIT_WORK_TREE accepted if GIT_DIR unset (bare gitfile case)' '
742 try_repo 25 "$here/25" unset unset gitfile true \
743 "$here/25.git" "$here/25" "$here/25" "(null)" \
744 "$here/25.git" "$here/25" "$here/25" "sub/" 2>message &&
SZEDER Gáborec10b012018-08-19 23:57:22 +0200745 test_must_be_empty message
Nguyễn Thái Ngọc Duy5362cbf2010-11-26 22:32:22 +0700746'
747
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600748test_expect_success '#26: bare repo has no worktree (GIT_DIR -> gitfile case)' '
749 try_repo 26 unset "$here/26/.git" unset gitfile true \
750 "$here/26.git" "(null)" "$here/26" "(null)" \
751 "$here/26.git" "(null)" "$here/26/sub" "(null)" &&
752 try_repo 26b unset .git unset gitfile true \
753 "$here/26b.git" "(null)" "$here/26b" "(null)" \
754 "$here/26b.git" "(null)" "$here/26b/sub" "(null)"
Nguyễn Thái Ngọc Duy5362cbf2010-11-26 22:32:22 +0700755'
756
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600757# Case #27: GIT_DIR + GIT_WORK_TREE suppresses bareness (with gitfile).
Nguyễn Thái Ngọc Duy00bc13a2010-11-26 22:32:26 +0700758test_expect_success '#27: setup' '
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600759 setup_repo 27 unset gitfile true &&
760 mkdir -p 27/sub/sub 27/wt/sub
761'
762run_wt_tests 27 gitfile
763
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600764test_expect_success '#28: core.worktree and core.bare conflict (gitfile case)' '
765 setup_repo 28 "$here/28" gitfile true &&
766 (
767 cd 28 &&
Jeff Kingfada7672015-05-29 02:49:10 -0400768 test_must_fail git status
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600769 ) 2>message &&
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600770 grep "core.bare and core.worktree" message
Nguyễn Thái Ngọc Duy00bc13a2010-11-26 22:32:26 +0700771'
772
Jonathan Nieder6abbee82011-01-22 14:02:48 -0600773# Case #29: GIT_WORK_TREE(+core.worktree) overrides core.bare (gitfile case).
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600774test_expect_success '#29: setup' '
775 setup_repo 29 non-existent gitfile true &&
Ramkumar Ramachandra02380382011-12-08 18:40:17 +0530776 mkdir -p 29/sub/sub 29/wt/sub &&
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600777 (
778 cd 29 &&
779 GIT_WORK_TREE="$here/29" &&
780 export GIT_WORK_TREE &&
Jeff Kingfada7672015-05-29 02:49:10 -0400781 git status
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600782 ) 2>message &&
SZEDER Gáborec10b012018-08-19 23:57:22 +0200783 test_must_be_empty message
Nguyễn Thái Ngọc Duy00bc13a2010-11-26 22:32:26 +0700784'
Jonathan Nieder4868b2e2011-01-19 06:42:30 -0600785run_wt_tests 29 gitfile
Nguyễn Thái Ngọc Duy00bc13a2010-11-26 22:32:26 +0700786
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600787test_expect_success '#30: core.worktree and core.bare conflict (gitfile version)' '
788 # Just like case #22.
789 setup_repo 30 "$here/30" gitfile true &&
Nguyễn Thái Ngọc Duya2f509e2010-11-26 22:32:29 +0700790 (
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600791 cd 30 &&
Jeff Kingfada7672015-05-29 02:49:10 -0400792 test_must_fail env GIT_DIR=.git git status 2>result
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600793 ) &&
794 grep "core.bare and core.worktree" 30/result
Nguyễn Thái Ngọc Duya2f509e2010-11-26 22:32:29 +0700795'
796
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600797# Case #31: GIT_DIR + GIT_WORK_TREE(+core.worktree) suppresses
798# bareness (gitfile version).
Nguyễn Thái Ngọc Duye0d769d2010-11-26 22:32:30 +0700799test_expect_success '#31: setup' '
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600800 setup_repo 31 non-existent gitfile true &&
801 mkdir -p 31/sub/sub 31/wt/sub
Nguyễn Thái Ngọc Duye0d769d2010-11-26 22:32:30 +0700802'
Jonathan Nieder786dabe2011-01-19 06:40:51 -0600803run_wt_tests 31 gitfile
Nguyễn Thái Ngọc Duye0d769d2010-11-26 22:32:30 +0700804
Nguyễn Thái Ngọc Duy03a2b6e2010-11-26 22:31:58 +0700805test_done