1#!/bin/sh
2
3test_description='Various filesystem issues'
4
5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8. ./test-lib.sh
9
10auml=$(printf '\303\244')
11aumlcdiar=$(printf '\141\314\210')
12
13if test_have_prereq CASE_INSENSITIVE_FS
14then
15	say "will test on a case insensitive filesystem"
16	test_case=test_expect_failure
17else
18	test_case=test_expect_success
19fi
20
21if test_have_prereq UTF8_NFD_TO_NFC
22then
23	say "will test on a unicode corrupting filesystem"
24	test_unicode=test_expect_failure
25else
26	test_unicode=test_expect_success
27fi
28
29test_have_prereq SYMLINKS ||
30	say "will test on a filesystem lacking symbolic links"
31
32if test_have_prereq CASE_INSENSITIVE_FS
33then
34test_expect_success "detection of case insensitive filesystem during repo init" '
35	test $(git config --bool core.ignorecase) = true
36'
37else
38test_expect_success "detection of case insensitive filesystem during repo init" '
39	{
40		test_must_fail git config --bool core.ignorecase >/dev/null ||
41			test $(git config --bool core.ignorecase) = false
42	}
43'
44fi
45
46if test_have_prereq SYMLINKS
47then
48test_expect_success "detection of filesystem w/o symlink support during repo init" '
49	{
50		test_must_fail git config --bool core.symlinks ||
51		test "$(git config --bool core.symlinks)" = true
52	}
53'
54else
55test_expect_success "detection of filesystem w/o symlink support during repo init" '
56	v=$(git config --bool core.symlinks) &&
57	test "$v" = false
58'
59fi
60
61test_expect_success "setup case tests" '
62	git config core.ignorecase true &&
63	touch camelcase &&
64	git add camelcase &&
65	git commit -m "initial" &&
66	git tag initial &&
67	git checkout -b topic &&
68	git mv camelcase tmp &&
69	git mv tmp CamelCase &&
70	git commit -m "rename" &&
71	git checkout -f main
72'
73
74test_expect_success 'rename (case change)' '
75	git mv camelcase CamelCase &&
76	git commit -m "rename"
77'
78
79test_expect_success 'merge (case change)' '
80	rm -f CamelCase &&
81	rm -f camelcase &&
82	git reset --hard initial &&
83	git merge topic
84'
85
86test_expect_success CASE_INSENSITIVE_FS 'add directory (with different case)' '
87	git reset --hard initial &&
88	mkdir -p dir1/dir2 &&
89	echo >dir1/dir2/a &&
90	echo >dir1/dir2/b &&
91	git add dir1/dir2/a &&
92	git add dir1/DIR2/b &&
93	git ls-files >actual &&
94	cat >expected <<-\EOF &&
95		camelcase
96		dir1/dir2/a
97		dir1/dir2/b
98	EOF
99	test_cmp expected actual
100'
101
102test_expect_failure CASE_INSENSITIVE_FS 'add (with different case)' '
103	git reset --hard initial &&
104	rm camelcase &&
105	echo 1 >CamelCase &&
106	git add CamelCase &&
107	camel=$(git ls-files | grep -i camelcase) &&
108	test $(echo "$camel" | wc -l) = 1 &&
109	test "z$(git cat-file blob :$camel)" = z1
110'
111
112test_expect_success "setup unicode normalization tests" '
113	test_create_repo unicode &&
114	cd unicode &&
115	git config core.precomposeunicode false &&
116	touch "$aumlcdiar" &&
117	git add "$aumlcdiar" &&
118	git commit -m initial &&
119	git tag initial &&
120	git checkout -b topic &&
121	git mv $aumlcdiar tmp &&
122	git mv tmp "$auml" &&
123	git commit -m rename &&
124	git checkout -f main
125'
126
127$test_unicode 'rename (silent unicode normalization)' '
128	git mv "$aumlcdiar" "$auml" &&
129	git commit -m rename
130'
131
132$test_unicode 'merge (silent unicode normalization)' '
133	git reset --hard initial &&
134	git merge topic
135'
136
137test_expect_success CASE_INSENSITIVE_FS 'checkout with no pathspec and a case insensitive fs' '
138	git init repo &&
139	(
140		cd repo &&
141
142		>Gitweb &&
143		git add Gitweb &&
144		git commit -m "add Gitweb" &&
145
146		git checkout --orphan todo &&
147		git reset --hard &&
148		mkdir -p gitweb/subdir &&
149		>gitweb/subdir/file &&
150		git add gitweb &&
151		git commit -m "add gitweb/subdir/file" &&
152
153		git checkout main
154	)
155'
156
157test_done
158