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 readdir()
53 test_expect_success
"add file Adiarnfc" '
54 echo f.Adiarnfc >f.$Adiarnfc &&
55 git add f.$Adiarnfc &&
56 git commit -m "add f.$Adiarnfc"
58 # This will test nfd2nfc in git stage()
59 test_expect_success
"stage file d.Adiarnfd/f.Adiarnfd" '
61 echo d.$Adiarnfd/f.$Adiarnfd >d.$Adiarnfd/f.$Adiarnfd &&
62 git stage d.$Adiarnfd/f.$Adiarnfd &&
63 git commit -m "add d.$Adiarnfd/f.$Adiarnfd"
65 test_expect_success
"add link Adiarnfc" '
66 ln -s d.$Adiarnfd/f.$Adiarnfd l.$Adiarnfc &&
67 git add l.$Adiarnfc &&
68 git commit -m "add l.Adiarnfc"
70 # This will test git log
71 test_expect_success
"git log f.Adiar" '
72 git log f.$Adiarnfc > f.Adiarnfc.log &&
73 git log f.$Adiarnfd > f.Adiarnfd.log &&
74 test -s f.Adiarnfc.log &&
75 test -s f.Adiarnfd.log &&
76 test_cmp f.Adiarnfc.log f.Adiarnfd.log &&
77 rm f.Adiarnfc.log f.Adiarnfd.log
79 # This will test git ls-files
80 test_expect_success
"git lsfiles f.Adiar" '
81 git ls-files f.$Adiarnfc > f.Adiarnfc.log &&
82 git ls-files f.$Adiarnfd > f.Adiarnfd.log &&
83 test -s f.Adiarnfc.log &&
84 test -s f.Adiarnfd.log &&
85 test_cmp f.Adiarnfc.log f.Adiarnfd.log &&
86 rm f.Adiarnfc.log f.Adiarnfd.log
88 # This will test git mv
89 test_expect_success
"git mv" '
90 git mv f.$Adiarnfd f.$Odiarnfc &&
91 git mv d.$Adiarnfd d.$Odiarnfc &&
92 git mv l.$Adiarnfd l.$Odiarnfc &&
93 git commit -m "mv Adiarnfd Odiarnfc"
95 # Files can be checked out as nfc
96 # And the link has been corrected from nfd to nfc
97 test_expect_success
"git checkout nfc" '
99 git checkout f.$Odiarnfc
101 # Make it possible to checkout files with their NFD names
102 test_expect_success
"git checkout file nfd" '
104 git checkout f.$Odiarnfd
106 # Make it possible to checkout links with their NFD names
107 test_expect_success
"git checkout link nfd" '
109 git checkout l.$Odiarnfd
111 test_expect_success
"setup case mac2" '
112 git checkout master &&
114 git checkout -b mac_os_2
116 # This will test nfd2nfc in git commit
117 test_expect_success
"commit file d2.Adiarnfd/f.Adiarnfd" '
118 mkdir d2.$Adiarnfd &&
119 echo d2.$Adiarnfd/f.$Adiarnfd >d2.$Adiarnfd/f.$Adiarnfd &&
120 git add d2.$Adiarnfd/f.$Adiarnfd &&
121 git commit -m "add d2.$Adiarnfd/f.$Adiarnfd" -- d2.$Adiarnfd/f.$Adiarnfd
123 test_expect_success
"setup for long decomposed filename" '
124 git checkout master &&
126 git checkout -b mac_os_long_nfd_fn
128 test_expect_success
"Add long decomposed filename" '
129 echo longd >$Alongd &&
131 git commit -m "Long filename"
133 test_expect_success
"setup for long precomposed filename" '
134 git checkout master &&
136 git checkout -b mac_os_long_nfc_fn
138 test_expect_success
"Add long precomposed filename" '
139 echo longc >$Alongc &&
141 git commit -m "Long filename"
144 test_expect_failure
'handle existing decomposed filenames' '
145 echo content >"verbatim.$Adiarnfd" &&
146 git -c core.precomposeunicode=false add "verbatim.$Adiarnfd" &&
147 git commit -m "existing decomposed file" &&
149 git ls-files --exclude-standard -o "verbatim*" >untracked &&
150 test_cmp expect untracked
153 # Test if the global core.precomposeunicode stops autosensing
154 # Must be the last test case
155 test_expect_success
"respect git config --global core.precomposeunicode" '
156 git config --global core.precomposeunicode true &&
159 precomposeunicode=$(git config core.precomposeunicode) &&
160 test "$precomposeunicode" = "true"