Merge branch 'ib/t3700-add-chmod-x-updates'
[git.git] / t / t3901-i18n-patch.sh
blob509084e1a70b4cd5ee7f56421bb9b8995b0a5d94
1 #!/bin/sh
3 # Copyright (c) 2006 Junio C Hamano
6 test_description='i18n settings and format-patch | am pipe'
8 . ./test-lib.sh
10 check_encoding () {
11 # Make sure characters are not corrupted
12 cnt="$1" header="$2" i=1 j=0
13 while test "$i" -le $cnt
15 git format-patch --encoding=UTF-8 --stdout HEAD~$i..HEAD~$j |
16 grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" &&
17 git cat-file commit HEAD~$j |
18 case "$header" in
19 8859)
20 grep "^encoding ISO8859-1" ;;
22 grep "^encoding ISO8859-1"; test "$?" != 0 ;;
23 esac || return 1
24 j=$i
25 i=$(($i+1))
26 done
29 test_expect_success setup '
30 git config i18n.commitencoding UTF-8 &&
32 # use UTF-8 in author and committer name to match the
33 # i18n.commitencoding settings
34 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
36 test_tick &&
37 echo "$GIT_AUTHOR_NAME" >mine &&
38 git add mine &&
39 git commit -s -m "Initial commit" &&
41 test_tick &&
42 echo Hello world >mine &&
43 git add mine &&
44 git commit -s -m "Second on main" &&
46 # the first commit on the side branch is UTF-8
47 test_tick &&
48 git checkout -b side master^ &&
49 echo Another file >yours &&
50 git add yours &&
51 git commit -s -m "Second on side" &&
53 if test_have_prereq !MINGW
54 then
55 # the second one on the side branch is ISO-8859-1
56 git config i18n.commitencoding ISO8859-1 &&
57 # use author and committer name in ISO-8859-1 to match it.
58 . "$TEST_DIRECTORY"/t3901-8859-1.txt
59 fi &&
60 test_tick &&
61 echo Yet another >theirs &&
62 git add theirs &&
63 git commit -s -m "Third on side" &&
65 # Back to default
66 git config i18n.commitencoding UTF-8
69 test_expect_success 'format-patch output (ISO-8859-1)' '
70 git config i18n.logoutputencoding ISO8859-1 &&
72 git format-patch --stdout master..HEAD^ >out-l1 &&
73 git format-patch --stdout HEAD^ >out-l2 &&
74 grep "^Content-Type: text/plain; charset=ISO8859-1" out-l1 &&
75 grep "^From: =?ISO8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l1 &&
76 grep "^Content-Type: text/plain; charset=ISO8859-1" out-l2 &&
77 grep "^From: =?ISO8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l2
80 test_expect_success 'format-patch output (UTF-8)' '
81 git config i18n.logoutputencoding UTF-8 &&
83 git format-patch --stdout master..HEAD^ >out-u1 &&
84 git format-patch --stdout HEAD^ >out-u2 &&
85 grep "^Content-Type: text/plain; charset=UTF-8" out-u1 &&
86 grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" out-u1 &&
87 grep "^Content-Type: text/plain; charset=UTF-8" out-u2 &&
88 grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" out-u2
91 test_expect_success 'rebase (U/U)' '
92 # We want the result of rebase in UTF-8
93 git config i18n.commitencoding UTF-8 &&
95 # The test is about logoutputencoding not affecting the
96 # final outcome -- it is used internally to generate the
97 # patch and the log.
99 git config i18n.logoutputencoding UTF-8 &&
101 # The result will be committed by GIT_COMMITTER_NAME --
102 # we want UTF-8 encoded name.
103 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
104 git checkout -b test &&
105 git rebase master &&
107 check_encoding 2
110 test_expect_success 'rebase (U/L)' '
111 git config i18n.commitencoding UTF-8 &&
112 git config i18n.logoutputencoding ISO8859-1 &&
113 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
115 git reset --hard side &&
116 git rebase master &&
118 check_encoding 2
121 test_expect_success !MINGW 'rebase (L/L)' '
122 # In this test we want ISO-8859-1 encoded commits as the result
123 git config i18n.commitencoding ISO8859-1 &&
124 git config i18n.logoutputencoding ISO8859-1 &&
125 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
127 git reset --hard side &&
128 git rebase master &&
130 check_encoding 2 8859
133 test_expect_success !MINGW 'rebase (L/U)' '
134 # This is pathological -- use UTF-8 as intermediate form
135 # to get ISO-8859-1 results.
136 git config i18n.commitencoding ISO8859-1 &&
137 git config i18n.logoutputencoding UTF-8 &&
138 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
140 git reset --hard side &&
141 git rebase master &&
143 check_encoding 2 8859
146 test_expect_success 'cherry-pick(U/U)' '
147 # Both the commitencoding and logoutputencoding is set to UTF-8.
149 git config i18n.commitencoding UTF-8 &&
150 git config i18n.logoutputencoding UTF-8 &&
151 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
153 git reset --hard master &&
154 git cherry-pick side^ &&
155 git cherry-pick side &&
156 git revert HEAD &&
158 check_encoding 3
161 test_expect_success !MINGW 'cherry-pick(L/L)' '
162 # Both the commitencoding and logoutputencoding is set to ISO-8859-1
164 git config i18n.commitencoding ISO8859-1 &&
165 git config i18n.logoutputencoding ISO8859-1 &&
166 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
168 git reset --hard master &&
169 git cherry-pick side^ &&
170 git cherry-pick side &&
171 git revert HEAD &&
173 check_encoding 3 8859
176 test_expect_success 'cherry-pick(U/L)' '
177 # Commitencoding is set to UTF-8 but logoutputencoding is ISO-8859-1
179 git config i18n.commitencoding UTF-8 &&
180 git config i18n.logoutputencoding ISO8859-1 &&
181 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
183 git reset --hard master &&
184 git cherry-pick side^ &&
185 git cherry-pick side &&
186 git revert HEAD &&
188 check_encoding 3
191 test_expect_success !MINGW 'cherry-pick(L/U)' '
192 # Again, the commitencoding is set to ISO-8859-1 but
193 # logoutputencoding is set to UTF-8.
195 git config i18n.commitencoding ISO8859-1 &&
196 git config i18n.logoutputencoding UTF-8 &&
197 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
199 git reset --hard master &&
200 git cherry-pick side^ &&
201 git cherry-pick side &&
202 git revert HEAD &&
204 check_encoding 3 8859
207 test_expect_success 'rebase --merge (U/U)' '
208 git config i18n.commitencoding UTF-8 &&
209 git config i18n.logoutputencoding UTF-8 &&
210 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
212 git reset --hard side &&
213 git rebase --merge master &&
215 check_encoding 2
218 test_expect_success 'rebase --merge (U/L)' '
219 git config i18n.commitencoding UTF-8 &&
220 git config i18n.logoutputencoding ISO8859-1 &&
221 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
223 git reset --hard side &&
224 git rebase --merge master &&
226 check_encoding 2
229 test_expect_success 'rebase --merge (L/L)' '
230 # In this test we want ISO-8859-1 encoded commits as the result
231 git config i18n.commitencoding ISO8859-1 &&
232 git config i18n.logoutputencoding ISO8859-1 &&
233 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
235 git reset --hard side &&
236 git rebase --merge master &&
238 check_encoding 2 8859
241 test_expect_success 'rebase --merge (L/U)' '
242 # This is pathological -- use UTF-8 as intermediate form
243 # to get ISO-8859-1 results.
244 git config i18n.commitencoding ISO8859-1 &&
245 git config i18n.logoutputencoding UTF-8 &&
246 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
248 git reset --hard side &&
249 git rebase --merge master &&
251 check_encoding 2 8859
254 test_expect_success 'am (U/U)' '
255 # Apply UTF-8 patches with UTF-8 commitencoding
256 git config i18n.commitencoding UTF-8 &&
257 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
259 git reset --hard master &&
260 git am out-u1 out-u2 &&
262 check_encoding 2
265 test_expect_success !MINGW 'am (L/L)' '
266 # Apply ISO-8859-1 patches with ISO-8859-1 commitencoding
267 git config i18n.commitencoding ISO8859-1 &&
268 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
270 git reset --hard master &&
271 git am out-l1 out-l2 &&
273 check_encoding 2 8859
276 test_expect_success 'am (U/L)' '
277 # Apply ISO-8859-1 patches with UTF-8 commitencoding
278 git config i18n.commitencoding UTF-8 &&
279 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
280 git reset --hard master &&
282 # am specifies --utf8 by default.
283 git am out-l1 out-l2 &&
285 check_encoding 2
288 test_expect_success 'am --no-utf8 (U/L)' '
289 # Apply ISO-8859-1 patches with UTF-8 commitencoding
290 git config i18n.commitencoding UTF-8 &&
291 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
293 git reset --hard master &&
294 git am --no-utf8 out-l1 out-l2 2>err &&
296 # commit-tree will warn that the commit message does not contain valid UTF-8
297 # as mailinfo did not convert it
298 grep "did not conform" err &&
300 check_encoding 2
303 test_expect_success !MINGW 'am (L/U)' '
304 # Apply UTF-8 patches with ISO-8859-1 commitencoding
305 git config i18n.commitencoding ISO8859-1 &&
306 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
308 git reset --hard master &&
309 # mailinfo will re-code the commit message to the charset specified by
310 # i18n.commitencoding
311 git am out-u1 out-u2 &&
313 check_encoding 2 8859
316 test_done