Raw
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Junio C Hamano
4 #
5
6 test_description='i18n settings and format-patch | am pipe'
7
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
11 . ./test-lib.sh
12
13 if ! test_have_prereq ICONV
14 then
15 skip_all='skipping patch i18n tests; iconv not available'
16 test_done
17 fi
18
19 check_encoding () {
20 # Make sure characters are not corrupted
21 cnt="$1" header="$2" i=1 j=0
22 while test "$i" -le $cnt
23 do
24 git format-patch --encoding=UTF-8 --stdout HEAD~$i..HEAD~$j |
25 grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" &&
26 git cat-file commit HEAD~$j |
27 case "$header" in
28 8859)
29 grep "^encoding ISO8859-1" ;;
30 *)
31 ret=0; grep "^encoding ISO8859-1" || ret=$?
32 test "$ret" != 0 ;;
33 esac || return 1
34 j=$i
35 i=$(($i+1))
36 done
37 }
38
39 test_expect_success setup '
40 git config i18n.commitencoding UTF-8 &&
41
42 # use UTF-8 in author and committer name to match the
43 # i18n.commitencoding settings
44 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
45
46 test_tick &&
47 echo "$GIT_AUTHOR_NAME" >mine &&
48 git add mine &&
49 git commit -s -m "Initial commit" &&
50
51 test_tick &&
52 echo Hello world >mine &&
53 git add mine &&
54 git commit -s -m "Second on main" &&
55
56 # the first commit on the side branch is UTF-8
57 test_tick &&
58 git checkout -b side main^ &&
59 echo Another file >yours &&
60 git add yours &&
61 git commit -s -m "Second on side" &&
62
63 if test_have_prereq !MINGW
64 then
65 # the second one on the side branch is ISO-8859-1
66 git config i18n.commitencoding ISO8859-1 &&
67 # use author and committer name in ISO-8859-1 to match it.
68 . "$TEST_DIRECTORY"/t3901/8859-1.txt
69 fi &&
70 test_tick &&
71 echo Yet another >theirs &&
72 git add theirs &&
73 git commit -s -m "Third on side" &&
74
75 # Back to default
76 git config i18n.commitencoding UTF-8
77 '
78
79 test_expect_success 'format-patch output (ISO-8859-1)' '
80 git config i18n.logoutputencoding ISO8859-1 &&
81
82 git format-patch --stdout main..HEAD^ >out-l1 &&
83 git format-patch --stdout HEAD^ >out-l2 &&
84 grep "^Content-Type: text/plain; charset=ISO8859-1" out-l1 &&
85 grep "^From: =?ISO8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l1 &&
86 grep "^Content-Type: text/plain; charset=ISO8859-1" out-l2 &&
87 grep "^From: =?ISO8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l2
88 '
89
90 test_expect_success 'format-patch output (UTF-8)' '
91 git config i18n.logoutputencoding UTF-8 &&
92
93 git format-patch --stdout main..HEAD^ >out-u1 &&
94 git format-patch --stdout HEAD^ >out-u2 &&
95 grep "^Content-Type: text/plain; charset=UTF-8" out-u1 &&
96 grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" out-u1 &&
97 grep "^Content-Type: text/plain; charset=UTF-8" out-u2 &&
98 grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" out-u2
99 '
100
101 test_expect_success 'rebase (U/U)' '
102 # We want the result of rebase in UTF-8
103 git config i18n.commitencoding UTF-8 &&
104
105 # The test is about logoutputencoding not affecting the
106 # final outcome -- it is used internally to generate the
107 # patch and the log.
108
109 git config i18n.logoutputencoding UTF-8 &&
110
111 # The result will be committed by GIT_COMMITTER_NAME --
112 # we want UTF-8 encoded name.
113 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
114 git checkout -b test &&
115 git rebase main &&
116
117 check_encoding 2
118 '
119
120 test_expect_success 'rebase (U/L)' '
121 git config i18n.commitencoding UTF-8 &&
122 git config i18n.logoutputencoding ISO8859-1 &&
123 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
124
125 git reset --hard side &&
126 git rebase main &&
127
128 check_encoding 2
129 '
130
131 test_expect_success !MINGW 'rebase (L/L)' '
132 # In this test we want ISO-8859-1 encoded commits as the result
133 git config i18n.commitencoding ISO8859-1 &&
134 git config i18n.logoutputencoding ISO8859-1 &&
135 . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
136
137 git reset --hard side &&
138 git rebase main &&
139
140 check_encoding 2 8859
141 '
142
143 test_expect_success !MINGW 'rebase (L/U)' '
144 # This is pathological -- use UTF-8 as intermediate form
145 # to get ISO-8859-1 results.
146 git config i18n.commitencoding ISO8859-1 &&
147 git config i18n.logoutputencoding UTF-8 &&
148 . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
149
150 git reset --hard side &&
151 git rebase main &&
152
153 check_encoding 2 8859
154 '
155
156 test_expect_success 'cherry-pick(U/U)' '
157 # Both the commitencoding and logoutputencoding is set to UTF-8.
158
159 git config i18n.commitencoding UTF-8 &&
160 git config i18n.logoutputencoding UTF-8 &&
161 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
162
163 git reset --hard main &&
164 git cherry-pick side^ &&
165 git cherry-pick side &&
166 git revert HEAD &&
167
168 check_encoding 3
169 '
170
171 test_expect_success !MINGW 'cherry-pick(L/L)' '
172 # Both the commitencoding and logoutputencoding is set to ISO-8859-1
173
174 git config i18n.commitencoding ISO8859-1 &&
175 git config i18n.logoutputencoding ISO8859-1 &&
176 . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
177
178 git reset --hard main &&
179 git cherry-pick side^ &&
180 git cherry-pick side &&
181 git revert HEAD &&
182
183 check_encoding 3 8859
184 '
185
186 test_expect_success 'cherry-pick(U/L)' '
187 # Commitencoding is set to UTF-8 but logoutputencoding is ISO-8859-1
188
189 git config i18n.commitencoding UTF-8 &&
190 git config i18n.logoutputencoding ISO8859-1 &&
191 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
192
193 git reset --hard main &&
194 git cherry-pick side^ &&
195 git cherry-pick side &&
196 git revert HEAD &&
197
198 check_encoding 3
199 '
200
201 test_expect_success !MINGW 'cherry-pick(L/U)' '
202 # Again, the commitencoding is set to ISO-8859-1 but
203 # logoutputencoding is set to UTF-8.
204
205 git config i18n.commitencoding ISO8859-1 &&
206 git config i18n.logoutputencoding UTF-8 &&
207 . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
208
209 git reset --hard main &&
210 git cherry-pick side^ &&
211 git cherry-pick side &&
212 git revert HEAD &&
213
214 check_encoding 3 8859
215 '
216
217 test_expect_success 'rebase --merge (U/U)' '
218 git config i18n.commitencoding UTF-8 &&
219 git config i18n.logoutputencoding UTF-8 &&
220 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
221
222 git reset --hard side &&
223 git rebase --merge main &&
224
225 check_encoding 2
226 '
227
228 test_expect_success 'rebase --merge (U/L)' '
229 git config i18n.commitencoding UTF-8 &&
230 git config i18n.logoutputencoding ISO8859-1 &&
231 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
232
233 git reset --hard side &&
234 git rebase --merge main &&
235
236 check_encoding 2
237 '
238
239 test_expect_success 'rebase --merge (L/L)' '
240 # In this test we want ISO-8859-1 encoded commits as the result
241 git config i18n.commitencoding ISO8859-1 &&
242 git config i18n.logoutputencoding ISO8859-1 &&
243 . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
244
245 git reset --hard side &&
246 git rebase --merge main &&
247
248 check_encoding 2 8859
249 '
250
251 test_expect_success 'rebase --merge (L/U)' '
252 # This is pathological -- use UTF-8 as intermediate form
253 # to get ISO-8859-1 results.
254 git config i18n.commitencoding ISO8859-1 &&
255 git config i18n.logoutputencoding UTF-8 &&
256 . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
257
258 git reset --hard side &&
259 git rebase --merge main &&
260
261 check_encoding 2 8859
262 '
263
264 test_expect_success 'am (U/U)' '
265 # Apply UTF-8 patches with UTF-8 commitencoding
266 git config i18n.commitencoding UTF-8 &&
267 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
268
269 git reset --hard main &&
270 git am out-u1 out-u2 &&
271
272 check_encoding 2
273 '
274
275 test_expect_success !MINGW 'am (L/L)' '
276 # Apply ISO-8859-1 patches with ISO-8859-1 commitencoding
277 git config i18n.commitencoding ISO8859-1 &&
278 . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
279
280 git reset --hard main &&
281 git am out-l1 out-l2 &&
282
283 check_encoding 2 8859
284 '
285
286 test_expect_success 'am (U/L)' '
287 # Apply ISO-8859-1 patches with UTF-8 commitencoding
288 git config i18n.commitencoding UTF-8 &&
289 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
290 git reset --hard main &&
291
292 # am specifies --utf8 by default.
293 git am out-l1 out-l2 &&
294
295 check_encoding 2
296 '
297
298 test_expect_success 'am --no-utf8 (U/L)' '
299 # Apply ISO-8859-1 patches with UTF-8 commitencoding
300 git config i18n.commitencoding UTF-8 &&
301 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
302
303 git reset --hard main &&
304 git am --no-utf8 out-l1 out-l2 2>err &&
305
306 # commit-tree will warn that the commit message does not contain valid UTF-8
307 # as mailinfo did not convert it
308 test_grep "did not conform" err &&
309
310 check_encoding 2
311 '
312
313 test_expect_success !MINGW 'am (L/U)' '
314 # Apply UTF-8 patches with ISO-8859-1 commitencoding
315 git config i18n.commitencoding ISO8859-1 &&
316 . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
317
318 git reset --hard main &&
319 # mailinfo will re-code the commit message to the charset specified by
320 # i18n.commitencoding
321 git am out-u1 out-u2 &&
322
323 check_encoding 2 8859
324 '
325
326 test_done