Use the final_oid_fn to finalize hashing of object IDs
[alt-git.git] / t / t3910-mac-os-precompose.sh
blob898267a6bd1c8d1320c8e808707ba079c39933fe
1 #!/bin/sh
3 # Copyright (c) 2012 Torsten Bögershausen
6 test_description='utf-8 decomposed (nfd) converted to precomposed (nfc)'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 . ./test-lib.sh
13 if ! test_have_prereq UTF8_NFD_TO_NFC
14 then
15 skip_all="filesystem does not corrupt utf-8"
16 test_done
19 # create utf-8 variables
20 Adiarnfc=$(printf '\303\204')
21 Adiarnfd=$(printf 'A\314\210')
23 Odiarnfc=$(printf '\303\226')
24 Odiarnfd=$(printf 'O\314\210')
25 AEligatu=$(printf '\303\206')
26 Invalidu=$(printf '\303\377')
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
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
40 test_expect_success "detect if nfd needed" '
41 precomposeunicode=$(git config core.precomposeunicode) &&
42 test "$precomposeunicode" = true &&
43 git config core.precomposeunicode true
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"
52 test_expect_success "setup case mac" '
53 git checkout -b mac_os
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
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
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
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"
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
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"
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"
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
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
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"
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
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
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
156 test_expect_success "setup case mac2" '
157 git checkout main &&
158 git reset --hard &&
159 git checkout -b mac_os_2
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
168 test_expect_success "setup for long decomposed filename" '
169 git checkout main &&
170 git reset --hard &&
171 git checkout -b mac_os_long_nfd_fn
173 test_expect_success "Add long decomposed filename" '
174 echo longd >$Alongd &&
175 git add * &&
176 git commit -m "Long filename"
178 test_expect_success "setup for long precomposed filename" '
179 git checkout main &&
180 git reset --hard &&
181 git checkout -b mac_os_long_nfc_fn
183 test_expect_success "Add long precomposed filename" '
184 echo longc >$Alongc &&
185 git add * &&
186 git commit -m "Long filename"
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" &&
193 git ls-files --exclude-standard -o "verbatim*" >untracked &&
194 test_must_be_empty untracked
197 test_expect_success "unicode decomposed: git restore -p . " '
198 DIRNAMEPWD=dir.Odiarnfc &&
199 DIRNAMEINREPO=dir.$Adiarnfc &&
200 export DIRNAMEPWD DIRNAMEINREPO &&
201 git init "$DIRNAMEPWD" &&
203 cd "$DIRNAMEPWD" &&
204 mkdir "$DIRNAMEINREPO" &&
205 cd "$DIRNAMEINREPO" &&
206 echo "Initial" >file &&
207 git add file &&
208 echo "More stuff" >>file &&
209 echo y | git restore -p .
213 # Test if the global core.precomposeunicode stops autosensing
214 # Must be the last test case
215 test_expect_success "respect git config --global core.precomposeunicode" '
216 git config --global core.precomposeunicode true &&
217 rm -rf .git &&
218 git init &&
219 precomposeunicode=$(git config core.precomposeunicode) &&
220 test "$precomposeunicode" = "true"
223 test_done