3 # Copyright (c) 2006 Junio C Hamano
6 test_description
='i18n settings and format-patch | am pipe'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 TEST_PASSES_SANITIZE_LEAK
=true
14 if ! test_have_prereq ICONV
16 skip_all
='skipping patch i18n tests; iconv not available'
21 # Make sure characters are not corrupted
22 cnt
="$1" header
="$2" i
=1 j
=0
23 while test "$i" -le $cnt
25 git format-patch
--encoding=UTF-8
--stdout HEAD~
$i..HEAD~
$j |
26 grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" &&
27 git cat-file commit HEAD~
$j |
30 grep "^encoding ISO8859-1" ;;
32 grep "^encoding ISO8859-1"; test "$?" != 0 ;;
39 test_expect_success setup
'
40 git config i18n.commitencoding UTF-8 &&
42 # use UTF-8 in author and committer name to match the
43 # i18n.commitencoding settings
44 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
47 echo "$GIT_AUTHOR_NAME" >mine &&
49 git commit -s -m "Initial commit" &&
52 echo Hello world >mine &&
54 git commit -s -m "Second on main" &&
56 # the first commit on the side branch is UTF-8
58 git checkout -b side main^ &&
59 echo Another file >yours &&
61 git commit -s -m "Second on side" &&
63 if test_have_prereq !MINGW
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
71 echo Yet another >theirs &&
73 git commit -s -m "Third on side" &&
76 git config i18n.commitencoding UTF-8
79 test_expect_success
'format-patch output (ISO-8859-1)' '
80 git config i18n.logoutputencoding ISO8859-1 &&
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
90 test_expect_success
'format-patch output (UTF-8)' '
91 git config i18n.logoutputencoding UTF-8 &&
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
101 test_expect_success
'rebase (U/U)' '
102 # We want the result of rebase in UTF-8
103 git config i18n.commitencoding UTF-8 &&
105 # The test is about logoutputencoding not affecting the
106 # final outcome -- it is used internally to generate the
109 git config i18n.logoutputencoding UTF-8 &&
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 &&
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 &&
125 git reset --hard side &&
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 &&
137 git reset --hard side &&
140 check_encoding 2 8859
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 &&
150 git reset --hard side &&
153 check_encoding 2 8859
156 test_expect_success
'cherry-pick(U/U)' '
157 # Both the commitencoding and logoutputencoding is set to UTF-8.
159 git config i18n.commitencoding UTF-8 &&
160 git config i18n.logoutputencoding UTF-8 &&
161 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
163 git reset --hard main &&
164 git cherry-pick side^ &&
165 git cherry-pick side &&
171 test_expect_success
!MINGW
'cherry-pick(L/L)' '
172 # Both the commitencoding and logoutputencoding is set to ISO-8859-1
174 git config i18n.commitencoding ISO8859-1 &&
175 git config i18n.logoutputencoding ISO8859-1 &&
176 . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
178 git reset --hard main &&
179 git cherry-pick side^ &&
180 git cherry-pick side &&
183 check_encoding 3 8859
186 test_expect_success
'cherry-pick(U/L)' '
187 # Commitencoding is set to UTF-8 but logoutputencoding is ISO-8859-1
189 git config i18n.commitencoding UTF-8 &&
190 git config i18n.logoutputencoding ISO8859-1 &&
191 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
193 git reset --hard main &&
194 git cherry-pick side^ &&
195 git cherry-pick side &&
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.
205 git config i18n.commitencoding ISO8859-1 &&
206 git config i18n.logoutputencoding UTF-8 &&
207 . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
209 git reset --hard main &&
210 git cherry-pick side^ &&
211 git cherry-pick side &&
214 check_encoding 3 8859
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 &&
222 git reset --hard side &&
223 git rebase --merge main &&
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 &&
233 git reset --hard side &&
234 git rebase --merge main &&
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 &&
245 git reset --hard side &&
246 git rebase --merge main &&
248 check_encoding 2 8859
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 &&
258 git reset --hard side &&
259 git rebase --merge main &&
261 check_encoding 2 8859
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 &&
269 git reset --hard main &&
270 git am out-u1 out-u2 &&
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 &&
280 git reset --hard main &&
281 git am out-l1 out-l2 &&
283 check_encoding 2 8859
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 &&
292 # am specifies --utf8 by default.
293 git am out-l1 out-l2 &&
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 &&
303 git reset --hard main &&
304 git am --no-utf8 out-l1 out-l2 2>err &&
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 &&
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 &&
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 &&
323 check_encoding 2 8859