summaryrefslogtreecommitdiffstats
path: root/t/t0060-path-utils.sh
blob: 85686ee15dadcaed4e00631ce677e987c7f7b3a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
#!/bin/sh
#
# Copyright (c) 2008 David Reiss
#

test_description='Test various path utilities'

TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh

norm_path() {
	expected=$(test-tool path-utils print_path "$2")
	test_expect_success $3 "normalize path: $1 => $2" "
		echo '$expected' >expect &&
		test-tool path-utils normalize_path_copy '$1' >actual &&
		test_cmp expect actual
	"
}

relative_path() {
	expected=$(test-tool path-utils print_path "$3")
	test_expect_success $4 "relative path: $1 $2 => $3" "
		echo '$expected' >expect &&
		test-tool path-utils relative_path '$1' '$2' >actual &&
		test_cmp expect actual
	"
}

test_submodule_relative_url() {
	test_expect_success "test_submodule_relative_url: $1 $2 $3 => $4" "
		echo '$4' >expect &&
		test-tool submodule resolve-relative-url '$1' '$2' '$3' >actual &&
		test_cmp expect actual
	"
}

test_git_path() {
	test_expect_success "git-path $1 $2 => $3" "
		$1 git rev-parse --git-path $2 >actual &&
		echo $3 >expect &&
		test_cmp expect actual
	"
}

# On Windows, we are using MSYS's bash, which mangles the paths.
# Absolute paths are anchored at the MSYS installation directory,
# which means that the path / accounts for this many characters:
rootoff=$(test-tool path-utils normalize_path_copy / | wc -c)
# Account for the trailing LF:
if test $rootoff = 2; then
	rootoff=	# we are on Unix
else
	rootoff=$(($rootoff-1))
	# In MSYS2, the root directory "/" is translated into a Windows
	# directory *with* trailing slash. Let's test for that and adjust
	# our expected longest ancestor length accordingly.
	case "$(test-tool path-utils print_path /)" in
	*/) rootslash=1;;
	*) rootslash=0;;
	esac
fi

ancestor() {
	# We do some math with the expected ancestor length.
	expected=$3
	case "$rootoff,$expected,$2" in
	*,*,//*) ;; # leave UNC paths alone
	[0-9]*,[0-9]*,/*)
		# On Windows, expect MSYS2 pseudo root translation for
		# Unix-style absolute paths
		expected=$(($expected-$rootslash+$rootoff))
		;;
	esac
	test_expect_success $4 "longest ancestor: $1 $2 => $expected" "
		echo '$expected' >expect &&
		test-tool path-utils longest_ancestor_length '$1' '$2' >actual &&
		test_cmp expect actual
	"
}

# Some absolute path tests should be skipped on Windows due to path mangling
# on POSIX-style absolute paths
case $(uname -s) in
*MINGW*)
	;;
*CYGWIN*)
	;;
*)
	test_set_prereq POSIX
	;;
esac

test_expect_success basename 'test-tool path-utils basename'
test_expect_success dirname 'test-tool path-utils dirname'

norm_path "" ""
norm_path . ""
norm_path ./ ""
norm_path ./. ""
norm_path ./.. ++failed++
norm_path ../. ++failed++
norm_path ./../.// ++failed++
norm_path dir/.. ""
norm_path dir/sub/../.. ""
norm_path dir/sub/../../.. ++failed++
norm_path dir dir
norm_path dir// dir/
norm_path ./dir dir
norm_path dir/. dir/
norm_path dir///./ dir/
norm_path dir//sub/.. dir/
norm_path dir/sub/../ dir/
norm_path dir/sub/../. dir/
norm_path dir/s1/../s2/ dir/s2/
norm_path d1/s1///s2/..//../s3/ d1/s3/
norm_path d1/s1//../s2/../../d2 d2
norm_path d1/.../d2 d1/.../d2
norm_path d1/..././../d2 d1/d2

norm_path / /
norm_path // / POSIX
norm_path /// / POSIX
norm_path /. /
norm_path /./ / POSIX
norm_path /./.. ++failed++ POSIX
norm_path /../. ++failed++
norm_path /./../.// ++failed++ POSIX
norm_path /dir/.. / POSIX
norm_path /dir/sub/../.. / POSIX
norm_path /dir/sub/../../.. ++failed++ POSIX
norm_path /dir /dir
norm_path /dir// /dir/
norm_path /./dir /dir
norm_path /dir/. /dir/
norm_path /dir///./ /dir/
norm_path /dir//sub/.. /dir/
norm_path /dir/sub/../ /dir/
norm_path //dir/sub/../. /dir/ POSIX
norm_path /dir/s1/../s2/ /dir/s2/
norm_path /d1/s1///s2/..//../s3/ /d1/s3/
norm_path /d1/s1//../s2/../../d2 /d2
norm_path /d1/.../d2 /d1/.../d2
norm_path /d1/..././../d2 /d1/d2

ancestor / / -1
ancestor /foo / 0
ancestor /foo /fo -1
ancestor /foo /foo -1
ancestor /foo /bar -1
ancestor /foo /foo/bar -1
ancestor /foo /foo:/bar -1
ancestor /foo /:/foo:/bar 0
ancestor /foo /foo:/:/bar 0
ancestor /foo /:/bar:/foo 0
ancestor /foo/bar / 0
ancestor /foo/bar /fo -1
ancestor /foo/bar /foo 4
ancestor /foo/bar /foo/ba -1
ancestor /foo/bar /:/fo 0
ancestor /foo/bar /foo:/foo/ba 4
ancestor /foo/bar /bar -1
ancestor /foo/bar /fo -1
ancestor /foo/bar /foo:/bar 4
ancestor /foo/bar /:/foo:/bar 4
ancestor /foo/bar /foo:/:/bar 4
ancestor /foo/bar /:/bar:/fo 0
ancestor /foo/bar /:/bar 0
ancestor /foo/bar /foo 4
ancestor /foo/bar /foo:/bar 4
ancestor /foo/bar /bar -1

# Windows-specific: DOS drives, network shares
ancestor C:/Users/me C:/ 2 MINGW
ancestor D:/Users/me C:/ -1 MINGW
ancestor //server/share/my-directory //server/share/ 14 MINGW

test_expect_success 'strip_path_suffix' '
	echo c:/msysgit >expect &&
	test-tool path-utils strip_path_suffix \
		c:/msysgit/libexec//git-core libexec/git-core >actual &&
	test_cmp expect actual
'

test_expect_success 'absolute path rejects the empty string' '
	test_must_fail test-tool path-utils absolute_path ""
'

test_expect_success MINGW '<drive-letter>:\\abc is an absolute path' '
	for letter in : \" C Z 1 ä
	do
		path=$letter:\\abc &&
		absolute="$(test-tool path-utils absolute_path "$path")" &&
		test "$path" = "$absolute" || return 1
	done
'

test_expect_success 'real path rejects the empty string' '
	test_must_fail test-tool path-utils real_path ""
'

test_expect_success POSIX 'real path works on absolute paths 1' '
	echo / >expect &&
	test-tool path-utils real_path "/" >actual &&
	test_cmp expect actual &&

	nopath="hopefully-absent-path" &&
	echo "/$nopath" >expect &&
	test-tool path-utils real_path "/$nopath" >actual &&
	test_cmp expect actual
'

test_expect_success 'real path works on absolute paths 2' '
	# Find an existing top-level directory for the remaining tests:
	d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") &&
	echo "$d" >expect &&
	test-tool path-utils real_path "$d" >actual &&
	test_cmp expect actual &&

	nopath="hopefully-absent-path" &&
	echo "$d/$nopath" >expect &&
	test-tool path-utils real_path "$d/$nopath" >actual &&
	test_cmp expect actual
'

test_expect_success POSIX 'real path removes extra leading slashes' '
	echo "/" >expect &&
	test-tool path-utils real_path "///" >actual &&
	test_cmp expect actual &&

	nopath="hopefully-absent-path" &&
	echo "/$nopath" >expect &&
	test-tool path-utils real_path "///$nopath" >actual &&
	test_cmp expect actual &&

	# Find an existing top-level directory for the remaining tests:
	d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") &&
	echo "$d" >expect &&
	test-tool path-utils real_path "//$d" >actual &&
	test_cmp expect actual &&

	echo "$d/$nopath" >expect &&
	test-tool path-utils real_path "//$d/$nopath" >actual &&
	test_cmp expect actual
'

test_expect_success 'real path removes other extra slashes' '
	# Find an existing top-level directory for the remaining tests:
	d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") &&
	echo "$d" >expect &&
	test-tool path-utils real_path "$d///" >actual &&
	test_cmp expect actual &&

	nopath="hopefully-absent-path" &&
	echo "$d/$nopath" >expect &&
	test-tool path-utils real_path "$d///$nopath" >actual &&
	test_cmp expect actual
'

test_expect_success SYMLINKS 'real path works on symlinks' '
	mkdir first &&
	ln -s ../.git first/.git &&
	mkdir second &&
	ln -s ../first second/other &&
	mkdir third &&
	dir="$(cd .git && pwd -P)" &&
	dir2=third/../second/other/.git &&
	echo "$dir" >expect &&
	test-tool path-utils real_path $dir2 >actual &&
	test_cmp expect actual &&
	file="$dir"/index &&
	echo "$file" >expect &&
	test-tool path-utils real_path $dir2/index >actual &&
	test_cmp expect actual &&
	basename=blub &&
	echo "$dir/$basename" >expect &&
	test-tool -C .git path-utils real_path "$basename" >actual &&
	test_cmp expect actual &&
	ln -s ../first/file .git/syml &&
	sym="$(cd first && pwd -P)"/file &&
	echo "$sym" >expect &&
	test-tool path-utils real_path "$dir2/syml" >actual &&
	test_cmp expect actual
'

test_expect_success SYMLINKS 'prefix_path works with absolute paths to work tree symlinks' '
	ln -s target symlink &&
	echo "symlink" >expect &&
	test-tool path-utils prefix_path prefix "$(pwd)/symlink" >actual &&
	test_cmp expect actual
'

test_expect_success 'prefix_path works with only absolute path to work tree' '
	echo "" >expected &&
	test-tool path-utils prefix_path prefix "$(pwd)" >actual &&
	test_cmp expected actual
'

test_expect_success 'prefix_path rejects absolute path to dir with same beginning as work tree' '
	test_must_fail test-tool path-utils prefix_path prefix "$(pwd)a"
'

test_expect_success SYMLINKS 'prefix_path works with absolute path to a symlink to work tree having  same beginning as work tree' '
	git init repo &&
	ln -s repo repolink &&
	echo "a" >expect &&
	repo_path="$(cd repo && pwd)" &&
	test-tool -C repo path-utils prefix_path prefix "$repo_path/../repolink/a" >actual &&
	test_cmp expect actual
'

relative_path /foo/a/b/c/	/foo/a/b/	c/
relative_path /foo/a/b/c/	/foo/a/b	c/
relative_path /foo/a//b//c/	///foo/a/b//	c/		POSIX
relative_path /foo/a/b		/foo/a/b	./
relative_path /foo/a/b/		/foo/a/b	./
relative_path /foo/a		/foo/a/b	../
relative_path /			/foo/a/b/	../../../
relative_path /foo/a/c		/foo/a/b/	../c
relative_path /foo/a/c		/foo/a/b	../c
relative_path /foo/x/y		/foo/a/b/	../../x/y
relative_path /foo/a/b		"<empty>"	/foo/a/b
relative_path /foo/a/b 		"<null>"	/foo/a/b
relative_path foo/a/b/c/	foo/a/b/	c/
relative_path foo/a/b/c/	foo/a/b		c/
relative_path foo/a/b//c	foo/a//b	c
relative_path foo/a/b/		foo/a/b/	./
relative_path foo/a/b/		foo/a/b		./
relative_path foo/a		foo/a/b		../
relative_path foo/x/y		foo/a/b		../../x/y
relative_path foo/a/c		foo/a/b		../c
relative_path foo/a/b		/foo/x/y	foo/a/b
relative_path /foo/a/b		foo/x/y		/foo/a/b
relative_path d:/a/b		D:/a/c		../b		MINGW
relative_path C:/a/b		D:/a/c		C:/a/b		MINGW
relative_path foo/a/b		"<empty>"	foo/a/b
relative_path foo/a/b 		"<null>"	foo/a/b
relative_path "<empty>"		/foo/a/b	./
relative_path "<empty>"		"<empty>"	./
relative_path "<empty>"		"<null>"	./
relative_path "<null>"		"<empty>"	./
relative_path "<null>"		"<null>"	./
relative_path "<null>"		/foo/a/b	./

test_git_path A=B                info/grafts .git/info/grafts
test_git_path GIT_GRAFT_FILE=foo info/grafts foo
test_git_path GIT_GRAFT_FILE=foo info/////grafts foo
test_git_path GIT_INDEX_FILE=foo index foo
test_git_path GIT_INDEX_FILE=foo index/foo .git/index/foo
test_git_path GIT_INDEX_FILE=foo index2 .git/index2
test_expect_success 'setup fake objects directory foo' 'mkdir foo'
test_git_path GIT_OBJECT_DIRECTORY=foo objects foo
test_git_path GIT_OBJECT_DIRECTORY=foo objects/foo foo/foo
test_git_path GIT_OBJECT_DIRECTORY=foo objects2 .git/objects2
test_expect_success 'setup common repository' 'git --git-dir=bar init'
test_git_path GIT_COMMON_DIR=bar index                    .git/index
test_git_path GIT_COMMON_DIR=bar index.lock               .git/index.lock
test_git_path GIT_COMMON_DIR=bar HEAD                     .git/HEAD
test_git_path GIT_COMMON_DIR=bar logs/HEAD                .git/logs/HEAD
test_git_path GIT_COMMON_DIR=bar logs/HEAD.lock           .git/logs/HEAD.lock
test_git_path GIT_COMMON_DIR=bar logs/refs/bisect/foo     .git/logs/refs/bisect/foo
test_git_path GIT_COMMON_DIR=bar logs/refs                bar/logs/refs
test_git_path GIT_COMMON_DIR=bar logs/refs/               bar/logs/refs/
test_git_path GIT_COMMON_DIR=bar logs/refs/bisec/foo      bar/logs/refs/bisec/foo
test_git_path GIT_COMMON_DIR=bar logs/refs/bisec          bar/logs/refs/bisec
test_git_path GIT_COMMON_DIR=bar logs/refs/bisectfoo      bar/logs/refs/bisectfoo
test_git_path GIT_COMMON_DIR=bar objects                  bar/objects
test_git_path GIT_COMMON_DIR=bar objects/bar              bar/objects/bar
test_git_path GIT_COMMON_DIR=bar info/exclude             bar/info/exclude
test_git_path GIT_COMMON_DIR=bar info/grafts              bar/info/grafts
test_git_path GIT_COMMON_DIR=bar info/sparse-checkout     .git/info/sparse-checkout
test_git_path GIT_COMMON_DIR=bar info//sparse-checkout    .git/info//sparse-checkout
test_git_path GIT_COMMON_DIR=bar remotes/bar              bar/remotes/bar
test_git_path GIT_COMMON_DIR=bar branches/bar             bar/branches/bar
test_git_path GIT_COMMON_DIR=bar logs/refs/heads/main     bar/logs/refs/heads/main
test_git_path GIT_COMMON_DIR=bar refs/heads/main          bar/refs/heads/main
test_git_path GIT_COMMON_DIR=bar refs/bisect/foo          .git/refs/bisect/foo
test_git_path GIT_COMMON_DIR=bar hooks/me                 bar/hooks/me
test_git_path GIT_COMMON_DIR=bar config                   bar/config
test_git_path GIT_COMMON_DIR=bar packed-refs              bar/packed-refs
test_git_path GIT_COMMON_DIR=bar shallow                  bar/shallow
test_git_path GIT_COMMON_DIR=bar common                   bar/common
test_git_path GIT_COMMON_DIR=bar common/file              bar/common/file

# In the tests below, $(pwd) must be used because it is a native path on
# Windows and avoids MSYS's path mangling (which simplifies "foo/../bar" and
# strips the dot from trailing "/.").

test_submodule_relative_url "../" "../foo" "../submodule" "../../submodule"
test_submodule_relative_url "../" "../foo/bar" "../submodule" "../../foo/submodule"
test_submodule_relative_url "../" "../foo/submodule" "../submodule" "../../foo/submodule"
test_submodule_relative_url "../" "./foo" "../submodule" "../submodule"
test_submodule_relative_url "../" "./foo/bar" "../submodule" "../foo/submodule"
test_submodule_relative_url "../../../" "../foo/bar" "../sub/a/b/c" "../../../../foo/sub/a/b/c"
test_submodule_relative_url "../" "$(pwd)/addtest" "../repo" "$(pwd)/repo"
test_submodule_relative_url "../" "foo/bar" "../submodule" "../foo/submodule"
test_submodule_relative_url "../" "foo" "../submodule" "../submodule"

test_submodule_relative_url "(null)" "../foo/bar" "../sub/a/b/c" "../foo/sub/a/b/c"
test_submodule_relative_url "(null)" "../foo/bar" "../sub/a/b/c/" "../foo/sub/a/b/c"
test_submodule_relative_url "(null)" "../foo/bar/" "../sub/a/b/c" "../foo/sub/a/b/c"
test_submodule_relative_url "(null)" "../foo/bar" "../submodule" "../foo/submodule"
test_submodule_relative_url "(null)" "../foo/submodule" "../submodule" "../foo/submodule"
test_submodule_relative_url "(null)" "../foo" "../submodule" "../submodule"
test_submodule_relative_url "(null)" "./foo/bar" "../submodule" "foo/submodule"
test_submodule_relative_url "(null)" "./foo" "../submodule" "submodule"
test_submodule_relative_url "(null)" "//somewhere else/repo" "../subrepo" "//somewhere else/subrepo"
test_submodule_relative_url "(null)" "//somewhere else/repo" "../../subrepo" "//subrepo"
test_submodule_relative_url "(null)" "//somewhere else/repo" "../../../subrepo" "/subrepo"
test_submodule_relative_url "(null)" "//somewhere else/repo" "../../../../subrepo" "subrepo"
test_submodule_relative_url "(null)" "$(pwd)/subsuper_update_r" "../subsubsuper_update_r" "$(pwd)/subsubsuper_update_r"
test_submodule_relative_url "(null)" "$(pwd)/super_update_r2" "../subsuper_update_r" "$(pwd)/subsuper_update_r"
test_submodule_relative_url "(null)" "$(pwd)/." "../." "$(pwd)/."
test_submodule_relative_url "(null)" "$(pwd)" "./." "$(pwd)/."
test_submodule_relative_url "(null)" "$(pwd)/addtest" "../repo" "$(pwd)/repo"
test_submodule_relative_url "(null)" "$(pwd)" "./å äö" "$(pwd)/å äö"
test_submodule_relative_url "(null)" "$(pwd)/." "../submodule" "$(pwd)/submodule"
test_submodule_relative_url "(null)" "$(pwd)/submodule" "../submodule" "$(pwd)/submodule"
test_submodule_relative_url "(null)" "$(pwd)/home2/../remote" "../bundle1" "$(pwd)/home2/../bundle1"
test_submodule_relative_url "(null)" "$(pwd)/submodule_update_repo" "./." "$(pwd)/submodule_update_repo/."
test_submodule_relative_url "(null)" "file:///tmp/repo" "../subrepo" "file:///tmp/subrepo"
test_submodule_relative_url "(null)" "foo/bar" "../submodule" "foo/submodule"
test_submodule_relative_url "(null)" "foo" "../submodule" "submodule"
test_submodule_relative_url "(null)" "helper:://hostname/repo" "../subrepo" "helper:://hostname/subrepo"
test_submodule_relative_url "(null)" "helper:://hostname/repo" "../../subrepo" "helper:://subrepo"
test_submodule_relative_url "(null)" "helper:://hostname/repo" "../../../subrepo" "helper::/subrepo"
test_submodule_relative_url "(null)" "helper:://hostname/repo" "../../../../subrepo" "helper::subrepo"
test_submodule_relative_url "(null)" "helper:://hostname/repo" "../../../../../subrepo" "helper:subrepo"
test_submodule_relative_url "(null)" "helper:://hostname/repo" "../../../../../../subrepo" ".:subrepo"
test_submodule_relative_url "(null)" "ssh://hostname/repo" "../subrepo" "ssh://hostname/subrepo"
test_submodule_relative_url "(null)" "ssh://hostname/repo" "../../subrepo" "ssh://subrepo"
test_submodule_relative_url "(null)" "ssh://hostname/repo" "../../../subrepo" "ssh:/subrepo"
test_submodule_relative_url "(null)" "ssh://hostname/repo" "../../../../subrepo" "ssh:subrepo"
test_submodule_relative_url "(null)" "ssh://hostname/repo" "../../../../../subrepo" ".:subrepo"
test_submodule_relative_url "(null)" "ssh://hostname:22/repo" "../subrepo" "ssh://hostname:22/subrepo"
test_submodule_relative_url "(null)" "user@host:path/to/repo" "../subrepo" "user@host:path/to/subrepo"
test_submodule_relative_url "(null)" "user@host:repo" "../subrepo" "user@host:subrepo"
test_submodule_relative_url "(null)" "user@host:repo" "../../subrepo" ".:subrepo"

test_expect_success 'match .gitmodules' '
	test-tool path-utils is_dotgitmodules \
		.gitmodules \
		\
		.git${u200c}modules \
		\
		.Gitmodules \
		.gitmoduleS \
		\
		".gitmodules " \
		".gitmodules." \
		".gitmodules  " \
		".gitmodules. " \
		".gitmodules ." \
		".gitmodules.." \
		".gitmodules   " \
		".gitmodules.  " \
		".gitmodules . " \
		".gitmodules  ." \
		\
		".Gitmodules " \
		".Gitmodules." \
		".Gitmodules  " \
		".Gitmodules. " \
		".Gitmodules ." \
		".Gitmodules.." \
		".Gitmodules   " \
		".Gitmodules.  " \
		".Gitmodules . " \
		".Gitmodules  ." \
		\
		GITMOD~1 \
		gitmod~1 \
		GITMOD~2 \
		gitmod~3 \
		GITMOD~4 \
		\
		"GITMOD~1 " \
		"gitmod~2." \
		"GITMOD~3  " \
		"gitmod~4. " \
		"GITMOD~1 ." \
		"gitmod~2   " \
		"GITMOD~3.  " \
		"gitmod~4 . " \
		\
		GI7EBA~1 \
		gi7eba~9 \
		\
		GI7EB~10 \
		GI7EB~11 \
		GI7EB~99 \
		GI7EB~10 \
		GI7E~100 \
		GI7E~101 \
		GI7E~999 \
		~1000000 \
		~9999999 \
		\
		.gitmodules:\$DATA \
		"gitmod~4 . :\$DATA" \
		\
		--not \
		".gitmodules x"  \
		".gitmodules .x" \
		\
		" .gitmodules" \
		\
		..gitmodules \
		\
		gitmodules \
		\
		.gitmodule \
		\
		".gitmodules x " \
		".gitmodules .x" \
		\
		GI7EBA~ \
		GI7EBA~0 \
		GI7EBA~~1 \
		GI7EBA~X \
		Gx7EBA~1 \
		GI7EBX~1 \
		\
		GI7EB~1 \
		GI7EB~01 \
		GI7EB~1X \
		\
		.gitmodules,:\$DATA
'

test_expect_success 'match .gitattributes' '
	test-tool path-utils is_dotgitattributes \
		.gitattributes \
		.git${u200c}attributes \
		.Gitattributes \
		.gitattributeS \
		GITATT~1 \
		GI7D29~1
'

test_expect_success 'match .gitignore' '
	test-tool path-utils is_dotgitignore \
		.gitignore \
		.git${u200c}ignore \
		.Gitignore \
		.gitignorE \
		GITIGN~1 \
		GI250A~1
'

test_expect_success 'match .mailmap' '
	test-tool path-utils is_dotmailmap \
		.mailmap \
		.mail${u200c}map \
		.Mailmap \
		.mailmaP \
		MAILMA~1 \
		MABA30~1
'

test_expect_success MINGW 'is_valid_path() on Windows' '
	test-tool path-utils is_valid_path \
		win32 \
		"win32 x" \
		../hello.txt \
		C:\\git \
		comm \
		conout.c \
		com0.c \
		lptN \
		\
		--not \
		"win32 "  \
		"win32 /x "  \
		"win32."  \
		"win32 . ." \
		.../hello.txt \
		colon:test \
		"AUX.c" \
		"abc/conOut\$  .xyz/test" \
		lpt8 \
		com9.c \
		"lpt*" \
		Nul \
		"PRN./abc"
'

test_lazy_prereq RUNTIME_PREFIX '
	test true = "$RUNTIME_PREFIX"
'

test_lazy_prereq CAN_EXEC_IN_PWD '
	cp "$GIT_EXEC_PATH"/git$X ./ &&
	./git rev-parse
'

test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD 'RUNTIME_PREFIX works' '
	mkdir -p pretend/bin pretend/libexec/git-core &&
	echo "echo HERE" | write_script pretend/libexec/git-core/git-here &&
	cp "$GIT_EXEC_PATH"/git$X pretend/bin/ &&
	GIT_EXEC_PATH= ./pretend/bin/git here >actual &&
	echo HERE >expect &&
	test_cmp expect actual'

test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD '%(prefix)/ works' '
	mkdir -p pretend/bin &&
	cp "$GIT_EXEC_PATH"/git$X pretend/bin/ &&
	git config yes.path "%(prefix)/yes" &&
	GIT_EXEC_PATH= ./pretend/bin/git config --path yes.path >actual &&
	echo "$(pwd)/pretend/yes" >expect &&
	test_cmp expect actual
'

test_expect_success 'do_files_match()' '
	test_seq 0 10 >0-10.txt &&
	test_seq -1 10 >-1-10.txt &&
	test_seq 1 10 >1-10.txt &&
	test_seq 1 9 >1-9.txt &&
	test_seq 0 8 >0-8.txt &&

	test-tool path-utils do_files_match 0-10.txt 0-10.txt >out &&

	assert_fails() {
		test_must_fail \
		test-tool path-utils do_files_match "$1" "$2" >out &&
		grep different out
	} &&

	assert_fails 0-8.txt 1-9.txt &&
	assert_fails -1-10.txt 0-10.txt &&
	assert_fails 1-10.txt 1-9.txt &&
	assert_fails 1-10.txt .git &&
	assert_fails does-not-exist 1-10.txt &&

	if test_have_prereq FILEMODE
	then
		cp 0-10.txt 0-10.x &&
		chmod a+x 0-10.x &&
		assert_fails 0-10.txt 0-10.x
	fi &&

	if test_have_prereq SYMLINKS
	then
		ln -sf 0-10.txt symlink &&
		ln -s 0-10.txt another-symlink &&
		ln -s over-the-ocean yet-another-symlink &&
		ln -s "$PWD/0-10.txt" absolute-symlink &&
		assert_fails 0-10.txt symlink &&
		test-tool path-utils do_files_match symlink another-symlink &&
		assert_fails symlink yet-another-symlink &&
		assert_fails symlink absolute-symlink
	fi
'

test_done