3 # Copyright (c) 2006 Junio C Hamano
6 test_description
='commit and log output encodings'
8 TEST_PASSES_SANITIZE_LEAK
=true
12 git show
-s $1 |
sed -e '1,/^$/d' -e 's/^ //' >current
&&
15 test_cmp
"$2" current
;;
17 iconv -f "$3" -t UTF-8
>current.utf8
<current
&&
18 iconv -f "$3" -t UTF-8
>expect.utf8
<"$2" &&
19 test_cmp expect.utf8 current.utf8
24 test_expect_success setup
'
27 T=$(git write-tree) &&
28 C=$(git commit-tree $T <"$TEST_DIRECTORY"/t3900/1-UTF-8.txt) &&
29 git update-ref HEAD $C &&
33 test_expect_success
'no encoding header for base case' '
34 E=$(git cat-file commit C0 | sed -ne "s/^encoding //p") &&
38 test_expect_success
'UTF-16 refused because of NULs' '
40 test_must_fail git commit -a -F "$TEST_DIRECTORY"/t3900/UTF-16.txt
43 test_expect_success
'UTF-8 invalid characters refused' '
44 test_when_finished "rm -f \"\$HOME/stderr\" \"\$HOME/invalid\"" &&
45 echo "UTF-8 characters" >F &&
46 printf "Commit message\n\nInvalid surrogate:\355\240\200\n" \
48 git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
49 test_grep "did not conform" "$HOME"/stderr
52 test_expect_success
'UTF-8 overlong sequences rejected' '
53 test_when_finished "rm -f \"\$HOME/stderr\" \"\$HOME/invalid\"" &&
54 rm -f "$HOME/stderr" "$HOME/invalid" &&
55 echo "UTF-8 overlong" >F &&
56 printf "\340\202\251ommit message\n\nThis is not a space:\300\240\n" \
58 git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
59 test_grep "did not conform" "$HOME"/stderr
62 test_expect_success
'UTF-8 non-characters refused' '
63 test_when_finished "rm -f \"\$HOME/stderr\" \"\$HOME/invalid\"" &&
64 echo "UTF-8 non-character 1" >F &&
65 printf "Commit message\n\nNon-character:\364\217\277\276\n" \
67 git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
68 test_grep "did not conform" "$HOME"/stderr
71 test_expect_success
'UTF-8 non-characters refused' '
72 test_when_finished "rm -f \"\$HOME/stderr\" \"\$HOME/invalid\"" &&
73 echo "UTF-8 non-character 2." >F &&
74 printf "Commit message\n\nNon-character:\357\267\220\n" \
76 git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
77 test_grep "did not conform" "$HOME"/stderr
80 for H
in ISO8859-1 eucJP ISO-2022-JP
82 test_expect_success
"$H setup" '
83 git config i18n.commitencoding $H &&
84 git checkout -b $H C0 &&
86 git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt
90 for H
in ISO8859-1 eucJP ISO-2022-JP
92 test_expect_success
"check encoding header for $H" '
93 E=$(git cat-file commit '$H' | sed -ne "s/^encoding //p") &&
98 test_expect_success
'config to remove customization' '
99 git config --unset-all i18n.commitencoding &&
100 if Z=$(git config --get-all i18n.commitencoding)
102 echo Oops, should have failed.
107 git config i18n.commitencoding UTF-8
110 test_expect_success
'ISO8859-1 should be shown in UTF-8 now' '
111 compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
114 for H
in eucJP ISO-2022-JP
116 test_expect_success
"$H should be shown in UTF-8 now" '
117 compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
121 test_expect_success
'config to add customization' '
122 git config --unset-all i18n.commitencoding &&
123 if Z=$(git config --get-all i18n.commitencoding)
125 echo Oops, should have failed.
132 for H
in ISO8859-1 eucJP ISO-2022-JP
134 test_expect_success
"$H should be shown in itself now" '
135 git config i18n.commitencoding '$H' &&
136 compare_with '$H' "$TEST_DIRECTORY"/t3900/'$H'.txt
140 test_expect_success
'config to tweak customization' '
141 git config i18n.logoutputencoding UTF-8
144 test_expect_success
'ISO8859-1 should be shown in UTF-8 now' '
145 compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
148 for H
in eucJP ISO-2022-JP
150 test_expect_success
"$H should be shown in UTF-8 now" '
151 compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
155 for J
in eucJP ISO-2022-JP
157 if test "$J" = ISO-2022-JP
163 git config i18n.logoutputencoding
$J
164 for H
in eucJP ISO-2022-JP
166 test_expect_success
"$H should be shown in $J now" '
167 compare_with '$H' "$TEST_DIRECTORY"/t3900/'$J'.txt $ICONV
172 for H
in ISO8859-1 eucJP ISO-2022-JP
174 test_expect_success
"No conversion with $H" '
175 compare_with "--encoding=none '$H'" "$TEST_DIRECTORY"/t3900/'$H'.txt
179 test_commit_autosquash_flags
() {
182 test_expect_success
"commit --$flag with $H encoding" '
183 git config i18n.commitencoding $H &&
184 git checkout -b $H-$flag C0 &&
186 git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt &&
188 echo intermediate stuff >>G &&
190 git commit -a -m "intermediate commit" &&
193 git commit -a --$flag HEAD~1 &&
194 E=$(git cat-file commit '$H-$flag' |
195 sed -ne "s/^encoding //p") &&
196 test "z$E" = "z$H" &&
197 git config --unset-all i18n.commitencoding &&
198 git rebase --autosquash -i HEAD^^^ &&
199 git log --oneline >actual &&
200 test_line_count = 3 actual
204 test_commit_autosquash_flags eucJP fixup
206 test_commit_autosquash_flags ISO-2022-JP squash
208 test_commit_autosquash_multi_encoding
() {
213 test_expect_success
"commit --$flag into $old from $new" '
214 git checkout -b $flag-$old-$new C0 &&
215 git config i18n.commitencoding $old &&
217 git commit -a -F "$TEST_DIRECTORY"/t3900/$msg &&
219 echo intermediate stuff >>G &&
221 git commit -a -m "intermediate commit" &&
223 git config i18n.commitencoding $new &&
224 echo $new-$flag >>F &&
225 git commit -a --$flag HEAD^ &&
226 git rebase --autosquash -i HEAD^^^ &&
227 git rev-list HEAD >actual &&
228 test_line_count = 3 actual &&
229 iconv -f $old -t UTF-8 "$TEST_DIRECTORY"/t3900/$msg >expect &&
230 git cat-file commit HEAD^ >raw &&
231 (sed "1,/^$/d" raw | iconv -f $new -t utf-8) >actual &&
232 test_cmp expect actual
236 test_commit_autosquash_multi_encoding fixup UTF-8 ISO-8859-1
1-UTF-8.txt
237 test_commit_autosquash_multi_encoding squash ISO-8859-1 UTF-8 ISO8859-1.txt
238 test_commit_autosquash_multi_encoding squash eucJP ISO-2022-JP eucJP.txt
239 test_commit_autosquash_multi_encoding fixup ISO-2022-JP UTF-8 ISO-2022-JP.txt