]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3901-i18n-patch.sh
Add basic infrastructure to assign attributes to paths
[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 |
16 grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD_=C3=B3=C3=BA?=" &&
17 git-cat-file commit HEAD~$j |
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 '
e0d10e1c 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
38 . ../t3901-utf8.txt &&
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
e0d10e1c 58 git-config i18n.commitencoding ISO-8859-1 &&
a731ec5e
JH
59 # use author and committer name in ISO-8859-1 to match it.
60 . ../t3901-8859-1.txt &&
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
e0d10e1c 67 git-config i18n.commitencoding UTF-8
a731ec5e
JH
68'
69
70test_expect_success 'format-patch output (ISO-8859-1)' '
e0d10e1c 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 &&
76 grep "^From: =?ISO-8859-1?q?=C1=E9=ED_=F3=FA?=" out-l1 &&
77 grep "^Content-Type: text/plain; charset=ISO-8859-1" out-l2 &&
78 grep "^From: =?ISO-8859-1?q?=C1=E9=ED_=F3=FA?=" out-l2
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 &&
87 grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD_=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_=C3=B3=C3=BA?=" out-u2
90'
91
c34c6008 92test_expect_success 'rebase (U/U)' '
a731ec5e 93 # We want the result of rebase in UTF-8
e0d10e1c 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.
104 . ../t3901-utf8.txt &&
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)' '
e0d10e1c
TP
112 git-config i18n.commitencoding UTF-8 &&
113 git config i18n.logoutputencoding ISO-8859-1 &&
a731ec5e
JH
114 . ../t3901-utf8.txt &&
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
e0d10e1c
TP
124 git-config i18n.commitencoding ISO-8859-1 &&
125 git config i18n.logoutputencoding ISO-8859-1 &&
a731ec5e
JH
126 . ../t3901-8859-1.txt &&
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.
e0d10e1c
TP
137 git-config i18n.commitencoding ISO-8859-1 &&
138 git config i18n.logoutputencoding UTF-8 &&
a731ec5e
JH
139 . ../t3901-8859-1.txt &&
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
e0d10e1c
TP
150 git-config i18n.commitencoding UTF-8 &&
151 git config i18n.logoutputencoding UTF-8 &&
c34c6008
JH
152 . ../t3901-utf8.txt &&
153
154 git reset --hard master &&
155 git cherry-pick side^ &&
156 git cherry-pick side &&
157 EDITOR=: VISUAL=: git revert HEAD &&
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
e0d10e1c
TP
165 git-config i18n.commitencoding ISO-8859-1 &&
166 git config i18n.logoutputencoding ISO-8859-1 &&
c34c6008
JH
167 . ../t3901-8859-1.txt &&
168
169 git reset --hard master &&
170 git cherry-pick side^ &&
171 git cherry-pick side &&
172 EDITOR=: VISUAL=: git revert HEAD &&
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
e0d10e1c
TP
180 git-config i18n.commitencoding UTF-8 &&
181 git config i18n.logoutputencoding ISO-8859-1 &&
c34c6008
JH
182 . ../t3901-utf8.txt &&
183
184 git reset --hard master &&
185 git cherry-pick side^ &&
186 git cherry-pick side &&
187 EDITOR=: VISUAL=: git revert HEAD &&
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
e0d10e1c
TP
196 git-config i18n.commitencoding ISO-8859-1 &&
197 git config i18n.logoutputencoding UTF-8 &&
c34c6008
JH
198 . ../t3901-8859-1.txt &&
199
200 git reset --hard master &&
201 git cherry-pick side^ &&
202 git cherry-pick side &&
203 EDITOR=: VISUAL=: git revert HEAD &&
204
205 check_encoding 3 8859
206'
207
208test_expect_success 'rebase --merge (U/U)' '
e0d10e1c
TP
209 git-config i18n.commitencoding UTF-8 &&
210 git config i18n.logoutputencoding UTF-8 &&
c34c6008
JH
211 . ../t3901-utf8.txt &&
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)' '
e0d10e1c
TP
220 git-config i18n.commitencoding UTF-8 &&
221 git config i18n.logoutputencoding ISO-8859-1 &&
c34c6008
JH
222 . ../t3901-utf8.txt &&
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
e0d10e1c
TP
232 git-config i18n.commitencoding ISO-8859-1 &&
233 git config i18n.logoutputencoding ISO-8859-1 &&
c34c6008
JH
234 . ../t3901-8859-1.txt &&
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.
e0d10e1c
TP
245 git-config i18n.commitencoding ISO-8859-1 &&
246 git config i18n.logoutputencoding UTF-8 &&
c34c6008
JH
247 . ../t3901-8859-1.txt &&
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