]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3900-i18n-commit.sh
051ea9d3c289d825601aed0a3055b1565370dc3a
[thirdparty/git.git] / t / t3900-i18n-commit.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Junio C Hamano
4 #
5
6 test_description='commit and log output encodings'
7
8 . ./test-lib.sh
9
10 compare_with () {
11 git show -s $1 | sed -e '1,/^$/d' -e 's/^ //' >current &&
12 case "$3" in
13 '')
14 test_cmp "$2" current ;;
15 ?*)
16 iconv -f "$3" -t UTF-8 >current.utf8 <current &&
17 iconv -f "$3" -t UTF-8 >expect.utf8 <"$2" &&
18 test_cmp expect.utf8 current.utf8
19 ;;
20 esac
21 }
22
23 test_expect_success setup '
24 : >F &&
25 git add F &&
26 T=$(git write-tree) &&
27 C=$(git commit-tree $T <"$TEST_DIRECTORY"/t3900/1-UTF-8.txt) &&
28 git update-ref HEAD $C &&
29 git tag C0
30 '
31
32 test_expect_success 'no encoding header for base case' '
33 E=$(git cat-file commit C0 | sed -ne "s/^encoding //p") &&
34 test z = "z$E"
35 '
36
37 test_expect_failure 'UTF-16 refused because of NULs' '
38 echo UTF-16 >F &&
39 git commit -a -F "$TEST_DIRECTORY"/t3900/UTF-16.txt
40 '
41
42 test_expect_success 'UTF-8 invalid characters refused' '
43 test_when_finished "rm -f $HOME/stderr $HOME/invalid" &&
44 echo "UTF-8 characters" >F &&
45 printf "Commit message\n\nInvalid surrogate:\355\240\200\n" \
46 >"$HOME/invalid" &&
47 git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
48 grep "did not conform" "$HOME"/stderr
49 '
50
51 test_expect_success 'UTF-8 overlong sequences rejected' '
52 test_when_finished "rm -f $HOME/stderr $HOME/invalid" &&
53 rm -f "$HOME/stderr" "$HOME/invalid" &&
54 echo "UTF-8 overlong" >F &&
55 printf "\340\202\251ommit message\n\nThis is not a space:\300\240\n" \
56 >"$HOME/invalid" &&
57 git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
58 grep "did not conform" "$HOME"/stderr
59 '
60
61 for H in ISO8859-1 eucJP ISO-2022-JP
62 do
63 test_expect_success "$H setup" '
64 git config i18n.commitencoding $H &&
65 git checkout -b $H C0 &&
66 echo $H >F &&
67 git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt
68 '
69 done
70
71 for H in ISO8859-1 eucJP ISO-2022-JP
72 do
73 test_expect_success "check encoding header for $H" '
74 E=$(git cat-file commit '$H' | sed -ne "s/^encoding //p") &&
75 test "z$E" = "z'$H'"
76 '
77 done
78
79 test_expect_success 'config to remove customization' '
80 git config --unset-all i18n.commitencoding &&
81 if Z=$(git config --get-all i18n.commitencoding)
82 then
83 echo Oops, should have failed.
84 false
85 else
86 test z = "z$Z"
87 fi &&
88 git config i18n.commitencoding UTF-8
89 '
90
91 test_expect_success 'ISO8859-1 should be shown in UTF-8 now' '
92 compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
93 '
94
95 for H in eucJP ISO-2022-JP
96 do
97 test_expect_success "$H should be shown in UTF-8 now" '
98 compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
99 '
100 done
101
102 test_expect_success 'config to add 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 '
112
113 for H in ISO8859-1 eucJP ISO-2022-JP
114 do
115 test_expect_success "$H should be shown in itself now" '
116 git config i18n.commitencoding '$H' &&
117 compare_with '$H' "$TEST_DIRECTORY"/t3900/'$H'.txt
118 '
119 done
120
121 test_expect_success 'config to tweak customization' '
122 git config i18n.logoutputencoding UTF-8
123 '
124
125 test_expect_success 'ISO8859-1 should be shown in UTF-8 now' '
126 compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
127 '
128
129 for H in eucJP ISO-2022-JP
130 do
131 test_expect_success "$H should be shown in UTF-8 now" '
132 compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
133 '
134 done
135
136 for J in eucJP ISO-2022-JP
137 do
138 if test "$J" = ISO-2022-JP
139 then
140 ICONV=$J
141 else
142 ICONV=
143 fi
144 git config i18n.logoutputencoding $J
145 for H in eucJP ISO-2022-JP
146 do
147 test_expect_success "$H should be shown in $J now" '
148 compare_with '$H' "$TEST_DIRECTORY"/t3900/'$J'.txt $ICONV
149 '
150 done
151 done
152
153 for H in ISO8859-1 eucJP ISO-2022-JP
154 do
155 test_expect_success "No conversion with $H" '
156 compare_with "--encoding=none '$H'" "$TEST_DIRECTORY"/t3900/'$H'.txt
157 '
158 done
159
160 test_commit_autosquash_flags () {
161 H=$1
162 flag=$2
163 test_expect_success "commit --$flag with $H encoding" '
164 git config i18n.commitencoding $H &&
165 git checkout -b $H-$flag C0 &&
166 echo $H >>F &&
167 git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt &&
168 test_tick &&
169 echo intermediate stuff >>G &&
170 git add G &&
171 git commit -a -m "intermediate commit" &&
172 test_tick &&
173 echo $H $flag >>F &&
174 git commit -a --$flag HEAD~1 &&
175 E=$(git cat-file commit '$H-$flag' |
176 sed -ne "s/^encoding //p") &&
177 test "z$E" = "z$H" &&
178 git config --unset-all i18n.commitencoding &&
179 git rebase --autosquash -i HEAD^^^ &&
180 git log --oneline >actual &&
181 test_line_count = 3 actual
182 '
183 }
184
185 test_commit_autosquash_flags eucJP fixup
186
187 test_commit_autosquash_flags ISO-2022-JP squash
188
189 test_done