The eleventh batch
[git/gitster.git] / t / t3901-i18n-patch.sh
blobe0659c92935e7f7582e03fd1121df7488e0e2b4a
1 #!/bin/sh
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
12 . ./test-lib.sh
14 if ! test_have_prereq ICONV
15 then
16 skip_all='skipping patch i18n tests; iconv not available'
17 test_done
20 check_encoding () {
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 |
28 case "$header" in
29 8859)
30 grep "^encoding ISO8859-1" ;;
32 grep "^encoding ISO8859-1"; test "$?" != 0 ;;
33 esac || return 1
34 j=$i
35 i=$(($i+1))
36 done
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 &&
46 test_tick &&
47 echo "$GIT_AUTHOR_NAME" >mine &&
48 git add mine &&
49 git commit -s -m "Initial commit" &&
51 test_tick &&
52 echo Hello world >mine &&
53 git add mine &&
54 git commit -s -m "Second on main" &&
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" &&
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" &&
75 # Back to default
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
107 # patch and the log.
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 &&
115 git rebase main &&
117 check_encoding 2
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 &&
126 git rebase main &&
128 check_encoding 2
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 &&
138 git rebase main &&
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 &&
151 git rebase main &&
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 &&
166 git revert HEAD &&
168 check_encoding 3
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 &&
181 git revert HEAD &&
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 &&
196 git revert HEAD &&
198 check_encoding 3
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 &&
212 git revert HEAD &&
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 &&
225 check_encoding 2
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 &&
236 check_encoding 2
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 &&
272 check_encoding 2
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 &&
295 check_encoding 2
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 &&
310 check_encoding 2
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
326 test_done