Merge branch 'ab/merge-file-prefix'
[git.git] / t / t3901-i18n-patch.sh
bloba392f3d1d66757361ff9fc4e26f4125da5ab0a4f
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 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 master..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 master..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 master &&
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 master &&
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 master &&
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 master &&
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 master &&
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 master &&
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 master &&
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 master &&
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 master &&
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 master &&
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 master &&
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 master &&
255 check_encoding 2 8859
258 test_done