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