Sync with 'maint'
[alt-git.git] / t / t3900-i18n-commit.sh
blob9d4b5ab1f9520f3892a32e17239ae6cb34184269
1 #!/bin/sh
3 # Copyright (c) 2006 Junio C Hamano
6 test_description='commit and log output encodings'
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 if ! test_have_prereq ICONV
12 then
13 skip_all='skipping commit i18n tests; iconv not available'
14 test_done
17 compare_with () {
18 git show -s $1 | sed -e '1,/^$/d' -e 's/^ //' >current &&
19 case "$3" in
20 '')
21 test_cmp "$2" current ;;
22 ?*)
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
27 esac
30 test_expect_success setup '
31 : >F &&
32 git add F &&
33 T=$(git write-tree) &&
34 C=$(git commit-tree $T <"$TEST_DIRECTORY"/t3900/1-UTF-8.txt) &&
35 git update-ref HEAD $C &&
36 git tag C0
39 test_expect_success 'no encoding header for base case' '
40 E=$(git cat-file commit C0 | sed -ne "s/^encoding //p") &&
41 test z = "z$E"
44 test_expect_success 'UTF-16 refused because of NULs' '
45 echo UTF-16 >F &&
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" \
53 >"$HOME/invalid" &&
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" \
63 >"$HOME/invalid" &&
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" \
72 >"$HOME/invalid" &&
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" \
81 >"$HOME/invalid" &&
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 &&
91 echo $H >F &&
92 git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt
94 done
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") &&
100 test "z$E" = "z'$H'"
102 done
104 test_expect_success 'config to remove customization' '
105 git config --unset-all i18n.commitencoding &&
106 if Z=$(git config --get-all i18n.commitencoding)
107 then
108 echo Oops, should have failed.
109 false
110 else
111 test z = "z$Z"
112 fi &&
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
125 done
127 test_expect_success 'config to add customization' '
128 git config --unset-all i18n.commitencoding &&
129 if Z=$(git config --get-all i18n.commitencoding)
130 then
131 echo Oops, should have failed.
132 false
133 else
134 test z = "z$Z"
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
144 done
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
159 done
161 for J in eucJP ISO-2022-JP
163 if test "$J" = ISO-2022-JP
164 then
165 ICONV=$J
166 else
167 ICONV=
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
175 done
176 done
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
183 done
185 test_commit_autosquash_flags () {
186 H=$1
187 flag=$2
188 test_expect_success "commit --$flag with $H encoding" '
189 git config i18n.commitencoding $H &&
190 git checkout -b $H-$flag C0 &&
191 echo $H >>F &&
192 git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt &&
193 test_tick &&
194 echo intermediate stuff >>G &&
195 git add G &&
196 git commit -a -m "intermediate commit" &&
197 test_tick &&
198 echo $H $flag >>F &&
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 () {
215 flag=$1
216 old=$2
217 new=$3
218 msg=$4
219 test_expect_success "commit --$flag into $old from $new" '
220 git checkout -b $flag-$old-$new C0 &&
221 git config i18n.commitencoding $old &&
222 echo $old >>F &&
223 git commit -a -F "$TEST_DIRECTORY"/t3900/$msg &&
224 test_tick &&
225 echo intermediate stuff >>G &&
226 git add G &&
227 git commit -a -m "intermediate commit" &&
228 test_tick &&
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
247 test_done