687669f28d930cb217f54b6f207f41a1835e17b7
1#!/bin/sh
2#
3# Copyright (c) 2006 Junio C Hamano
4#
5
6test_description='commit and log output encodings'
7
8. ./test-lib.sh
9
10compare_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
23test_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
32test_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
37test_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
42test_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
51for H in ISO8859-1 eucJP ISO-2022-JP
52do
53 test_expect_success "$H setup" '
54 git config i18n.commitencoding $H &&
55 git checkout -b $H C0 &&
56 echo $H >F &&
57 git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt
58 '
59done
60
61for H in ISO8859-1 eucJP ISO-2022-JP
62do
63 test_expect_success "check encoding header for $H" '
64 E=$(git cat-file commit '$H' | sed -ne "s/^encoding //p") &&
65 test "z$E" = "z'$H'"
66 '
67done
68
69test_expect_success 'config to remove customization' '
70 git config --unset-all i18n.commitencoding &&
71 if Z=$(git config --get-all i18n.commitencoding)
72 then
73 echo Oops, should have failed.
74 false
75 else
76 test z = "z$Z"
77 fi &&
78 git config i18n.commitencoding UTF-8
79'
80
81test_expect_success 'ISO8859-1 should be shown in UTF-8 now' '
82 compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
83'
84
85for H in eucJP ISO-2022-JP
86do
87 test_expect_success "$H should be shown in UTF-8 now" '
88 compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
89 '
90done
91
92test_expect_success 'config to add customization' '
93 git config --unset-all i18n.commitencoding &&
94 if Z=$(git config --get-all i18n.commitencoding)
95 then
96 echo Oops, should have failed.
97 false
98 else
99 test z = "z$Z"
100 fi
101'
102
103for H in ISO8859-1 eucJP ISO-2022-JP
104do
105 test_expect_success "$H should be shown in itself now" '
106 git config i18n.commitencoding '$H' &&
107 compare_with '$H' "$TEST_DIRECTORY"/t3900/'$H'.txt
108 '
109done
110
111test_expect_success 'config to tweak customization' '
112 git config i18n.logoutputencoding UTF-8
113'
114
115test_expect_success 'ISO8859-1 should be shown in UTF-8 now' '
116 compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
117'
118
119for H in eucJP ISO-2022-JP
120do
121 test_expect_success "$H should be shown in UTF-8 now" '
122 compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
123 '
124done
125
126for J in eucJP ISO-2022-JP
127do
128 if test "$J" = ISO-2022-JP
129 then
130 ICONV=$J
131 else
132 ICONV=
133 fi
134 git config i18n.logoutputencoding $J
135 for H in eucJP ISO-2022-JP
136 do
137 test_expect_success "$H should be shown in $J now" '
138 compare_with '$H' "$TEST_DIRECTORY"/t3900/'$J'.txt $ICONV
139 '
140 done
141done
142
143for H in ISO8859-1 eucJP ISO-2022-JP
144do
145 test_expect_success "No conversion with $H" '
146 compare_with "--encoding=none '$H'" "$TEST_DIRECTORY"/t3900/'$H'.txt
147 '
148done
149
150test_commit_autosquash_flags () {
151 H=$1
152 flag=$2
153 test_expect_success "commit --$flag with $H encoding" '
154 git config i18n.commitencoding $H &&
155 git checkout -b $H-$flag C0 &&
156 echo $H >>F &&
157 git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt &&
158 test_tick &&
159 echo intermediate stuff >>G &&
160 git add G &&
161 git commit -a -m "intermediate commit" &&
162 test_tick &&
163 echo $H $flag >>F &&
164 git commit -a --$flag HEAD~1 &&
165 E=$(git cat-file commit '$H-$flag' |
166 sed -ne "s/^encoding //p") &&
167 test "z$E" = "z$H" &&
168 git config --unset-all i18n.commitencoding &&
169 git rebase --autosquash -i HEAD^^^ &&
170 git log --oneline >actual &&
171 test_line_count = 3 actual
172 '
173}
174
175test_commit_autosquash_flags eucJP fixup
176
177test_commit_autosquash_flags ISO-2022-JP squash
178
179test_done