3 # Copyright (c) 2012 Torsten Bögershausen
6 test_description
='utf-8 decomposed (nfd) converted to precomposed (nfc)'
10 if ! test_have_prereq UTF8_NFD_TO_NFC
12 skip_all
="filesystem does not corrupt utf-8"
16 # create utf-8 variables
17 Adiarnfc
=$
(printf '\303\204')
18 Adiarnfd
=$
(printf 'A\314\210')
20 Odiarnfc
=$
(printf '\303\226')
21 Odiarnfd
=$
(printf 'O\314\210')
22 AEligatu
=$
(printf '\303\206')
23 Invalidu
=$
(printf '\303\377')
26 #Create a string with 255 bytes (decomposed)
27 Alongd
=$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd #21 Byte
28 Alongd
=$Alongd$Alongd$Alongd #63 Byte
29 Alongd
=$Alongd$Alongd$Alongd$Alongd$Adiarnfd #255 Byte
31 #Create a string with 254 bytes (precomposed)
32 Alongc
=$AEligatu$AEligatu$AEligatu$AEligatu$AEligatu #10 Byte
33 Alongc
=$Alongc$Alongc$Alongc$Alongc$Alongc #50 Byte
34 Alongc
=$Alongc$Alongc$Alongc$Alongc$Alongc #250 Byte
35 Alongc
=$Alongc$AEligatu$AEligatu #254 Byte
37 test_expect_success
"detect if nfd needed" '
38 precomposeunicode=$(git config core.precomposeunicode) &&
39 test "$precomposeunicode" = true &&
40 git config core.precomposeunicode true
42 test_expect_success
"setup" '
45 git commit -m "1st commit" &&
49 test_expect_success
"setup case mac" '
50 git checkout -b mac_os
52 # This will test nfd2nfc in git diff
53 test_expect_success
"git diff f.Adiar" '
55 git add f.$Adiarnfc &&
56 echo f.Adiarnfc >f.$Adiarnfc &&
57 git diff f.$Adiarnfd >expect &&
58 git diff f.$Adiarnfc >actual &&
59 test_cmp expect actual &&
60 git reset HEAD f.Adiarnfc &&
61 rm f.$Adiarnfc expect actual
63 # This will test nfd2nfc in git diff-files
64 test_expect_success
"git diff-files f.Adiar" '
66 git add f.$Adiarnfc &&
67 echo f.Adiarnfc >f.$Adiarnfc &&
68 git diff-files f.$Adiarnfd >expect &&
69 git diff-files f.$Adiarnfc >actual &&
70 test_cmp expect actual &&
71 git reset HEAD f.Adiarnfc &&
72 rm f.$Adiarnfc expect actual
74 # This will test nfd2nfc in git diff-index
75 test_expect_success
"git diff-index f.Adiar" '
77 git add f.$Adiarnfc &&
78 echo f.Adiarnfc >f.$Adiarnfc &&
79 git diff-index HEAD f.$Adiarnfd >expect &&
80 git diff-index HEAD f.$Adiarnfc >actual &&
81 test_cmp expect actual &&
82 git reset HEAD f.Adiarnfc &&
83 rm f.$Adiarnfc expect actual
85 # This will test nfd2nfc in readdir()
86 test_expect_success
"add file Adiarnfc" '
87 echo f.Adiarnfc >f.$Adiarnfc &&
88 git add f.$Adiarnfc &&
89 git commit -m "add f.$Adiarnfc"
91 # This will test nfd2nfc in git diff-tree
92 test_expect_success
"git diff-tree f.Adiar" '
93 echo f.Adiarnfc >>f.$Adiarnfc &&
94 git diff-tree HEAD f.$Adiarnfd >expect &&
95 git diff-tree HEAD f.$Adiarnfc >actual &&
96 test_cmp expect actual &&
97 git checkout f.$Adiarnfc &&
100 # This will test nfd2nfc in git stage()
101 test_expect_success
"stage file d.Adiarnfd/f.Adiarnfd" '
103 echo d.$Adiarnfd/f.$Adiarnfd >d.$Adiarnfd/f.$Adiarnfd &&
104 git stage d.$Adiarnfd/f.$Adiarnfd &&
105 git commit -m "add d.$Adiarnfd/f.$Adiarnfd"
107 test_expect_success
"add link Adiarnfc" '
108 ln -s d.$Adiarnfd/f.$Adiarnfd l.$Adiarnfc &&
109 git add l.$Adiarnfc &&
110 git commit -m "add l.Adiarnfc"
112 # This will test git log
113 test_expect_success
"git log f.Adiar" '
114 git log f.$Adiarnfc > f.Adiarnfc.log &&
115 git log f.$Adiarnfd > f.Adiarnfd.log &&
116 test -s f.Adiarnfc.log &&
117 test -s f.Adiarnfd.log &&
118 test_cmp f.Adiarnfc.log f.Adiarnfd.log &&
119 rm f.Adiarnfc.log f.Adiarnfd.log
121 # This will test git ls-files
122 test_expect_success
"git lsfiles f.Adiar" '
123 git ls-files f.$Adiarnfc > f.Adiarnfc.log &&
124 git ls-files f.$Adiarnfd > f.Adiarnfd.log &&
125 test -s f.Adiarnfc.log &&
126 test -s f.Adiarnfd.log &&
127 test_cmp f.Adiarnfc.log f.Adiarnfd.log &&
128 rm f.Adiarnfc.log f.Adiarnfd.log
130 # This will test git mv
131 test_expect_success
"git mv" '
132 git mv f.$Adiarnfd f.$Odiarnfc &&
133 git mv d.$Adiarnfd d.$Odiarnfc &&
134 git mv l.$Adiarnfd l.$Odiarnfc &&
135 git commit -m "mv Adiarnfd Odiarnfc"
137 # Files can be checked out as nfc
138 # And the link has been corrected from nfd to nfc
139 test_expect_success
"git checkout nfc" '
141 git checkout f.$Odiarnfc
143 # Make it possible to checkout files with their NFD names
144 test_expect_success
"git checkout file nfd" '
146 git checkout f.$Odiarnfd
148 # Make it possible to checkout links with their NFD names
149 test_expect_success
"git checkout link nfd" '
151 git checkout l.$Odiarnfd
153 test_expect_success
"setup case mac2" '
154 git checkout master &&
156 git checkout -b mac_os_2
158 # This will test nfd2nfc in git commit
159 test_expect_success
"commit file d2.Adiarnfd/f.Adiarnfd" '
160 mkdir d2.$Adiarnfd &&
161 echo d2.$Adiarnfd/f.$Adiarnfd >d2.$Adiarnfd/f.$Adiarnfd &&
162 git add d2.$Adiarnfd/f.$Adiarnfd &&
163 git commit -m "add d2.$Adiarnfd/f.$Adiarnfd" -- d2.$Adiarnfd/f.$Adiarnfd
165 test_expect_success
"setup for long decomposed filename" '
166 git checkout master &&
168 git checkout -b mac_os_long_nfd_fn
170 test_expect_success
"Add long decomposed filename" '
171 echo longd >$Alongd &&
173 git commit -m "Long filename"
175 test_expect_success
"setup for long precomposed filename" '
176 git checkout master &&
178 git checkout -b mac_os_long_nfc_fn
180 test_expect_success
"Add long precomposed filename" '
181 echo longc >$Alongc &&
183 git commit -m "Long filename"
186 test_expect_failure
'handle existing decomposed filenames' '
187 echo content >"verbatim.$Adiarnfd" &&
188 git -c core.precomposeunicode=false add "verbatim.$Adiarnfd" &&
189 git commit -m "existing decomposed file" &&
191 git ls-files --exclude-standard -o "verbatim*" >untracked &&
192 test_cmp expect untracked
195 # Test if the global core.precomposeunicode stops autosensing
196 # Must be the last test case
197 test_expect_success
"respect git config --global core.precomposeunicode" '
198 git config --global core.precomposeunicode true &&
201 precomposeunicode=$(git config core.precomposeunicode) &&
202 test "$precomposeunicode" = "true"