Sixth batch for 2.1
[alt-git.git] / t / t3901-i18n-patch.sh
blob31a5770b34466c9ed52a9f00bac27b71fd6e0deb
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 bad=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 || {
24 bad=1
25 break
27 j=$i
28 i=$(($i+1))
29 done
30 (exit $bad)
33 test_expect_success setup '
34 git config i18n.commitencoding UTF-8 &&
36 # use UTF-8 in author and committer name to match the
37 # i18n.commitencoding settings
38 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
40 test_tick &&
41 echo "$GIT_AUTHOR_NAME" >mine &&
42 git add mine &&
43 git commit -s -m "Initial commit" &&
45 test_tick &&
46 echo Hello world >mine &&
47 git add mine &&
48 git commit -s -m "Second on main" &&
50 # the first commit on the side branch is UTF-8
51 test_tick &&
52 git checkout -b side master^ &&
53 echo Another file >yours &&
54 git add yours &&
55 git commit -s -m "Second on side" &&
57 # the second one on the side branch is ISO-8859-1
58 git config i18n.commitencoding ISO8859-1 &&
59 # use author and committer name in ISO-8859-1 to match it.
60 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
61 test_tick &&
62 echo Yet another >theirs &&
63 git add theirs &&
64 git commit -s -m "Third on side" &&
66 # Back to default
67 git config i18n.commitencoding UTF-8
70 test_expect_success 'format-patch output (ISO-8859-1)' '
71 git config i18n.logoutputencoding ISO8859-1 &&
73 git format-patch --stdout master..HEAD^ >out-l1 &&
74 git format-patch --stdout HEAD^ >out-l2 &&
75 grep "^Content-Type: text/plain; charset=ISO8859-1" out-l1 &&
76 grep "^From: =?ISO8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l1 &&
77 grep "^Content-Type: text/plain; charset=ISO8859-1" out-l2 &&
78 grep "^From: =?ISO8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l2
81 test_expect_success 'format-patch output (UTF-8)' '
82 git config i18n.logoutputencoding UTF-8 &&
84 git format-patch --stdout master..HEAD^ >out-u1 &&
85 git format-patch --stdout HEAD^ >out-u2 &&
86 grep "^Content-Type: text/plain; charset=UTF-8" out-u1 &&
87 grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" out-u1 &&
88 grep "^Content-Type: text/plain; charset=UTF-8" out-u2 &&
89 grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" out-u2
92 test_expect_success 'rebase (U/U)' '
93 # We want the result of rebase in UTF-8
94 git config i18n.commitencoding UTF-8 &&
96 # The test is about logoutputencoding not affecting the
97 # final outcome -- it is used internally to generate the
98 # patch and the log.
100 git config i18n.logoutputencoding UTF-8 &&
102 # The result will be committed by GIT_COMMITTER_NAME --
103 # we want UTF-8 encoded name.
104 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
105 git checkout -b test &&
106 git rebase master &&
108 check_encoding 2
111 test_expect_success 'rebase (U/L)' '
112 git config i18n.commitencoding UTF-8 &&
113 git config i18n.logoutputencoding ISO8859-1 &&
114 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
116 git reset --hard side &&
117 git rebase master &&
119 check_encoding 2
122 test_expect_success 'rebase (L/L)' '
123 # In this test we want ISO-8859-1 encoded commits as the result
124 git config i18n.commitencoding ISO8859-1 &&
125 git config i18n.logoutputencoding ISO8859-1 &&
126 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
128 git reset --hard side &&
129 git rebase master &&
131 check_encoding 2 8859
134 test_expect_success 'rebase (L/U)' '
135 # This is pathological -- use UTF-8 as intermediate form
136 # to get ISO-8859-1 results.
137 git config i18n.commitencoding ISO8859-1 &&
138 git config i18n.logoutputencoding UTF-8 &&
139 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
141 git reset --hard side &&
142 git rebase master &&
144 check_encoding 2 8859
147 test_expect_success 'cherry-pick(U/U)' '
148 # Both the commitencoding and logoutputencoding is set to UTF-8.
150 git config i18n.commitencoding UTF-8 &&
151 git config i18n.logoutputencoding UTF-8 &&
152 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
154 git reset --hard master &&
155 git cherry-pick side^ &&
156 git cherry-pick side &&
157 git revert HEAD &&
159 check_encoding 3
162 test_expect_success 'cherry-pick(L/L)' '
163 # Both the commitencoding and logoutputencoding is set to ISO-8859-1
165 git config i18n.commitencoding ISO8859-1 &&
166 git config i18n.logoutputencoding ISO8859-1 &&
167 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
169 git reset --hard master &&
170 git cherry-pick side^ &&
171 git cherry-pick side &&
172 git revert HEAD &&
174 check_encoding 3 8859
177 test_expect_success 'cherry-pick(U/L)' '
178 # Commitencoding is set to UTF-8 but logoutputencoding is ISO-8859-1
180 git config i18n.commitencoding UTF-8 &&
181 git config i18n.logoutputencoding ISO8859-1 &&
182 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
184 git reset --hard master &&
185 git cherry-pick side^ &&
186 git cherry-pick side &&
187 git revert HEAD &&
189 check_encoding 3
192 test_expect_success 'cherry-pick(L/U)' '
193 # Again, the commitencoding is set to ISO-8859-1 but
194 # logoutputencoding is set to UTF-8.
196 git config i18n.commitencoding ISO8859-1 &&
197 git config i18n.logoutputencoding UTF-8 &&
198 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
200 git reset --hard master &&
201 git cherry-pick side^ &&
202 git cherry-pick side &&
203 git revert HEAD &&
205 check_encoding 3 8859
208 test_expect_success 'rebase --merge (U/U)' '
209 git config i18n.commitencoding UTF-8 &&
210 git config i18n.logoutputencoding UTF-8 &&
211 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
213 git reset --hard side &&
214 git rebase --merge master &&
216 check_encoding 2
219 test_expect_success 'rebase --merge (U/L)' '
220 git config i18n.commitencoding UTF-8 &&
221 git config i18n.logoutputencoding ISO8859-1 &&
222 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
224 git reset --hard side &&
225 git rebase --merge master &&
227 check_encoding 2
230 test_expect_success 'rebase --merge (L/L)' '
231 # In this test we want ISO-8859-1 encoded commits as the result
232 git config i18n.commitencoding ISO8859-1 &&
233 git config i18n.logoutputencoding ISO8859-1 &&
234 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
236 git reset --hard side &&
237 git rebase --merge master &&
239 check_encoding 2 8859
242 test_expect_success 'rebase --merge (L/U)' '
243 # This is pathological -- use UTF-8 as intermediate form
244 # to get ISO-8859-1 results.
245 git config i18n.commitencoding ISO8859-1 &&
246 git config i18n.logoutputencoding UTF-8 &&
247 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
249 git reset --hard side &&
250 git rebase --merge master &&
252 check_encoding 2 8859
255 test_done