]>
Commit | Line | Data |
---|---|---|
76759c7d TB |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2012 Torsten Bögershausen | |
4 | # | |
5 | ||
6 | test_description='utf-8 decomposed (nfd) converted to precomposed (nfc)' | |
7 | ||
334afbc7 JS |
8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master |
9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME | |
10 | ||
76759c7d TB |
11 | . ./test-lib.sh |
12 | ||
308566eb MG |
13 | if ! test_have_prereq UTF8_NFD_TO_NFC |
14 | then | |
15 | skip_all="filesystem does not corrupt utf-8" | |
16 | test_done | |
17 | fi | |
18 | ||
19 | # create utf-8 variables | |
a4cf6b4b EP |
20 | Adiarnfc=$(printf '\303\204') |
21 | Adiarnfd=$(printf 'A\314\210') | |
76759c7d | 22 | |
a4cf6b4b EP |
23 | Odiarnfc=$(printf '\303\226') |
24 | Odiarnfd=$(printf 'O\314\210') | |
25 | AEligatu=$(printf '\303\206') | |
26 | Invalidu=$(printf '\303\377') | |
76759c7d TB |
27 | |
28 | ||
308566eb MG |
29 | #Create a string with 255 bytes (decomposed) |
30 | Alongd=$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd #21 Byte | |
31 | Alongd=$Alongd$Alongd$Alongd #63 Byte | |
32 | Alongd=$Alongd$Alongd$Alongd$Alongd$Adiarnfd #255 Byte | |
76759c7d | 33 | |
308566eb MG |
34 | #Create a string with 254 bytes (precomposed) |
35 | Alongc=$AEligatu$AEligatu$AEligatu$AEligatu$AEligatu #10 Byte | |
36 | Alongc=$Alongc$Alongc$Alongc$Alongc$Alongc #50 Byte | |
37 | Alongc=$Alongc$Alongc$Alongc$Alongc$Alongc #250 Byte | |
38 | Alongc=$Alongc$AEligatu$AEligatu #254 Byte | |
76759c7d | 39 | |
308566eb | 40 | test_expect_success "detect if nfd needed" ' |
a4cf6b4b | 41 | precomposeunicode=$(git config core.precomposeunicode) && |
92b0c8be | 42 | test "$precomposeunicode" = true && |
308566eb MG |
43 | git config core.precomposeunicode true |
44 | ' | |
45 | test_expect_success "setup" ' | |
46 | >x && | |
47 | git add x && | |
48 | git commit -m "1st commit" && | |
49 | git rm x && | |
50 | git commit -m "rm x" | |
51 | ' | |
52 | test_expect_success "setup case mac" ' | |
53 | git checkout -b mac_os | |
54 | ' | |
90a78b83 AR |
55 | # This will test nfd2nfc in git diff |
56 | test_expect_success "git diff f.Adiar" ' | |
57 | touch f.$Adiarnfc && | |
58 | git add f.$Adiarnfc && | |
59 | echo f.Adiarnfc >f.$Adiarnfc && | |
60 | git diff f.$Adiarnfd >expect && | |
61 | git diff f.$Adiarnfc >actual && | |
62 | test_cmp expect actual && | |
63 | git reset HEAD f.Adiarnfc && | |
64 | rm f.$Adiarnfc expect actual | |
65 | ' | |
66 | # This will test nfd2nfc in git diff-files | |
67 | test_expect_success "git diff-files f.Adiar" ' | |
68 | touch f.$Adiarnfc && | |
69 | git add f.$Adiarnfc && | |
70 | echo f.Adiarnfc >f.$Adiarnfc && | |
71 | git diff-files f.$Adiarnfd >expect && | |
72 | git diff-files f.$Adiarnfc >actual && | |
73 | test_cmp expect actual && | |
74 | git reset HEAD f.Adiarnfc && | |
75 | rm f.$Adiarnfc expect actual | |
76 | ' | |
77 | # This will test nfd2nfc in git diff-index | |
78 | test_expect_success "git diff-index f.Adiar" ' | |
79 | touch f.$Adiarnfc && | |
80 | git add f.$Adiarnfc && | |
81 | echo f.Adiarnfc >f.$Adiarnfc && | |
82 | git diff-index HEAD f.$Adiarnfd >expect && | |
83 | git diff-index HEAD f.$Adiarnfc >actual && | |
84 | test_cmp expect actual && | |
85 | git reset HEAD f.Adiarnfc && | |
86 | rm f.$Adiarnfc expect actual | |
87 | ' | |
308566eb MG |
88 | # This will test nfd2nfc in readdir() |
89 | test_expect_success "add file Adiarnfc" ' | |
90 | echo f.Adiarnfc >f.$Adiarnfc && | |
91 | git add f.$Adiarnfc && | |
92 | git commit -m "add f.$Adiarnfc" | |
93 | ' | |
90a78b83 AR |
94 | # This will test nfd2nfc in git diff-tree |
95 | test_expect_success "git diff-tree f.Adiar" ' | |
96 | echo f.Adiarnfc >>f.$Adiarnfc && | |
97 | git diff-tree HEAD f.$Adiarnfd >expect && | |
98 | git diff-tree HEAD f.$Adiarnfc >actual && | |
99 | test_cmp expect actual && | |
100 | git checkout f.$Adiarnfc && | |
101 | rm expect actual | |
102 | ' | |
308566eb MG |
103 | # This will test nfd2nfc in git stage() |
104 | test_expect_success "stage file d.Adiarnfd/f.Adiarnfd" ' | |
105 | mkdir d.$Adiarnfd && | |
106 | echo d.$Adiarnfd/f.$Adiarnfd >d.$Adiarnfd/f.$Adiarnfd && | |
107 | git stage d.$Adiarnfd/f.$Adiarnfd && | |
108 | git commit -m "add d.$Adiarnfd/f.$Adiarnfd" | |
109 | ' | |
110 | test_expect_success "add link Adiarnfc" ' | |
111 | ln -s d.$Adiarnfd/f.$Adiarnfd l.$Adiarnfc && | |
112 | git add l.$Adiarnfc && | |
113 | git commit -m "add l.Adiarnfc" | |
114 | ' | |
115 | # This will test git log | |
116 | test_expect_success "git log f.Adiar" ' | |
117 | git log f.$Adiarnfc > f.Adiarnfc.log && | |
118 | git log f.$Adiarnfd > f.Adiarnfd.log && | |
119 | test -s f.Adiarnfc.log && | |
120 | test -s f.Adiarnfd.log && | |
121 | test_cmp f.Adiarnfc.log f.Adiarnfd.log && | |
122 | rm f.Adiarnfc.log f.Adiarnfd.log | |
123 | ' | |
124 | # This will test git ls-files | |
125 | test_expect_success "git lsfiles f.Adiar" ' | |
126 | git ls-files f.$Adiarnfc > f.Adiarnfc.log && | |
127 | git ls-files f.$Adiarnfd > f.Adiarnfd.log && | |
128 | test -s f.Adiarnfc.log && | |
129 | test -s f.Adiarnfd.log && | |
130 | test_cmp f.Adiarnfc.log f.Adiarnfd.log && | |
131 | rm f.Adiarnfc.log f.Adiarnfd.log | |
132 | ' | |
133 | # This will test git mv | |
134 | test_expect_success "git mv" ' | |
135 | git mv f.$Adiarnfd f.$Odiarnfc && | |
136 | git mv d.$Adiarnfd d.$Odiarnfc && | |
137 | git mv l.$Adiarnfd l.$Odiarnfc && | |
138 | git commit -m "mv Adiarnfd Odiarnfc" | |
139 | ' | |
140 | # Files can be checked out as nfc | |
141 | # And the link has been corrected from nfd to nfc | |
142 | test_expect_success "git checkout nfc" ' | |
143 | rm f.$Odiarnfc && | |
144 | git checkout f.$Odiarnfc | |
145 | ' | |
146 | # Make it possible to checkout files with their NFD names | |
147 | test_expect_success "git checkout file nfd" ' | |
148 | rm -f f.* && | |
149 | git checkout f.$Odiarnfd | |
150 | ' | |
151 | # Make it possible to checkout links with their NFD names | |
152 | test_expect_success "git checkout link nfd" ' | |
153 | rm l.* && | |
154 | git checkout l.$Odiarnfd | |
155 | ' | |
156 | test_expect_success "setup case mac2" ' | |
157 | git checkout master && | |
158 | git reset --hard && | |
159 | git checkout -b mac_os_2 | |
160 | ' | |
161 | # This will test nfd2nfc in git commit | |
162 | test_expect_success "commit file d2.Adiarnfd/f.Adiarnfd" ' | |
163 | mkdir d2.$Adiarnfd && | |
164 | echo d2.$Adiarnfd/f.$Adiarnfd >d2.$Adiarnfd/f.$Adiarnfd && | |
165 | git add d2.$Adiarnfd/f.$Adiarnfd && | |
166 | git commit -m "add d2.$Adiarnfd/f.$Adiarnfd" -- d2.$Adiarnfd/f.$Adiarnfd | |
167 | ' | |
168 | test_expect_success "setup for long decomposed filename" ' | |
169 | git checkout master && | |
170 | git reset --hard && | |
171 | git checkout -b mac_os_long_nfd_fn | |
172 | ' | |
173 | test_expect_success "Add long decomposed filename" ' | |
174 | echo longd >$Alongd && | |
175 | git add * && | |
176 | git commit -m "Long filename" | |
177 | ' | |
178 | test_expect_success "setup for long precomposed filename" ' | |
179 | git checkout master && | |
180 | git reset --hard && | |
181 | git checkout -b mac_os_long_nfc_fn | |
182 | ' | |
183 | test_expect_success "Add long precomposed filename" ' | |
184 | echo longc >$Alongc && | |
185 | git add * && | |
186 | git commit -m "Long filename" | |
187 | ' | |
750b2e47 JK |
188 | |
189 | test_expect_failure 'handle existing decomposed filenames' ' | |
190 | echo content >"verbatim.$Adiarnfd" && | |
191 | git -c core.precomposeunicode=false add "verbatim.$Adiarnfd" && | |
192 | git commit -m "existing decomposed file" && | |
750b2e47 | 193 | git ls-files --exclude-standard -o "verbatim*" >untracked && |
d3c6751b | 194 | test_must_be_empty untracked |
750b2e47 JK |
195 | ' |
196 | ||
308566eb MG |
197 | # Test if the global core.precomposeunicode stops autosensing |
198 | # Must be the last test case | |
199 | test_expect_success "respect git config --global core.precomposeunicode" ' | |
200 | git config --global core.precomposeunicode true && | |
201 | rm -rf .git && | |
202 | git init && | |
a4cf6b4b | 203 | precomposeunicode=$(git config core.precomposeunicode) && |
308566eb MG |
204 | test "$precomposeunicode" = "true" |
205 | ' | |
76759c7d TB |
206 | |
207 | test_done |