Git 2.46-rc1
[git.git] / t / t3900-i18n-commit.sh
blobdb7b403bc1541d8eed62eb65f21ce5ba262d8128
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 compare_with () {
12 git show -s $1 | sed -e '1,/^$/d' -e 's/^ //' >current &&
13 case "$3" in
14 '')
15 test_cmp "$2" current ;;
16 ?*)
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
21 esac
24 test_expect_success setup '
25 : >F &&
26 git add F &&
27 T=$(git write-tree) &&
28 C=$(git commit-tree $T <"$TEST_DIRECTORY"/t3900/1-UTF-8.txt) &&
29 git update-ref HEAD $C &&
30 git tag C0
33 test_expect_success 'no encoding header for base case' '
34 E=$(git cat-file commit C0 | sed -ne "s/^encoding //p") &&
35 test z = "z$E"
38 test_expect_success 'UTF-16 refused because of NULs' '
39 echo UTF-16 >F &&
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" \
47 >"$HOME/invalid" &&
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" \
57 >"$HOME/invalid" &&
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" \
66 >"$HOME/invalid" &&
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" \
75 >"$HOME/invalid" &&
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 &&
85 echo $H >F &&
86 git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt
88 done
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") &&
94 test "z$E" = "z'$H'"
96 done
98 test_expect_success 'config to remove customization' '
99 git config --unset-all i18n.commitencoding &&
100 if Z=$(git config --get-all i18n.commitencoding)
101 then
102 echo Oops, should have failed.
103 false
104 else
105 test z = "z$Z"
106 fi &&
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
119 done
121 test_expect_success 'config to add customization' '
122 git config --unset-all i18n.commitencoding &&
123 if Z=$(git config --get-all i18n.commitencoding)
124 then
125 echo Oops, should have failed.
126 false
127 else
128 test z = "z$Z"
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
138 done
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
153 done
155 for J in eucJP ISO-2022-JP
157 if test "$J" = ISO-2022-JP
158 then
159 ICONV=$J
160 else
161 ICONV=
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
169 done
170 done
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
177 done
179 test_commit_autosquash_flags () {
180 H=$1
181 flag=$2
182 test_expect_success "commit --$flag with $H encoding" '
183 git config i18n.commitencoding $H &&
184 git checkout -b $H-$flag C0 &&
185 echo $H >>F &&
186 git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt &&
187 test_tick &&
188 echo intermediate stuff >>G &&
189 git add G &&
190 git commit -a -m "intermediate commit" &&
191 test_tick &&
192 echo $H $flag >>F &&
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 () {
209 flag=$1
210 old=$2
211 new=$3
212 msg=$4
213 test_expect_success "commit --$flag into $old from $new" '
214 git checkout -b $flag-$old-$new C0 &&
215 git config i18n.commitencoding $old &&
216 echo $old >>F &&
217 git commit -a -F "$TEST_DIRECTORY"/t3900/$msg &&
218 test_tick &&
219 echo intermediate stuff >>G &&
220 git add G &&
221 git commit -a -m "intermediate commit" &&
222 test_tick &&
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
241 test_done