Interested in helping open source friends on HP-UX?
[git/mjg.git] / t / t3900-i18n-commit.sh
blobd522677b77933b1b7a8ef646be104066409a4774
1 #!/bin/sh
3 # Copyright (c) 2006 Junio C Hamano
6 test_description='commit and log output encodings'
8 . ./test-lib.sh
10 if ! test_have_prereq ICONV; then
11 skip_all='skipping i18n tests, iconv not available'
12 test_done
15 compare_with () {
16 git show -s $1 | sed -e '1,/^$/d' -e 's/^ //' >current &&
17 case "$3" in
18 '')
19 test_cmp "$2" current ;;
20 ?*)
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
25 esac
28 test_expect_success setup '
29 : >F &&
30 git add F &&
31 T=$(git write-tree) &&
32 C=$(git commit-tree $T <"$TEST_DIRECTORY"/t3900/1-UTF-8.txt) &&
33 git update-ref HEAD $C &&
34 git tag C0
37 test_expect_success 'no encoding header for base case' '
38 E=$(git cat-file commit C0 | sed -ne "s/^encoding //p") &&
39 test z = "z$E"
42 test_expect_success 'UTF-16 refused because of NULs' '
43 echo UTF-16 >F &&
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" \
51 >"$HOME/invalid" &&
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" \
61 >"$HOME/invalid" &&
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" \
70 >"$HOME/invalid" &&
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" \
79 >"$HOME/invalid" &&
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 &&
89 echo $H >F &&
90 git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt
92 done
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") &&
98 test "z$E" = "z'$H'"
100 done
102 test_expect_success 'config to remove customization' '
103 git config --unset-all i18n.commitencoding &&
104 if Z=$(git config --get-all i18n.commitencoding)
105 then
106 echo Oops, should have failed.
107 false
108 else
109 test z = "z$Z"
110 fi &&
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
123 done
125 test_expect_success 'config to add customization' '
126 git config --unset-all i18n.commitencoding &&
127 if Z=$(git config --get-all i18n.commitencoding)
128 then
129 echo Oops, should have failed.
130 false
131 else
132 test z = "z$Z"
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
142 done
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
157 done
159 for J in eucJP ISO-2022-JP
161 if test "$J" = ISO-2022-JP
162 then
163 ICONV=$J
164 else
165 ICONV=
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
173 done
174 done
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
181 done
183 test_commit_autosquash_flags () {
184 H=$1
185 flag=$2
186 test_expect_success "commit --$flag with $H encoding" '
187 git config i18n.commitencoding $H &&
188 git checkout -b $H-$flag C0 &&
189 echo $H >>F &&
190 git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt &&
191 test_tick &&
192 echo intermediate stuff >>G &&
193 git add G &&
194 git commit -a -m "intermediate commit" &&
195 test_tick &&
196 echo $H $flag >>F &&
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
212 test_done