]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0060-path-utils.sh
The fifth batch
[thirdparty/git.git] / t / t0060-path-utils.sh
CommitLineData
ae299be0
DR
1#!/bin/sh
2#
3# Copyright (c) 2008 David Reiss
4#
5
6test_description='Test various path utilities'
7
8. ./test-lib.sh
9
2718e852 10norm_path() {
b8d5cf4f 11 expected=$(test-tool path-utils print_path "$2")
4bd0785d
ÆAB
12 test_expect_success $3 "normalize path: $1 => $2" "
13 echo '$expected' >expect &&
14 test-tool path-utils normalize_path_copy '$1' >actual &&
15 test_cmp expect actual
16 "
ae299be0
DR
17}
18
203439b2 19relative_path() {
b8d5cf4f 20 expected=$(test-tool path-utils print_path "$3")
4bd0785d
ÆAB
21 test_expect_success $4 "relative path: $1 $2 => $3" "
22 echo '$expected' >expect &&
23 test-tool path-utils relative_path '$1' '$2' >actual &&
24 test_cmp expect actual
25 "
203439b2
JX
26}
27
63e95beb
SB
28test_submodule_relative_url() {
29 test_expect_success "test_submodule_relative_url: $1 $2 $3 => $4" "
4bd0785d
ÆAB
30 echo '$4' >expect &&
31 test-tool submodule resolve-relative-url '$1' '$2' '$3' >actual &&
32 test_cmp expect actual
63e95beb
SB
33 "
34}
35
557bd833
NTND
36test_git_path() {
37 test_expect_success "git-path $1 $2 => $3" "
38 $1 git rev-parse --git-path $2 >actual &&
39 echo $3 >expect &&
40 test_cmp expect actual
41 "
42}
43
2718e852
JS
44# On Windows, we are using MSYS's bash, which mangles the paths.
45# Absolute paths are anchored at the MSYS installation directory,
46# which means that the path / accounts for this many characters:
b8d5cf4f 47rootoff=$(test-tool path-utils normalize_path_copy / | wc -c)
2718e852 48# Account for the trailing LF:
28baf82e 49if test $rootoff = 2; then
2718e852
JS
50 rootoff= # we are on Unix
51else
52 rootoff=$(($rootoff-1))
fc56c7b3
JS
53 # In MSYS2, the root directory "/" is translated into a Windows
54 # directory *with* trailing slash. Let's test for that and adjust
55 # our expected longest ancestor length accordingly.
b8d5cf4f 56 case "$(test-tool path-utils print_path /)" in
fc56c7b3
JS
57 */) rootslash=1;;
58 *) rootslash=0;;
59 esac
2718e852
JS
60fi
61
0454dd93 62ancestor() {
2718e852
JS
63 # We do some math with the expected ancestor length.
64 expected=$3
fdcad5a5
JS
65 case "$rootoff,$expected,$2" in
66 *,*,//*) ;; # leave UNC paths alone
67 [0-9]*,[0-9]*,/*)
68 # On Windows, expect MSYS2 pseudo root translation for
69 # Unix-style absolute paths
70 expected=$(($expected-$rootslash+$rootoff))
71 ;;
72 esac
4bd0785d
ÆAB
73 test_expect_success $4 "longest ancestor: $1 $2 => $expected" "
74 echo '$expected' >expect &&
75 test-tool path-utils longest_ancestor_length '$1' '$2' >actual &&
76 test_cmp expect actual
77 "
0454dd93
DR
78}
79
abd4284b
JX
80# Some absolute path tests should be skipped on Windows due to path mangling
81# on POSIX-style absolute paths
2718e852
JS
82case $(uname -s) in
83*MINGW*)
84 ;;
496f2569
TB
85*CYGWIN*)
86 ;;
2718e852
JS
87*)
88 test_set_prereq POSIX
89 ;;
90esac
91
b8d5cf4f
NTND
92test_expect_success basename 'test-tool path-utils basename'
93test_expect_success dirname 'test-tool path-utils dirname'
7d1aaa68 94
2718e852
JS
95norm_path "" ""
96norm_path . ""
97norm_path ./ ""
98norm_path ./. ""
99norm_path ./.. ++failed++
100norm_path ../. ++failed++
101norm_path ./../.// ++failed++
102norm_path dir/.. ""
103norm_path dir/sub/../.. ""
104norm_path dir/sub/../../.. ++failed++
105norm_path dir dir
106norm_path dir// dir/
107norm_path ./dir dir
108norm_path dir/. dir/
109norm_path dir///./ dir/
110norm_path dir//sub/.. dir/
111norm_path dir/sub/../ dir/
112norm_path dir/sub/../. dir/
113norm_path dir/s1/../s2/ dir/s2/
114norm_path d1/s1///s2/..//../s3/ d1/s3/
115norm_path d1/s1//../s2/../../d2 d2
116norm_path d1/.../d2 d1/.../d2
117norm_path d1/..././../d2 d1/d2
118
abd4284b 119norm_path / /
2718e852
JS
120norm_path // / POSIX
121norm_path /// / POSIX
abd4284b 122norm_path /. /
2718e852
JS
123norm_path /./ / POSIX
124norm_path /./.. ++failed++ POSIX
abd4284b 125norm_path /../. ++failed++
2718e852
JS
126norm_path /./../.// ++failed++ POSIX
127norm_path /dir/.. / POSIX
128norm_path /dir/sub/../.. / POSIX
129norm_path /dir/sub/../../.. ++failed++ POSIX
abd4284b
JX
130norm_path /dir /dir
131norm_path /dir// /dir/
132norm_path /./dir /dir
133norm_path /dir/. /dir/
134norm_path /dir///./ /dir/
135norm_path /dir//sub/.. /dir/
136norm_path /dir/sub/../ /dir/
2718e852 137norm_path //dir/sub/../. /dir/ POSIX
abd4284b
JX
138norm_path /dir/s1/../s2/ /dir/s2/
139norm_path /d1/s1///s2/..//../s3/ /d1/s3/
140norm_path /d1/s1//../s2/../../d2 /d2
141norm_path /d1/.../d2 /d1/.../d2
142norm_path /d1/..././../d2 /d1/d2
ae299be0 143
0454dd93 144ancestor / / -1
0454dd93
DR
145ancestor /foo / 0
146ancestor /foo /fo -1
147ancestor /foo /foo -1
0454dd93 148ancestor /foo /bar -1
0454dd93 149ancestor /foo /foo/bar -1
9e2326c7
MH
150ancestor /foo /foo:/bar -1
151ancestor /foo /:/foo:/bar 0
152ancestor /foo /foo:/:/bar 0
153ancestor /foo /:/bar:/foo 0
0454dd93
DR
154ancestor /foo/bar / 0
155ancestor /foo/bar /fo -1
0454dd93 156ancestor /foo/bar /foo 4
0454dd93
DR
157ancestor /foo/bar /foo/ba -1
158ancestor /foo/bar /:/fo 0
159ancestor /foo/bar /foo:/foo/ba 4
160ancestor /foo/bar /bar -1
9e2326c7
MH
161ancestor /foo/bar /fo -1
162ancestor /foo/bar /foo:/bar 4
163ancestor /foo/bar /:/foo:/bar 4
164ancestor /foo/bar /foo:/:/bar 4
165ancestor /foo/bar /:/bar:/fo 0
166ancestor /foo/bar /:/bar 0
167ancestor /foo/bar /foo 4
168ancestor /foo/bar /foo:/bar 4
169ancestor /foo/bar /bar -1
0454dd93 170
fdcad5a5
JS
171# Windows-specific: DOS drives, network shares
172ancestor C:/Users/me C:/ 2 MINGW
173ancestor D:/Users/me C:/ -1 MINGW
174ancestor //server/share/my-directory //server/share/ 14 MINGW
175
4fcc86b0 176test_expect_success 'strip_path_suffix' '
4bd0785d
ÆAB
177 echo c:/msysgit >expect &&
178 test-tool path-utils strip_path_suffix \
179 c:/msysgit/libexec//git-core libexec/git-core >actual &&
180 test_cmp expect actual
4fcc86b0 181'
8da650b4 182
a0601dc1 183test_expect_success 'absolute path rejects the empty string' '
b8d5cf4f 184 test_must_fail test-tool path-utils absolute_path ""
17264bcc
MH
185'
186
f82a97eb
JS
187test_expect_success MINGW '<drive-letter>:\\abc is an absolute path' '
188 for letter in : \" C Z 1 ä
189 do
190 path=$letter:\\abc &&
14af7ed5 191 absolute="$(test-tool path-utils absolute_path "$path")" &&
f82a97eb
JS
192 test "$path" = "$absolute" || return 1
193 done
194'
195
3efe5d1d 196test_expect_success 'real path rejects the empty string' '
b8d5cf4f 197 test_must_fail test-tool path-utils real_path ""
a5c45218
MH
198'
199
bacca785 200test_expect_success POSIX 'real path works on absolute paths 1' '
4bd0785d
ÆAB
201 echo / >expect &&
202 test-tool path-utils real_path "/" >actual &&
203 test_cmp expect actual &&
204
7bcf48da 205 nopath="hopefully-absent-path" &&
4bd0785d
ÆAB
206 echo "/$nopath" >expect &&
207 test-tool path-utils real_path "/$nopath" >actual &&
208 test_cmp expect actual
bacca785
JS
209'
210
211test_expect_success 'real path works on absolute paths 2' '
7bcf48da
MH
212 # Find an existing top-level directory for the remaining tests:
213 d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") &&
4bd0785d
ÆAB
214 echo "$d" >expect &&
215 test-tool path-utils real_path "$d" >actual &&
216 test_cmp expect actual &&
217
218 nopath="hopefully-absent-path" &&
219 echo "$d/$nopath" >expect &&
220 test-tool path-utils real_path "$d/$nopath" >actual &&
221 test_cmp expect actual
7bcf48da
MH
222'
223
379a03ad 224test_expect_success POSIX 'real path removes extra leading slashes' '
4bd0785d
ÆAB
225 echo "/" >expect &&
226 test-tool path-utils real_path "///" >actual &&
227 test_cmp expect actual &&
228
379a03ad 229 nopath="hopefully-absent-path" &&
4bd0785d
ÆAB
230 echo "/$nopath" >expect &&
231 test-tool path-utils real_path "///$nopath" >actual &&
232 test_cmp expect actual &&
233
379a03ad
MH
234 # Find an existing top-level directory for the remaining tests:
235 d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") &&
4bd0785d
ÆAB
236 echo "$d" >expect &&
237 test-tool path-utils real_path "//$d" >actual &&
238 test_cmp expect actual &&
239
240 echo "$d/$nopath" >expect &&
241 test-tool path-utils real_path "//$d/$nopath" >actual &&
242 test_cmp expect actual
379a03ad
MH
243'
244
245test_expect_success 'real path removes other extra slashes' '
379a03ad
MH
246 # Find an existing top-level directory for the remaining tests:
247 d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") &&
4bd0785d
ÆAB
248 echo "$d" >expect &&
249 test-tool path-utils real_path "$d///" >actual &&
250 test_cmp expect actual &&
251
252 nopath="hopefully-absent-path" &&
253 echo "$d/$nopath" >expect &&
254 test-tool path-utils real_path "$d///$nopath" >actual &&
255 test_cmp expect actual
379a03ad
MH
256'
257
7bcf48da 258test_expect_success SYMLINKS 'real path works on symlinks' '
8da650b4
MH
259 mkdir first &&
260 ln -s ../.git first/.git &&
261 mkdir second &&
262 ln -s ../first second/other &&
263 mkdir third &&
c576868e 264 dir="$(cd .git && pwd -P)" &&
8da650b4 265 dir2=third/../second/other/.git &&
4bd0785d
ÆAB
266 echo "$dir" >expect &&
267 test-tool path-utils real_path $dir2 >actual &&
268 test_cmp expect actual &&
8da650b4 269 file="$dir"/index &&
4bd0785d
ÆAB
270 echo "$file" >expect &&
271 test-tool path-utils real_path $dir2/index >actual &&
272 test_cmp expect actual &&
8da650b4 273 basename=blub &&
4bd0785d
ÆAB
274 echo "$dir/$basename" >expect &&
275 test-tool -C .git path-utils real_path "$basename" >actual &&
276 test_cmp expect actual &&
8da650b4 277 ln -s ../first/file .git/syml &&
c576868e 278 sym="$(cd first && pwd -P)"/file &&
4bd0785d
ÆAB
279 echo "$sym" >expect &&
280 test-tool path-utils real_path "$dir2/syml" >actual &&
281 test_cmp expect actual
8da650b4
MH
282'
283
655ee9ea 284test_expect_success SYMLINKS 'prefix_path works with absolute paths to work tree symlinks' '
74af95d6 285 ln -s target symlink &&
4bd0785d
ÆAB
286 echo "symlink" >expect &&
287 test-tool path-utils prefix_path prefix "$(pwd)/symlink" >actual &&
288 test_cmp expect actual
74af95d6
MEW
289'
290
e5aa1fc4
MEW
291test_expect_success 'prefix_path works with only absolute path to work tree' '
292 echo "" >expected &&
b8d5cf4f 293 test-tool path-utils prefix_path prefix "$(pwd)" >actual &&
e5aa1fc4
MEW
294 test_cmp expected actual
295'
296
e131daa4 297test_expect_success 'prefix_path rejects absolute path to dir with same beginning as work tree' '
b8d5cf4f 298 test_must_fail test-tool path-utils prefix_path prefix "$(pwd)a"
e131daa4
MEW
299'
300
301test_expect_success SYMLINKS 'prefix_path works with absolute path to a symlink to work tree having same beginning as work tree' '
302 git init repo &&
303 ln -s repo repolink &&
0cd1a881
ÆAB
304 echo "a" >expect &&
305 repo_path="$(cd repo && pwd)" &&
306 test-tool -C repo path-utils prefix_path prefix "$repo_path/../repolink/a" >actual &&
307 test_cmp expect actual
e131daa4
MEW
308'
309
daf19a80
JX
310relative_path /foo/a/b/c/ /foo/a/b/ c/
311relative_path /foo/a/b/c/ /foo/a/b c/
312relative_path /foo/a//b//c/ ///foo/a/b// c/ POSIX
313relative_path /foo/a/b /foo/a/b ./
314relative_path /foo/a/b/ /foo/a/b ./
315relative_path /foo/a /foo/a/b ../
316relative_path / /foo/a/b/ ../../../
317relative_path /foo/a/c /foo/a/b/ ../c
318relative_path /foo/a/c /foo/a/b ../c
319relative_path /foo/x/y /foo/a/b/ ../../x/y
320relative_path /foo/a/b "<empty>" /foo/a/b
321relative_path /foo/a/b "<null>" /foo/a/b
322relative_path foo/a/b/c/ foo/a/b/ c/
323relative_path foo/a/b/c/ foo/a/b c/
324relative_path foo/a/b//c foo/a//b c
325relative_path foo/a/b/ foo/a/b/ ./
326relative_path foo/a/b/ foo/a/b ./
327relative_path foo/a foo/a/b ../
328relative_path foo/x/y foo/a/b ../../x/y
329relative_path foo/a/c foo/a/b ../c
7fbd4221
JX
330relative_path foo/a/b /foo/x/y foo/a/b
331relative_path /foo/a/b foo/x/y /foo/a/b
332relative_path d:/a/b D:/a/c ../b MINGW
333relative_path C:/a/b D:/a/c C:/a/b MINGW
daf19a80
JX
334relative_path foo/a/b "<empty>" foo/a/b
335relative_path foo/a/b "<null>" foo/a/b
336relative_path "<empty>" /foo/a/b ./
337relative_path "<empty>" "<empty>" ./
338relative_path "<empty>" "<null>" ./
339relative_path "<null>" "<empty>" ./
340relative_path "<null>" "<null>" ./
341relative_path "<null>" /foo/a/b ./
203439b2 342
557bd833
NTND
343test_git_path A=B info/grafts .git/info/grafts
344test_git_path GIT_GRAFT_FILE=foo info/grafts foo
345test_git_path GIT_GRAFT_FILE=foo info/////grafts foo
346test_git_path GIT_INDEX_FILE=foo index foo
347test_git_path GIT_INDEX_FILE=foo index/foo .git/index/foo
348test_git_path GIT_INDEX_FILE=foo index2 .git/index2
349test_expect_success 'setup fake objects directory foo' 'mkdir foo'
350test_git_path GIT_OBJECT_DIRECTORY=foo objects foo
351test_git_path GIT_OBJECT_DIRECTORY=foo objects/foo foo/foo
352test_git_path GIT_OBJECT_DIRECTORY=foo objects2 .git/objects2
c7b3a3d2
NTND
353test_expect_success 'setup common repository' 'git --git-dir=bar init'
354test_git_path GIT_COMMON_DIR=bar index .git/index
76a53d64 355test_git_path GIT_COMMON_DIR=bar index.lock .git/index.lock
c7b3a3d2
NTND
356test_git_path GIT_COMMON_DIR=bar HEAD .git/HEAD
357test_git_path GIT_COMMON_DIR=bar logs/HEAD .git/logs/HEAD
76a53d64 358test_git_path GIT_COMMON_DIR=bar logs/HEAD.lock .git/logs/HEAD.lock
ce414b33 359test_git_path GIT_COMMON_DIR=bar logs/refs/bisect/foo .git/logs/refs/bisect/foo
f45f88b2
SG
360test_git_path GIT_COMMON_DIR=bar logs/refs bar/logs/refs
361test_git_path GIT_COMMON_DIR=bar logs/refs/ bar/logs/refs/
ce414b33
DT
362test_git_path GIT_COMMON_DIR=bar logs/refs/bisec/foo bar/logs/refs/bisec/foo
363test_git_path GIT_COMMON_DIR=bar logs/refs/bisec bar/logs/refs/bisec
364test_git_path GIT_COMMON_DIR=bar logs/refs/bisectfoo bar/logs/refs/bisectfoo
c7b3a3d2
NTND
365test_git_path GIT_COMMON_DIR=bar objects bar/objects
366test_git_path GIT_COMMON_DIR=bar objects/bar bar/objects/bar
367test_git_path GIT_COMMON_DIR=bar info/exclude bar/info/exclude
368test_git_path GIT_COMMON_DIR=bar info/grafts bar/info/grafts
6cfbdcb2 369test_git_path GIT_COMMON_DIR=bar info/sparse-checkout .git/info/sparse-checkout
4e09cf2a 370test_git_path GIT_COMMON_DIR=bar info//sparse-checkout .git/info//sparse-checkout
c7b3a3d2
NTND
371test_git_path GIT_COMMON_DIR=bar remotes/bar bar/remotes/bar
372test_git_path GIT_COMMON_DIR=bar branches/bar bar/branches/bar
06d53148
JS
373test_git_path GIT_COMMON_DIR=bar logs/refs/heads/main bar/logs/refs/heads/main
374test_git_path GIT_COMMON_DIR=bar refs/heads/main bar/refs/heads/main
ce414b33 375test_git_path GIT_COMMON_DIR=bar refs/bisect/foo .git/refs/bisect/foo
c7b3a3d2
NTND
376test_git_path GIT_COMMON_DIR=bar hooks/me bar/hooks/me
377test_git_path GIT_COMMON_DIR=bar config bar/config
378test_git_path GIT_COMMON_DIR=bar packed-refs bar/packed-refs
379test_git_path GIT_COMMON_DIR=bar shallow bar/shallow
8aff1a9c
NTND
380test_git_path GIT_COMMON_DIR=bar common bar/common
381test_git_path GIT_COMMON_DIR=bar common/file bar/common/file
557bd833 382
77b63ac3
JS
383# In the tests below, $(pwd) must be used because it is a native path on
384# Windows and avoids MSYS's path mangling (which simplifies "foo/../bar" and
385# strips the dot from trailing "/.").
63e95beb
SB
386
387test_submodule_relative_url "../" "../foo" "../submodule" "../../submodule"
388test_submodule_relative_url "../" "../foo/bar" "../submodule" "../../foo/submodule"
389test_submodule_relative_url "../" "../foo/submodule" "../submodule" "../../foo/submodule"
390test_submodule_relative_url "../" "./foo" "../submodule" "../submodule"
391test_submodule_relative_url "../" "./foo/bar" "../submodule" "../foo/submodule"
392test_submodule_relative_url "../../../" "../foo/bar" "../sub/a/b/c" "../../../../foo/sub/a/b/c"
77b63ac3 393test_submodule_relative_url "../" "$(pwd)/addtest" "../repo" "$(pwd)/repo"
63e95beb
SB
394test_submodule_relative_url "../" "foo/bar" "../submodule" "../foo/submodule"
395test_submodule_relative_url "../" "foo" "../submodule" "../submodule"
396
397test_submodule_relative_url "(null)" "../foo/bar" "../sub/a/b/c" "../foo/sub/a/b/c"
3389e78e 398test_submodule_relative_url "(null)" "../foo/bar" "../sub/a/b/c/" "../foo/sub/a/b/c"
08788504 399test_submodule_relative_url "(null)" "../foo/bar/" "../sub/a/b/c" "../foo/sub/a/b/c"
63e95beb
SB
400test_submodule_relative_url "(null)" "../foo/bar" "../submodule" "../foo/submodule"
401test_submodule_relative_url "(null)" "../foo/submodule" "../submodule" "../foo/submodule"
402test_submodule_relative_url "(null)" "../foo" "../submodule" "../submodule"
403test_submodule_relative_url "(null)" "./foo/bar" "../submodule" "foo/submodule"
404test_submodule_relative_url "(null)" "./foo" "../submodule" "submodule"
405test_submodule_relative_url "(null)" "//somewhere else/repo" "../subrepo" "//somewhere else/subrepo"
2711b1ad
ÆAB
406test_submodule_relative_url "(null)" "//somewhere else/repo" "../../subrepo" "//subrepo"
407test_submodule_relative_url "(null)" "//somewhere else/repo" "../../../subrepo" "/subrepo"
408test_submodule_relative_url "(null)" "//somewhere else/repo" "../../../../subrepo" "subrepo"
77b63ac3
JS
409test_submodule_relative_url "(null)" "$(pwd)/subsuper_update_r" "../subsubsuper_update_r" "$(pwd)/subsubsuper_update_r"
410test_submodule_relative_url "(null)" "$(pwd)/super_update_r2" "../subsuper_update_r" "$(pwd)/subsuper_update_r"
411test_submodule_relative_url "(null)" "$(pwd)/." "../." "$(pwd)/."
412test_submodule_relative_url "(null)" "$(pwd)" "./." "$(pwd)/."
413test_submodule_relative_url "(null)" "$(pwd)/addtest" "../repo" "$(pwd)/repo"
414test_submodule_relative_url "(null)" "$(pwd)" "./å äö" "$(pwd)/å äö"
415test_submodule_relative_url "(null)" "$(pwd)/." "../submodule" "$(pwd)/submodule"
416test_submodule_relative_url "(null)" "$(pwd)/submodule" "../submodule" "$(pwd)/submodule"
417test_submodule_relative_url "(null)" "$(pwd)/home2/../remote" "../bundle1" "$(pwd)/home2/../bundle1"
418test_submodule_relative_url "(null)" "$(pwd)/submodule_update_repo" "./." "$(pwd)/submodule_update_repo/."
63e95beb
SB
419test_submodule_relative_url "(null)" "file:///tmp/repo" "../subrepo" "file:///tmp/subrepo"
420test_submodule_relative_url "(null)" "foo/bar" "../submodule" "foo/submodule"
421test_submodule_relative_url "(null)" "foo" "../submodule" "submodule"
422test_submodule_relative_url "(null)" "helper:://hostname/repo" "../subrepo" "helper:://hostname/subrepo"
2711b1ad
ÆAB
423test_submodule_relative_url "(null)" "helper:://hostname/repo" "../../subrepo" "helper:://subrepo"
424test_submodule_relative_url "(null)" "helper:://hostname/repo" "../../../subrepo" "helper::/subrepo"
425test_submodule_relative_url "(null)" "helper:://hostname/repo" "../../../../subrepo" "helper::subrepo"
426test_submodule_relative_url "(null)" "helper:://hostname/repo" "../../../../../subrepo" "helper:subrepo"
427test_submodule_relative_url "(null)" "helper:://hostname/repo" "../../../../../../subrepo" ".:subrepo"
63e95beb 428test_submodule_relative_url "(null)" "ssh://hostname/repo" "../subrepo" "ssh://hostname/subrepo"
2711b1ad
ÆAB
429test_submodule_relative_url "(null)" "ssh://hostname/repo" "../../subrepo" "ssh://subrepo"
430test_submodule_relative_url "(null)" "ssh://hostname/repo" "../../../subrepo" "ssh:/subrepo"
431test_submodule_relative_url "(null)" "ssh://hostname/repo" "../../../../subrepo" "ssh:subrepo"
432test_submodule_relative_url "(null)" "ssh://hostname/repo" "../../../../../subrepo" ".:subrepo"
63e95beb
SB
433test_submodule_relative_url "(null)" "ssh://hostname:22/repo" "../subrepo" "ssh://hostname:22/subrepo"
434test_submodule_relative_url "(null)" "user@host:path/to/repo" "../subrepo" "user@host:path/to/subrepo"
435test_submodule_relative_url "(null)" "user@host:repo" "../subrepo" "user@host:subrepo"
2711b1ad 436test_submodule_relative_url "(null)" "user@host:repo" "../../subrepo" ".:subrepo"
63e95beb 437
dc2d9ba3 438test_expect_success 'match .gitmodules' '
7913f53b 439 test-tool path-utils is_dotgitmodules \
dc2d9ba3
JS
440 .gitmodules \
441 \
442 .git${u200c}modules \
443 \
444 .Gitmodules \
445 .gitmoduleS \
446 \
447 ".gitmodules " \
448 ".gitmodules." \
449 ".gitmodules " \
450 ".gitmodules. " \
451 ".gitmodules ." \
452 ".gitmodules.." \
453 ".gitmodules " \
454 ".gitmodules. " \
455 ".gitmodules . " \
456 ".gitmodules ." \
457 \
458 ".Gitmodules " \
459 ".Gitmodules." \
460 ".Gitmodules " \
461 ".Gitmodules. " \
462 ".Gitmodules ." \
463 ".Gitmodules.." \
464 ".Gitmodules " \
465 ".Gitmodules. " \
466 ".Gitmodules . " \
467 ".Gitmodules ." \
468 \
469 GITMOD~1 \
470 gitmod~1 \
471 GITMOD~2 \
472 gitmod~3 \
473 GITMOD~4 \
474 \
475 "GITMOD~1 " \
476 "gitmod~2." \
477 "GITMOD~3 " \
478 "gitmod~4. " \
479 "GITMOD~1 ." \
480 "gitmod~2 " \
481 "GITMOD~3. " \
482 "gitmod~4 . " \
483 \
484 GI7EBA~1 \
485 gi7eba~9 \
486 \
487 GI7EB~10 \
488 GI7EB~11 \
489 GI7EB~99 \
490 GI7EB~10 \
491 GI7E~100 \
492 GI7E~101 \
493 GI7E~999 \
494 ~1000000 \
495 ~9999999 \
496 \
91bd4658
JS
497 .gitmodules:\$DATA \
498 "gitmod~4 . :\$DATA" \
499 \
dc2d9ba3
JS
500 --not \
501 ".gitmodules x" \
502 ".gitmodules .x" \
503 \
504 " .gitmodules" \
505 \
506 ..gitmodules \
507 \
508 gitmodules \
509 \
510 .gitmodule \
511 \
512 ".gitmodules x " \
513 ".gitmodules .x" \
514 \
515 GI7EBA~ \
516 GI7EBA~0 \
517 GI7EBA~~1 \
518 GI7EBA~X \
519 Gx7EBA~1 \
520 GI7EBX~1 \
521 \
522 GI7EB~1 \
523 GI7EB~01 \
91bd4658
JS
524 GI7EB~1X \
525 \
526 .gitmodules,:\$DATA
dc2d9ba3
JS
527'
528
801ed010
JK
529test_expect_success 'match .gitattributes' '
530 test-tool path-utils is_dotgitattributes \
531 .gitattributes \
532 .git${u200c}attributes \
533 .Gitattributes \
534 .gitattributeS \
535 GITATT~1 \
536 GI7D29~1
537'
538
539test_expect_success 'match .gitignore' '
540 test-tool path-utils is_dotgitignore \
541 .gitignore \
542 .git${u200c}ignore \
543 .Gitignore \
544 .gitignorE \
545 GITIGN~1 \
546 GI250A~1
547'
548
549test_expect_success 'match .mailmap' '
550 test-tool path-utils is_dotmailmap \
551 .mailmap \
552 .mail${u200c}map \
553 .Mailmap \
554 .mailmaP \
555 MAILMA~1 \
556 MABA30~1
557'
558
d2c84dad 559test_expect_success MINGW 'is_valid_path() on Windows' '
4dc42c6c 560 test-tool path-utils is_valid_path \
d2c84dad
JS
561 win32 \
562 "win32 x" \
563 ../hello.txt \
817ddd64 564 C:\\git \
4dc42c6c
JS
565 comm \
566 conout.c \
b6852e19 567 com0.c \
4dc42c6c 568 lptN \
d2c84dad
JS
569 \
570 --not \
571 "win32 " \
572 "win32 /x " \
573 "win32." \
574 "win32 . ." \
817ddd64 575 .../hello.txt \
4dc42c6c
JS
576 colon:test \
577 "AUX.c" \
578 "abc/conOut\$ .xyz/test" \
579 lpt8 \
b6852e19 580 com9.c \
4dc42c6c
JS
581 "lpt*" \
582 Nul \
583 "PRN./abc"
dc2d9ba3
JS
584'
585
b7d11a0f
JS
586test_lazy_prereq RUNTIME_PREFIX '
587 test true = "$RUNTIME_PREFIX"
588'
589
590test_lazy_prereq CAN_EXEC_IN_PWD '
591 cp "$GIT_EXEC_PATH"/git$X ./ &&
592 ./git rev-parse
593'
594
b537af72
PS
595test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD 'setup runtime prefix' '
596 mkdir -p pretend/bin &&
597 cp "$GIT_EXEC_PATH"/git$X pretend/bin/
598'
599
58407e04 600test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD 'RUNTIME_PREFIX works' '
b537af72 601 mkdir -p pretend/libexec/git-core &&
b7d11a0f 602 echo "echo HERE" | write_script pretend/libexec/git-core/git-here &&
b7d11a0f
JS
603 GIT_EXEC_PATH= ./pretend/bin/git here >actual &&
604 echo HERE >expect &&
e394a160
JS
605 test_cmp expect actual'
606
58407e04 607test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD '%(prefix)/ works' '
e394a160
JS
608 git config yes.path "%(prefix)/yes" &&
609 GIT_EXEC_PATH= ./pretend/bin/git config --path yes.path >actual &&
610 echo "$(pwd)/pretend/yes" >expect &&
b7d11a0f
JS
611 test_cmp expect actual
612'
613
ae299be0 614test_done