Git 2.32
[git] / t / t0050-filesystem.sh
1 #!/bin/sh
2
3 test_description='Various filesystem issues'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 auml=$(printf '\303\244')
11 aumlcdiar=$(printf '\141\314\210')
12
13 if test_have_prereq CASE_INSENSITIVE_FS
14 then
15         say "will test on a case insensitive filesystem"
16         test_case=test_expect_failure
17 else
18         test_case=test_expect_success
19 fi
20
21 if test_have_prereq UTF8_NFD_TO_NFC
22 then
23         say "will test on a unicode corrupting filesystem"
24         test_unicode=test_expect_failure
25 else
26         test_unicode=test_expect_success
27 fi
28
29 test_have_prereq SYMLINKS ||
30         say "will test on a filesystem lacking symbolic links"
31
32 if test_have_prereq CASE_INSENSITIVE_FS
33 then
34 test_expect_success "detection of case insensitive filesystem during repo init" '
35         test $(git config --bool core.ignorecase) = true
36 '
37 else
38 test_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 '
44 fi
45
46 if test_have_prereq SYMLINKS
47 then
48 test_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 '
54 else
55 test_expect_success "detection of filesystem w/o symlink support during repo init" '
56         v=$(git config --bool core.symlinks) &&
57         test "$v" = false
58 '
59 fi
60
61 test_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
74 test_expect_success 'rename (case change)' '
75         git mv camelcase CamelCase &&
76         git commit -m "rename"
77 '
78
79 test_expect_success 'merge (case change)' '
80         rm -f CamelCase &&
81         rm -f camelcase &&
82         git reset --hard initial &&
83         git merge topic
84 '
85
86 test_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
102 test_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
112 test_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
137 test_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
157 test_done