]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3901-i18n-patch.sh
tests: use $TEST_DIRECTORY to refer to the t/ directory
[thirdparty/git.git] / t / t3901-i18n-patch.sh
CommitLineData
a731ec5e
JH
1#!/bin/sh
2#
3# Copyright (c) 2006 Junio C Hamano
4#
5
6test_description='i18n settings and format-patch | am pipe'
7
8. ./test-lib.sh
9
c34c6008
JH
10check_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
14 do
15 git format-patch --encoding=UTF-8 --stdout HEAD~$i..HEAD~$j |
996e2d6e 16 grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" &&
5be60078 17 git cat-file commit HEAD~$j |
c34c6008
JH
18 case "$header" in
19 8859)
20 grep "^encoding ISO-8859-1" ;;
21 *)
22 ! grep "^encoding ISO-8859-1" ;;
23 esac || {
24 bad=1
25 break
26 }
27 j=$i
28 i=$(($i+1))
29 done
30 (exit $bad)
31}
32
a731ec5e 33test_expect_success setup '
5be60078 34 git config i18n.commitencoding UTF-8 &&
a731ec5e
JH
35
36 # use UTF-8 in author and committer name to match the
37 # i18n.commitencoding settings
bfdbee98 38 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
a731ec5e
JH
39
40 test_tick &&
41 echo "$GIT_AUTHOR_NAME" >mine &&
42 git add mine &&
43 git commit -s -m "Initial commit" &&
44
45 test_tick &&
46 echo Hello world >mine &&
47 git add mine &&
48 git commit -s -m "Second on main" &&
49
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" &&
56
57 # the second one on the side branch is ISO-8859-1
5be60078 58 git config i18n.commitencoding ISO-8859-1 &&
a731ec5e 59 # use author and committer name in ISO-8859-1 to match it.
bfdbee98 60 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
a731ec5e
JH
61 test_tick &&
62 echo Yet another >theirs &&
63 git add theirs &&
64 git commit -s -m "Third on side" &&
65
66 # Back to default
5be60078 67 git config i18n.commitencoding UTF-8
a731ec5e
JH
68'
69
70test_expect_success 'format-patch output (ISO-8859-1)' '
5be60078 71 git config i18n.logoutputencoding ISO-8859-1 &&
a731ec5e
JH
72
73 git format-patch --stdout master..HEAD^ >out-l1 &&
74 git format-patch --stdout HEAD^ >out-l2 &&
75 grep "^Content-Type: text/plain; charset=ISO-8859-1" out-l1 &&
996e2d6e 76 grep "^From: =?ISO-8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l1 &&
a731ec5e 77 grep "^Content-Type: text/plain; charset=ISO-8859-1" out-l2 &&
996e2d6e 78 grep "^From: =?ISO-8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l2
a731ec5e
JH
79'
80
81test_expect_success 'format-patch output (UTF-8)' '
e0d10e1c 82 git config i18n.logoutputencoding UTF-8 &&
a731ec5e
JH
83
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 &&
996e2d6e 87 grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" out-u1 &&
a731ec5e 88 grep "^Content-Type: text/plain; charset=UTF-8" out-u2 &&
996e2d6e 89 grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" out-u2
a731ec5e
JH
90'
91
c34c6008 92test_expect_success 'rebase (U/U)' '
a731ec5e 93 # We want the result of rebase in UTF-8
5be60078 94 git config i18n.commitencoding UTF-8 &&
a731ec5e
JH
95
96 # The test is about logoutputencoding not affecting the
97 # final outcome -- it is used internally to generate the
98 # patch and the log.
99
e0d10e1c 100 git config i18n.logoutputencoding UTF-8 &&
a731ec5e
JH
101
102 # The result will be committed by GIT_COMMITTER_NAME --
103 # we want UTF-8 encoded name.
bfdbee98 104 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
a731ec5e
JH
105 git checkout -b test &&
106 git-rebase master &&
107
c34c6008 108 check_encoding 2
a731ec5e
JH
109'
110
c34c6008 111test_expect_success 'rebase (U/L)' '
5be60078 112 git config i18n.commitencoding UTF-8 &&
e0d10e1c 113 git config i18n.logoutputencoding ISO-8859-1 &&
bfdbee98 114 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
a731ec5e
JH
115
116 git reset --hard side &&
117 git-rebase master &&
118
c34c6008 119 check_encoding 2
a731ec5e
JH
120'
121
c34c6008 122test_expect_success 'rebase (L/L)' '
a731ec5e 123 # In this test we want ISO-8859-1 encoded commits as the result
5be60078 124 git config i18n.commitencoding ISO-8859-1 &&
e0d10e1c 125 git config i18n.logoutputencoding ISO-8859-1 &&
bfdbee98 126 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
a731ec5e
JH
127
128 git reset --hard side &&
129 git-rebase master &&
130
c34c6008 131 check_encoding 2 8859
a731ec5e
JH
132'
133
c34c6008 134test_expect_success 'rebase (L/U)' '
a731ec5e
JH
135 # This is pathological -- use UTF-8 as intermediate form
136 # to get ISO-8859-1 results.
5be60078 137 git config i18n.commitencoding ISO-8859-1 &&
e0d10e1c 138 git config i18n.logoutputencoding UTF-8 &&
bfdbee98 139 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
a731ec5e
JH
140
141 git reset --hard side &&
142 git-rebase master &&
143
c34c6008
JH
144 check_encoding 2 8859
145'
146
147test_expect_success 'cherry-pick(U/U)' '
148 # Both the commitencoding and logoutputencoding is set to UTF-8.
149
5be60078 150 git config i18n.commitencoding UTF-8 &&
e0d10e1c 151 git config i18n.logoutputencoding UTF-8 &&
bfdbee98 152 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
c34c6008
JH
153
154 git reset --hard master &&
155 git cherry-pick side^ &&
156 git cherry-pick side &&
9e54dc6c 157 git revert HEAD &&
c34c6008
JH
158
159 check_encoding 3
160'
161
162test_expect_success 'cherry-pick(L/L)' '
163 # Both the commitencoding and logoutputencoding is set to ISO-8859-1
164
5be60078 165 git config i18n.commitencoding ISO-8859-1 &&
e0d10e1c 166 git config i18n.logoutputencoding ISO-8859-1 &&
bfdbee98 167 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
c34c6008
JH
168
169 git reset --hard master &&
170 git cherry-pick side^ &&
171 git cherry-pick side &&
9e54dc6c 172 git revert HEAD &&
c34c6008
JH
173
174 check_encoding 3 8859
175'
176
177test_expect_success 'cherry-pick(U/L)' '
178 # Commitencoding is set to UTF-8 but logoutputencoding is ISO-8859-1
179
5be60078 180 git config i18n.commitencoding UTF-8 &&
e0d10e1c 181 git config i18n.logoutputencoding ISO-8859-1 &&
bfdbee98 182 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
c34c6008
JH
183
184 git reset --hard master &&
185 git cherry-pick side^ &&
186 git cherry-pick side &&
9e54dc6c 187 git revert HEAD &&
c34c6008
JH
188
189 check_encoding 3
190'
191
192test_expect_success 'cherry-pick(L/U)' '
193 # Again, the commitencoding is set to ISO-8859-1 but
194 # logoutputencoding is set to UTF-8.
195
5be60078 196 git config i18n.commitencoding ISO-8859-1 &&
e0d10e1c 197 git config i18n.logoutputencoding UTF-8 &&
bfdbee98 198 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
c34c6008
JH
199
200 git reset --hard master &&
201 git cherry-pick side^ &&
202 git cherry-pick side &&
9e54dc6c 203 git revert HEAD &&
c34c6008
JH
204
205 check_encoding 3 8859
206'
207
208test_expect_success 'rebase --merge (U/U)' '
5be60078 209 git config i18n.commitencoding UTF-8 &&
e0d10e1c 210 git config i18n.logoutputencoding UTF-8 &&
bfdbee98 211 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
c34c6008
JH
212
213 git reset --hard side &&
214 git-rebase --merge master &&
215
216 check_encoding 2
217'
218
219test_expect_success 'rebase --merge (U/L)' '
5be60078 220 git config i18n.commitencoding UTF-8 &&
e0d10e1c 221 git config i18n.logoutputencoding ISO-8859-1 &&
bfdbee98 222 . "$TEST_DIRECTORY"/t3901-utf8.txt &&
c34c6008
JH
223
224 git reset --hard side &&
225 git-rebase --merge master &&
226
227 check_encoding 2
228'
229
230test_expect_success 'rebase --merge (L/L)' '
231 # In this test we want ISO-8859-1 encoded commits as the result
5be60078 232 git config i18n.commitencoding ISO-8859-1 &&
e0d10e1c 233 git config i18n.logoutputencoding ISO-8859-1 &&
bfdbee98 234 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
c34c6008
JH
235
236 git reset --hard side &&
237 git-rebase --merge master &&
238
239 check_encoding 2 8859
240'
241
242test_expect_success 'rebase --merge (L/U)' '
243 # This is pathological -- use UTF-8 as intermediate form
244 # to get ISO-8859-1 results.
5be60078 245 git config i18n.commitencoding ISO-8859-1 &&
e0d10e1c 246 git config i18n.logoutputencoding UTF-8 &&
bfdbee98 247 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
c34c6008
JH
248
249 git reset --hard side &&
250 git-rebase --merge master &&
a731ec5e 251
c34c6008 252 check_encoding 2 8859
a731ec5e
JH
253'
254
255test_done