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