]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3910-mac-os-precompose.sh
Doc: no midx and partial clone relation
[thirdparty/git.git] / t / t3910-mac-os-precompose.sh
CommitLineData
76759c7d
TB
1#!/bin/sh
2#
3# Copyright (c) 2012 Torsten Bögershausen
4#
5
6test_description='utf-8 decomposed (nfd) converted to precomposed (nfc)'
7
cbc75a12 8GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
9export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
76759c7d
TB
11. ./test-lib.sh
12
308566eb
MG
13if ! test_have_prereq UTF8_NFD_TO_NFC
14then
15 skip_all="filesystem does not corrupt utf-8"
16 test_done
17fi
18
19# create utf-8 variables
a4cf6b4b
EP
20Adiarnfc=$(printf '\303\204')
21Adiarnfd=$(printf 'A\314\210')
76759c7d 22
a4cf6b4b
EP
23Odiarnfc=$(printf '\303\226')
24Odiarnfd=$(printf 'O\314\210')
25AEligatu=$(printf '\303\206')
26Invalidu=$(printf '\303\377')
76759c7d
TB
27
28
308566eb
MG
29#Create a string with 255 bytes (decomposed)
30Alongd=$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd$Adiarnfd #21 Byte
31Alongd=$Alongd$Alongd$Alongd #63 Byte
32Alongd=$Alongd$Alongd$Alongd$Alongd$Adiarnfd #255 Byte
76759c7d 33
308566eb
MG
34#Create a string with 254 bytes (precomposed)
35Alongc=$AEligatu$AEligatu$AEligatu$AEligatu$AEligatu #10 Byte
36Alongc=$Alongc$Alongc$Alongc$Alongc$Alongc #50 Byte
37Alongc=$Alongc$Alongc$Alongc$Alongc$Alongc #250 Byte
38Alongc=$Alongc$AEligatu$AEligatu #254 Byte
76759c7d 39
308566eb 40test_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'
45test_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'
52test_expect_success "setup case mac" '
53 git checkout -b mac_os
54'
90a78b83
AR
55# This will test nfd2nfc in git diff
56test_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
67test_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
78test_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()
89test_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
95test_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()
104test_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'
110test_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
116test_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
125test_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
134test_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
142test_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
147test_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
152test_expect_success "git checkout link nfd" '
153 rm l.* &&
154 git checkout l.$Odiarnfd
155'
156test_expect_success "setup case mac2" '
cbc75a12 157 git checkout main &&
308566eb
MG
158 git reset --hard &&
159 git checkout -b mac_os_2
160'
161# This will test nfd2nfc in git commit
162test_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'
168test_expect_success "setup for long decomposed filename" '
cbc75a12 169 git checkout main &&
308566eb
MG
170 git reset --hard &&
171 git checkout -b mac_os_long_nfd_fn
172'
173test_expect_success "Add long decomposed filename" '
174 echo longd >$Alongd &&
175 git add * &&
176 git commit -m "Long filename"
177'
178test_expect_success "setup for long precomposed filename" '
cbc75a12 179 git checkout main &&
308566eb
MG
180 git reset --hard &&
181 git checkout -b mac_os_long_nfc_fn
182'
183test_expect_success "Add long precomposed filename" '
184 echo longc >$Alongc &&
185 git add * &&
186 git commit -m "Long filename"
187'
750b2e47
JK
188
189test_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
5c327502
TB
197test_expect_success "unicode decomposed: git restore -p . " '
198 DIRNAMEPWD=dir.Odiarnfc &&
199 DIRNAMEINREPO=dir.$Adiarnfc &&
200 export DIRNAMEPWD DIRNAMEINREPO &&
201 git init "$DIRNAMEPWD" &&
202 (
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 .
210 )
211'
212
308566eb
MG
213# Test if the global core.precomposeunicode stops autosensing
214# Must be the last test case
215test_expect_success "respect git config --global core.precomposeunicode" '
216 git config --global core.precomposeunicode true &&
217 rm -rf .git &&
218 git init &&
a4cf6b4b 219 precomposeunicode=$(git config core.precomposeunicode) &&
308566eb
MG
220 test "$precomposeunicode" = "true"
221'
76759c7d
TB
222
223test_done