3 # Copyright (c) 2006 Junio C Hamano
6 test_description
='commit and log output encodings'
8 TEST_PASSES_SANITIZE_LEAK
=true
11 if ! test_have_prereq ICONV
13 skip_all
='skipping commit i18n tests; iconv not available'
18 git show
-s $1 |
sed -e '1,/^$/d' -e 's/^ //' >current
&&
21 test_cmp
"$2" current
;;
23 iconv -f "$3" -t UTF-8
>current.utf8
<current
&&
24 iconv -f "$3" -t UTF-8
>expect.utf8
<"$2" &&
25 test_cmp expect.utf8 current.utf8
30 test_expect_success setup
'
33 T=$(git write-tree) &&
34 C=$(git commit-tree $T <"$TEST_DIRECTORY"/t3900/1-UTF-8.txt) &&
35 git update-ref HEAD $C &&
39 test_expect_success
'no encoding header for base case' '
40 E=$(git cat-file commit C0 | sed -ne "s/^encoding //p") &&
44 test_expect_success
'UTF-16 refused because of NULs' '
46 test_must_fail git commit -a -F "$TEST_DIRECTORY"/t3900/UTF-16.txt
49 test_expect_success
'UTF-8 invalid characters refused' '
50 test_when_finished "rm -f \"\$HOME/stderr\" \"\$HOME/invalid\"" &&
51 echo "UTF-8 characters" >F &&
52 printf "Commit message\n\nInvalid surrogate:\355\240\200\n" \
54 git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
55 test_grep "did not conform" "$HOME"/stderr
58 test_expect_success
'UTF-8 overlong sequences rejected' '
59 test_when_finished "rm -f \"\$HOME/stderr\" \"\$HOME/invalid\"" &&
60 rm -f "$HOME/stderr" "$HOME/invalid" &&
61 echo "UTF-8 overlong" >F &&
62 printf "\340\202\251ommit message\n\nThis is not a space:\300\240\n" \
64 git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
65 test_grep "did not conform" "$HOME"/stderr
68 test_expect_success
'UTF-8 non-characters refused' '
69 test_when_finished "rm -f \"\$HOME/stderr\" \"\$HOME/invalid\"" &&
70 echo "UTF-8 non-character 1" >F &&
71 printf "Commit message\n\nNon-character:\364\217\277\276\n" \
73 git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
74 test_grep "did not conform" "$HOME"/stderr
77 test_expect_success
'UTF-8 non-characters refused' '
78 test_when_finished "rm -f \"\$HOME/stderr\" \"\$HOME/invalid\"" &&
79 echo "UTF-8 non-character 2." >F &&
80 printf "Commit message\n\nNon-character:\357\267\220\n" \
82 git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
83 test_grep "did not conform" "$HOME"/stderr
86 for H
in ISO8859-1 eucJP ISO-2022-JP
88 test_expect_success
"$H setup" '
89 git config i18n.commitencoding $H &&
90 git checkout -b $H C0 &&
92 git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt
96 for H
in ISO8859-1 eucJP ISO-2022-JP
98 test_expect_success
"check encoding header for $H" '
99 E=$(git cat-file commit '$H' | sed -ne "s/^encoding //p") &&
104 test_expect_success
'config to remove customization' '
105 git config --unset-all i18n.commitencoding &&
106 if Z=$(git config --get-all i18n.commitencoding)
108 echo Oops, should have failed.
113 git config i18n.commitencoding UTF-8
116 test_expect_success
'ISO8859-1 should be shown in UTF-8 now' '
117 compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
120 for H
in eucJP ISO-2022-JP
122 test_expect_success
"$H should be shown in UTF-8 now" '
123 compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
127 test_expect_success
'config to add customization' '
128 git config --unset-all i18n.commitencoding &&
129 if Z=$(git config --get-all i18n.commitencoding)
131 echo Oops, should have failed.
138 for H
in ISO8859-1 eucJP ISO-2022-JP
140 test_expect_success
"$H should be shown in itself now" '
141 git config i18n.commitencoding '$H' &&
142 compare_with '$H' "$TEST_DIRECTORY"/t3900/'$H'.txt
146 test_expect_success
'config to tweak customization' '
147 git config i18n.logoutputencoding UTF-8
150 test_expect_success
'ISO8859-1 should be shown in UTF-8 now' '
151 compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
154 for H
in eucJP ISO-2022-JP
156 test_expect_success
"$H should be shown in UTF-8 now" '
157 compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
161 for J
in eucJP ISO-2022-JP
163 if test "$J" = ISO-2022-JP
169 git config i18n.logoutputencoding
$J
170 for H
in eucJP ISO-2022-JP
172 test_expect_success
"$H should be shown in $J now" '
173 compare_with '$H' "$TEST_DIRECTORY"/t3900/'$J'.txt $ICONV
178 for H
in ISO8859-1 eucJP ISO-2022-JP
180 test_expect_success
"No conversion with $H" '
181 compare_with "--encoding=none '$H'" "$TEST_DIRECTORY"/t3900/'$H'.txt
185 test_commit_autosquash_flags
() {
188 test_expect_success
"commit --$flag with $H encoding" '
189 git config i18n.commitencoding $H &&
190 git checkout -b $H-$flag C0 &&
192 git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt &&
194 echo intermediate stuff >>G &&
196 git commit -a -m "intermediate commit" &&
199 git commit -a --$flag HEAD~1 &&
200 E=$(git cat-file commit '$H-$flag' |
201 sed -ne "s/^encoding //p") &&
202 test "z$E" = "z$H" &&
203 git config --unset-all i18n.commitencoding &&
204 git rebase --autosquash -i HEAD^^^ &&
205 git log --oneline >actual &&
206 test_line_count = 3 actual
210 test_commit_autosquash_flags eucJP fixup
212 test_commit_autosquash_flags ISO-2022-JP squash
214 test_commit_autosquash_multi_encoding
() {
219 test_expect_success
"commit --$flag into $old from $new" '
220 git checkout -b $flag-$old-$new C0 &&
221 git config i18n.commitencoding $old &&
223 git commit -a -F "$TEST_DIRECTORY"/t3900/$msg &&
225 echo intermediate stuff >>G &&
227 git commit -a -m "intermediate commit" &&
229 git config i18n.commitencoding $new &&
230 echo $new-$flag >>F &&
231 git commit -a --$flag HEAD^ &&
232 git rebase --autosquash -i HEAD^^^ &&
233 git rev-list HEAD >actual &&
234 test_line_count = 3 actual &&
235 iconv -f $old -t UTF-8 "$TEST_DIRECTORY"/t3900/$msg >expect &&
236 git cat-file commit HEAD^ >raw &&
237 (sed "1,/^$/d" raw | iconv -f $new -t utf-8) >actual &&
238 test_cmp expect actual
242 test_commit_autosquash_multi_encoding fixup UTF-8 ISO-8859-1
1-UTF-8.txt
243 test_commit_autosquash_multi_encoding squash ISO-8859-1 UTF-8 ISO8859-1.txt
244 test_commit_autosquash_multi_encoding squash eucJP ISO-2022-JP eucJP.txt
245 test_commit_autosquash_multi_encoding fixup ISO-2022-JP UTF-8 ISO-2022-JP.txt