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