3 # Copyright (c) 2006 Junio C Hamano
6 test_description
='commit and log output encodings'
10 if ! test_have_prereq ICONV
; then
11 skip_all
='skipping i18n tests, iconv not available'
16 git show
-s $1 |
sed -e '1,/^$/d' -e 's/^ //' >current
&&
19 test_cmp
"$2" current
;;
21 iconv -f "$3" -t UTF-8
>current.utf8
<current
&&
22 iconv -f "$3" -t UTF-8
>expect.utf8
<"$2" &&
23 test_cmp expect.utf8 current.utf8
28 test_expect_success setup
'
31 T=$(git write-tree) &&
32 C=$(git commit-tree $T <"$TEST_DIRECTORY"/t3900/1-UTF-8.txt) &&
33 git update-ref HEAD $C &&
37 test_expect_success
'no encoding header for base case' '
38 E=$(git cat-file commit C0 | sed -ne "s/^encoding //p") &&
42 test_expect_success
'UTF-16 refused because of NULs' '
44 test_must_fail git commit -a -F "$TEST_DIRECTORY"/t3900/UTF-16.txt
47 test_expect_success
'UTF-8 invalid characters refused' '
48 test_when_finished "rm -f $HOME/stderr $HOME/invalid" &&
49 echo "UTF-8 characters" >F &&
50 printf "Commit message\n\nInvalid surrogate:\355\240\200\n" \
52 git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
53 grep "did not conform" "$HOME"/stderr
56 test_expect_success
'UTF-8 overlong sequences rejected' '
57 test_when_finished "rm -f $HOME/stderr $HOME/invalid" &&
58 rm -f "$HOME/stderr" "$HOME/invalid" &&
59 echo "UTF-8 overlong" >F &&
60 printf "\340\202\251ommit message\n\nThis is not a space:\300\240\n" \
62 git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
63 grep "did not conform" "$HOME"/stderr
66 test_expect_success
'UTF-8 non-characters refused' '
67 test_when_finished "rm -f $HOME/stderr $HOME/invalid" &&
68 echo "UTF-8 non-character 1" >F &&
69 printf "Commit message\n\nNon-character:\364\217\277\276\n" \
71 git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
72 grep "did not conform" "$HOME"/stderr
75 test_expect_success
'UTF-8 non-characters refused' '
76 test_when_finished "rm -f $HOME/stderr $HOME/invalid" &&
77 echo "UTF-8 non-character 2." >F &&
78 printf "Commit message\n\nNon-character:\357\267\220\n" \
80 git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
81 grep "did not conform" "$HOME"/stderr
84 for H
in ISO8859-1 eucJP ISO-2022-JP
86 test_expect_success
"$H setup" '
87 git config i18n.commitencoding $H &&
88 git checkout -b $H C0 &&
90 git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt
94 for H
in ISO8859-1 eucJP ISO-2022-JP
96 test_expect_success
"check encoding header for $H" '
97 E=$(git cat-file commit '$H' | sed -ne "s/^encoding //p") &&
102 test_expect_success
'config to remove customization' '
103 git config --unset-all i18n.commitencoding &&
104 if Z=$(git config --get-all i18n.commitencoding)
106 echo Oops, should have failed.
111 git config i18n.commitencoding UTF-8
114 test_expect_success
'ISO8859-1 should be shown in UTF-8 now' '
115 compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
118 for H
in eucJP ISO-2022-JP
120 test_expect_success
"$H should be shown in UTF-8 now" '
121 compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
125 test_expect_success
'config to add customization' '
126 git config --unset-all i18n.commitencoding &&
127 if Z=$(git config --get-all i18n.commitencoding)
129 echo Oops, should have failed.
136 for H
in ISO8859-1 eucJP ISO-2022-JP
138 test_expect_success
"$H should be shown in itself now" '
139 git config i18n.commitencoding '$H' &&
140 compare_with '$H' "$TEST_DIRECTORY"/t3900/'$H'.txt
144 test_expect_success
'config to tweak customization' '
145 git config i18n.logoutputencoding UTF-8
148 test_expect_success
'ISO8859-1 should be shown in UTF-8 now' '
149 compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
152 for H
in eucJP ISO-2022-JP
154 test_expect_success
"$H should be shown in UTF-8 now" '
155 compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
159 for J
in eucJP ISO-2022-JP
161 if test "$J" = ISO-2022-JP
167 git config i18n.logoutputencoding
$J
168 for H
in eucJP ISO-2022-JP
170 test_expect_success
"$H should be shown in $J now" '
171 compare_with '$H' "$TEST_DIRECTORY"/t3900/'$J'.txt $ICONV
176 for H
in ISO8859-1 eucJP ISO-2022-JP
178 test_expect_success
"No conversion with $H" '
179 compare_with "--encoding=none '$H'" "$TEST_DIRECTORY"/t3900/'$H'.txt
183 test_commit_autosquash_flags
() {
186 test_expect_success
"commit --$flag with $H encoding" '
187 git config i18n.commitencoding $H &&
188 git checkout -b $H-$flag C0 &&
190 git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt &&
192 echo intermediate stuff >>G &&
194 git commit -a -m "intermediate commit" &&
197 git commit -a --$flag HEAD~1 &&
198 E=$(git cat-file commit '$H-$flag' |
199 sed -ne "s/^encoding //p") &&
200 test "z$E" = "z$H" &&
201 git config --unset-all i18n.commitencoding &&
202 git rebase --autosquash -i HEAD^^^ &&
203 git log --oneline >actual &&
204 test_line_count = 3 actual
208 test_commit_autosquash_flags eucJP fixup
210 test_commit_autosquash_flags ISO-2022-JP squash