Merge branch 'es/worktree-repair-copied' into cw/worktrees-relative
[git/gitster.git] / t / t3901-i18n-patch.sh
blob5f0b9afc3faa7d09013c8eaa6958e7c6786f1095
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 check_encoding () {
15 # Make sure characters are not corrupted
16 cnt="$1" header="$2" i=1 j=0
17 while test "$i" -le $cnt
19 git format-patch --encoding=UTF-8 --stdout HEAD~$i..HEAD~$j |
20 grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" &&
21 git cat-file commit HEAD~$j |
22 case "$header" in
23 8859)
24 grep "^encoding ISO8859-1" ;;
26 grep "^encoding ISO8859-1"; test "$?" != 0 ;;
27 esac || return 1
28 j=$i
29 i=$(($i+1))
30 done
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 main^ &&
53 echo Another file >yours &&
54 git add yours &&
55 git commit -s -m "Second on side" &&
57 if test_have_prereq !MINGW
58 then
59 # the second one on the side branch is ISO-8859-1
60 git config i18n.commitencoding ISO8859-1 &&
61 # use author and committer name in ISO-8859-1 to match it.
62 . "$TEST_DIRECTORY"/t3901/8859-1.txt
63 fi &&
64 test_tick &&
65 echo Yet another >theirs &&
66 git add theirs &&
67 git commit -s -m "Third on side" &&
69 # Back to default
70 git config i18n.commitencoding UTF-8
73 test_expect_success 'format-patch output (ISO-8859-1)' '
74 git config i18n.logoutputencoding ISO8859-1 &&
76 git format-patch --stdout main..HEAD^ >out-l1 &&
77 git format-patch --stdout HEAD^ >out-l2 &&
78 grep "^Content-Type: text/plain; charset=ISO8859-1" out-l1 &&
79 grep "^From: =?ISO8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l1 &&
80 grep "^Content-Type: text/plain; charset=ISO8859-1" out-l2 &&
81 grep "^From: =?ISO8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l2
84 test_expect_success 'format-patch output (UTF-8)' '
85 git config i18n.logoutputencoding UTF-8 &&
87 git format-patch --stdout main..HEAD^ >out-u1 &&
88 git format-patch --stdout HEAD^ >out-u2 &&
89 grep "^Content-Type: text/plain; charset=UTF-8" out-u1 &&
90 grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" out-u1 &&
91 grep "^Content-Type: text/plain; charset=UTF-8" out-u2 &&
92 grep "^From: =?UTF-8?q?=C3=81=C3=A9=C3=AD=20=C3=B3=C3=BA?=" out-u2
95 test_expect_success 'rebase (U/U)' '
96 # We want the result of rebase in UTF-8
97 git config i18n.commitencoding UTF-8 &&
99 # The test is about logoutputencoding not affecting the
100 # final outcome -- it is used internally to generate the
101 # patch and the log.
103 git config i18n.logoutputencoding UTF-8 &&
105 # The result will be committed by GIT_COMMITTER_NAME --
106 # we want UTF-8 encoded name.
107 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
108 git checkout -b test &&
109 git rebase main &&
111 check_encoding 2
114 test_expect_success 'rebase (U/L)' '
115 git config i18n.commitencoding UTF-8 &&
116 git config i18n.logoutputencoding ISO8859-1 &&
117 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
119 git reset --hard side &&
120 git rebase main &&
122 check_encoding 2
125 test_expect_success !MINGW 'rebase (L/L)' '
126 # In this test we want ISO-8859-1 encoded commits as the result
127 git config i18n.commitencoding ISO8859-1 &&
128 git config i18n.logoutputencoding ISO8859-1 &&
129 . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
131 git reset --hard side &&
132 git rebase main &&
134 check_encoding 2 8859
137 test_expect_success !MINGW 'rebase (L/U)' '
138 # This is pathological -- use UTF-8 as intermediate form
139 # to get ISO-8859-1 results.
140 git config i18n.commitencoding ISO8859-1 &&
141 git config i18n.logoutputencoding UTF-8 &&
142 . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
144 git reset --hard side &&
145 git rebase main &&
147 check_encoding 2 8859
150 test_expect_success 'cherry-pick(U/U)' '
151 # Both the commitencoding and logoutputencoding is set to UTF-8.
153 git config i18n.commitencoding UTF-8 &&
154 git config i18n.logoutputencoding UTF-8 &&
155 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
157 git reset --hard main &&
158 git cherry-pick side^ &&
159 git cherry-pick side &&
160 git revert HEAD &&
162 check_encoding 3
165 test_expect_success !MINGW 'cherry-pick(L/L)' '
166 # Both the commitencoding and logoutputencoding is set to ISO-8859-1
168 git config i18n.commitencoding ISO8859-1 &&
169 git config i18n.logoutputencoding ISO8859-1 &&
170 . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
172 git reset --hard main &&
173 git cherry-pick side^ &&
174 git cherry-pick side &&
175 git revert HEAD &&
177 check_encoding 3 8859
180 test_expect_success 'cherry-pick(U/L)' '
181 # Commitencoding is set to UTF-8 but logoutputencoding is ISO-8859-1
183 git config i18n.commitencoding UTF-8 &&
184 git config i18n.logoutputencoding ISO8859-1 &&
185 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
187 git reset --hard main &&
188 git cherry-pick side^ &&
189 git cherry-pick side &&
190 git revert HEAD &&
192 check_encoding 3
195 test_expect_success !MINGW 'cherry-pick(L/U)' '
196 # Again, the commitencoding is set to ISO-8859-1 but
197 # logoutputencoding is set to UTF-8.
199 git config i18n.commitencoding ISO8859-1 &&
200 git config i18n.logoutputencoding UTF-8 &&
201 . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
203 git reset --hard main &&
204 git cherry-pick side^ &&
205 git cherry-pick side &&
206 git revert HEAD &&
208 check_encoding 3 8859
211 test_expect_success 'rebase --merge (U/U)' '
212 git config i18n.commitencoding UTF-8 &&
213 git config i18n.logoutputencoding UTF-8 &&
214 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
216 git reset --hard side &&
217 git rebase --merge main &&
219 check_encoding 2
222 test_expect_success 'rebase --merge (U/L)' '
223 git config i18n.commitencoding UTF-8 &&
224 git config i18n.logoutputencoding ISO8859-1 &&
225 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
227 git reset --hard side &&
228 git rebase --merge main &&
230 check_encoding 2
233 test_expect_success 'rebase --merge (L/L)' '
234 # In this test we want ISO-8859-1 encoded commits as the result
235 git config i18n.commitencoding ISO8859-1 &&
236 git config i18n.logoutputencoding ISO8859-1 &&
237 . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
239 git reset --hard side &&
240 git rebase --merge main &&
242 check_encoding 2 8859
245 test_expect_success 'rebase --merge (L/U)' '
246 # This is pathological -- use UTF-8 as intermediate form
247 # to get ISO-8859-1 results.
248 git config i18n.commitencoding ISO8859-1 &&
249 git config i18n.logoutputencoding UTF-8 &&
250 . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
252 git reset --hard side &&
253 git rebase --merge main &&
255 check_encoding 2 8859
258 test_expect_success 'am (U/U)' '
259 # Apply UTF-8 patches with UTF-8 commitencoding
260 git config i18n.commitencoding UTF-8 &&
261 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
263 git reset --hard main &&
264 git am out-u1 out-u2 &&
266 check_encoding 2
269 test_expect_success !MINGW 'am (L/L)' '
270 # Apply ISO-8859-1 patches with ISO-8859-1 commitencoding
271 git config i18n.commitencoding ISO8859-1 &&
272 . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
274 git reset --hard main &&
275 git am out-l1 out-l2 &&
277 check_encoding 2 8859
280 test_expect_success 'am (U/L)' '
281 # Apply ISO-8859-1 patches with UTF-8 commitencoding
282 git config i18n.commitencoding UTF-8 &&
283 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
284 git reset --hard main &&
286 # am specifies --utf8 by default.
287 git am out-l1 out-l2 &&
289 check_encoding 2
292 test_expect_success 'am --no-utf8 (U/L)' '
293 # Apply ISO-8859-1 patches with UTF-8 commitencoding
294 git config i18n.commitencoding UTF-8 &&
295 . "$TEST_DIRECTORY"/t3901/utf8.txt &&
297 git reset --hard main &&
298 git am --no-utf8 out-l1 out-l2 2>err &&
300 # commit-tree will warn that the commit message does not contain valid UTF-8
301 # as mailinfo did not convert it
302 test_grep "did not conform" err &&
304 check_encoding 2
307 test_expect_success !MINGW 'am (L/U)' '
308 # Apply UTF-8 patches with ISO-8859-1 commitencoding
309 git config i18n.commitencoding ISO8859-1 &&
310 . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
312 git reset --hard main &&
313 # mailinfo will re-code the commit message to the charset specified by
314 # i18n.commitencoding
315 git am out-u1 out-u2 &&
317 check_encoding 2 8859
320 test_done