blob: b92ff95977281e7ebb727fe5079e03aa301f4111 [file] [log] [blame]
Junio C Hamanod2c11a32006-12-27 16:41:33 -08001#!/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 () {
Linus Torvalds304b5af2007-10-09 09:35:22 -070011 git show -s $1 | sed -e '1,/^$/d' -e 's/^ //' >current &&
Junio C Hamanoeb127882009-05-12 02:01:51 -070012 case "$3" in
13 '')
14 test_cmp "$2" current ;;
15 ?*)
Alex Riesen39d404d2009-05-14 14:55:54 +020016 iconv -f "$3" -t UTF-8 >current.utf8 <current &&
17 iconv -f "$3" -t UTF-8 >expect.utf8 <"$2" &&
Junio C Hamanoeb127882009-05-12 02:01:51 -070018 test_cmp expect.utf8 current.utf8
19 ;;
20 esac
Junio C Hamanod2c11a32006-12-27 16:41:33 -080021}
22
23test_expect_success setup '
24 : >F &&
Junio C Hamano5be60072007-07-02 22:52:14 -070025 git add F &&
26 T=$(git write-tree) &&
Junio C Hamanobfdbee92008-08-08 02:26:28 -070027 C=$(git commit-tree $T <"$TEST_DIRECTORY"/t3900/1-UTF-8.txt) &&
Junio C Hamano5be60072007-07-02 22:52:14 -070028 git update-ref HEAD $C &&
Nanako Shiraishi0cb0e142008-09-03 17:59:27 +090029 git tag C0
Junio C Hamanod2c11a32006-12-27 16:41:33 -080030'
31
32test_expect_success 'no encoding header for base case' '
Junio C Hamano5be60072007-07-02 22:52:14 -070033 E=$(git cat-file commit C0 | sed -ne "s/^encoding //p") &&
Junio C Hamanod2c11a32006-12-27 16:41:33 -080034 test z = "z$E"
35'
36
Junio C Hamano0ed45a12013-08-05 09:47:11 -070037test_expect_success 'UTF-16 refused because of NULs' '
Nguyễn Thái Ngọc Duy37576c12011-12-15 20:47:23 +070038 echo UTF-16 >F &&
Junio C Hamano0ed45a12013-08-05 09:47:11 -070039 test_must_fail git commit -a -F "$TEST_DIRECTORY"/t3900/UTF-16.txt
Nguyễn Thái Ngọc Duy37576c12011-12-15 20:47:23 +070040'
41
brian m. carlson28110d42013-07-04 17:19:43 +000042test_expect_success 'UTF-8 invalid characters refused' '
Beat Bolli36a6f492018-01-10 10:58:32 +010043 test_when_finished "rm -f \"\$HOME/stderr\" \"\$HOME/invalid\"" &&
brian m. carlson28110d42013-07-04 17:19:43 +000044 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 &&
Vasco Almeida4fa4b312016-09-19 13:08:16 +000048 test_i18ngrep "did not conform" "$HOME"/stderr
brian m. carlson28110d42013-07-04 17:19:43 +000049'
Nguyễn Thái Ngọc Duy37576c12011-12-15 20:47:23 +070050
brian m. carlsone82bd6c2013-07-04 17:20:34 +000051test_expect_success 'UTF-8 overlong sequences rejected' '
Beat Bolli36a6f492018-01-10 10:58:32 +010052 test_when_finished "rm -f \"\$HOME/stderr\" \"\$HOME/invalid\"" &&
brian m. carlsone82bd6c2013-07-04 17:20:34 +000053 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 &&
Vasco Almeida4fa4b312016-09-19 13:08:16 +000058 test_i18ngrep "did not conform" "$HOME"/stderr
brian m. carlsone82bd6c2013-07-04 17:20:34 +000059'
60
Peter Krefting81050ac2013-07-09 12:16:33 +010061test_expect_success 'UTF-8 non-characters refused' '
Beat Bolli36a6f492018-01-10 10:58:32 +010062 test_when_finished "rm -f \"\$HOME/stderr\" \"\$HOME/invalid\"" &&
Peter Krefting81050ac2013-07-09 12:16:33 +010063 echo "UTF-8 non-character 1" >F &&
64 printf "Commit message\n\nNon-character:\364\217\277\276\n" \
65 >"$HOME/invalid" &&
66 git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
Vasco Almeida4fa4b312016-09-19 13:08:16 +000067 test_i18ngrep "did not conform" "$HOME"/stderr
Peter Krefting81050ac2013-07-09 12:16:33 +010068'
69
70test_expect_success 'UTF-8 non-characters refused' '
Beat Bolli36a6f492018-01-10 10:58:32 +010071 test_when_finished "rm -f \"\$HOME/stderr\" \"\$HOME/invalid\"" &&
Peter Krefting81050ac2013-07-09 12:16:33 +010072 echo "UTF-8 non-character 2." >F &&
73 printf "Commit message\n\nNon-character:\357\267\220\n" \
74 >"$HOME/invalid" &&
75 git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
Vasco Almeida4fa4b312016-09-19 13:08:16 +000076 test_i18ngrep "did not conform" "$HOME"/stderr
Peter Krefting81050ac2013-07-09 12:16:33 +010077'
78
Brandon Casey5ae93df2009-05-18 18:44:38 -050079for H in ISO8859-1 eucJP ISO-2022-JP
Junio C Hamanod2c11a32006-12-27 16:41:33 -080080do
81 test_expect_success "$H setup" '
Junio C Hamano5be60072007-07-02 22:52:14 -070082 git config i18n.commitencoding $H &&
Nanako Shiraishi0cb0e142008-09-03 17:59:27 +090083 git checkout -b $H C0 &&
Junio C Hamanod2c11a32006-12-27 16:41:33 -080084 echo $H >F &&
Junio C Hamano9b8ae932008-09-03 16:08:23 -070085 git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt
Junio C Hamanod2c11a32006-12-27 16:41:33 -080086 '
87done
88
Brandon Casey5ae93df2009-05-18 18:44:38 -050089for H in ISO8859-1 eucJP ISO-2022-JP
Junio C Hamanod2c11a32006-12-27 16:41:33 -080090do
91 test_expect_success "check encoding header for $H" '
Junio C Hamano5be60072007-07-02 22:52:14 -070092 E=$(git cat-file commit '$H' | sed -ne "s/^encoding //p") &&
Junio C Hamanod2c11a32006-12-27 16:41:33 -080093 test "z$E" = "z'$H'"
94 '
95done
96
Tom Princee0d10e12007-01-28 16:16:53 -080097test_expect_success 'config to remove customization' '
Junio C Hamano5be60072007-07-02 22:52:14 -070098 git config --unset-all i18n.commitencoding &&
99 if Z=$(git config --get-all i18n.commitencoding)
Junio C Hamanod2c11a32006-12-27 16:41:33 -0800100 then
101 echo Oops, should have failed.
102 false
103 else
104 test z = "z$Z"
105 fi &&
Brandon Casey5ae93df2009-05-18 18:44:38 -0500106 git config i18n.commitencoding UTF-8
Junio C Hamanod2c11a32006-12-27 16:41:33 -0800107'
108
Brandon Casey5ae93df2009-05-18 18:44:38 -0500109test_expect_success 'ISO8859-1 should be shown in UTF-8 now' '
110 compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
Junio C Hamanod2c11a32006-12-27 16:41:33 -0800111'
112
Brandon Casey5ae93df2009-05-18 18:44:38 -0500113for H in eucJP ISO-2022-JP
Junio C Hamanod2c11a32006-12-27 16:41:33 -0800114do
115 test_expect_success "$H should be shown in UTF-8 now" '
Junio C Hamanobfdbee92008-08-08 02:26:28 -0700116 compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
Junio C Hamanod2c11a32006-12-27 16:41:33 -0800117 '
118done
119
Tom Princee0d10e12007-01-28 16:16:53 -0800120test_expect_success 'config to add customization' '
Junio C Hamano5be60072007-07-02 22:52:14 -0700121 git config --unset-all i18n.commitencoding &&
122 if Z=$(git config --get-all i18n.commitencoding)
Junio C Hamanod2c11a32006-12-27 16:41:33 -0800123 then
124 echo Oops, should have failed.
125 false
126 else
127 test z = "z$Z"
128 fi
129'
130
Brandon Casey5ae93df2009-05-18 18:44:38 -0500131for H in ISO8859-1 eucJP ISO-2022-JP
Junio C Hamanod2c11a32006-12-27 16:41:33 -0800132do
133 test_expect_success "$H should be shown in itself now" '
Junio C Hamano5be60072007-07-02 22:52:14 -0700134 git config i18n.commitencoding '$H' &&
Junio C Hamanobfdbee92008-08-08 02:26:28 -0700135 compare_with '$H' "$TEST_DIRECTORY"/t3900/'$H'.txt
Junio C Hamanod2c11a32006-12-27 16:41:33 -0800136 '
137done
138
Tom Princee0d10e12007-01-28 16:16:53 -0800139test_expect_success 'config to tweak customization' '
Brandon Casey5ae93df2009-05-18 18:44:38 -0500140 git config i18n.logoutputencoding UTF-8
Junio C Hamanod2c11a32006-12-27 16:41:33 -0800141'
142
Brandon Casey5ae93df2009-05-18 18:44:38 -0500143test_expect_success 'ISO8859-1 should be shown in UTF-8 now' '
144 compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
Junio C Hamanod2c11a32006-12-27 16:41:33 -0800145'
146
Brandon Casey5ae93df2009-05-18 18:44:38 -0500147for H in eucJP ISO-2022-JP
Junio C Hamanod2c11a32006-12-27 16:41:33 -0800148do
149 test_expect_success "$H should be shown in UTF-8 now" '
Junio C Hamanobfdbee92008-08-08 02:26:28 -0700150 compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
Junio C Hamanod2c11a32006-12-27 16:41:33 -0800151 '
152done
153
Brandon Casey5ae93df2009-05-18 18:44:38 -0500154for J in eucJP ISO-2022-JP
Junio C Hamano7255ff02006-12-28 17:36:35 -0800155do
Junio C Hamanoeb127882009-05-12 02:01:51 -0700156 if test "$J" = ISO-2022-JP
157 then
158 ICONV=$J
159 else
160 ICONV=
161 fi
Junio C Hamano5be60072007-07-02 22:52:14 -0700162 git config i18n.logoutputencoding $J
Brandon Casey5ae93df2009-05-18 18:44:38 -0500163 for H in eucJP ISO-2022-JP
Junio C Hamano7255ff02006-12-28 17:36:35 -0800164 do
165 test_expect_success "$H should be shown in $J now" '
Junio C Hamanoeb127882009-05-12 02:01:51 -0700166 compare_with '$H' "$TEST_DIRECTORY"/t3900/'$J'.txt $ICONV
Junio C Hamano7255ff02006-12-28 17:36:35 -0800167 '
168 done
169done
170
Brandon Casey5ae93df2009-05-18 18:44:38 -0500171for H in ISO8859-1 eucJP ISO-2022-JP
Junio C Hamano00079282006-12-30 02:35:14 -0800172do
173 test_expect_success "No conversion with $H" '
Junio C Hamanobfdbee92008-08-08 02:26:28 -0700174 compare_with "--encoding=none '$H'" "$TEST_DIRECTORY"/t3900/'$H'.txt
Junio C Hamano00079282006-12-30 02:35:14 -0800175 '
176done
177
Pat Notzb1a6c0a2010-11-02 13:59:10 -0600178test_commit_autosquash_flags () {
179 H=$1
180 flag=$2
181 test_expect_success "commit --$flag with $H encoding" '
182 git config i18n.commitencoding $H &&
183 git checkout -b $H-$flag C0 &&
184 echo $H >>F &&
185 git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt &&
186 test_tick &&
187 echo intermediate stuff >>G &&
188 git add G &&
189 git commit -a -m "intermediate commit" &&
190 test_tick &&
191 echo $H $flag >>F &&
Johannes Sixt23ce5c32011-08-11 09:05:48 +0200192 git commit -a --$flag HEAD~1 &&
Pat Notzb1a6c0a2010-11-02 13:59:10 -0600193 E=$(git cat-file commit '$H-$flag' |
194 sed -ne "s/^encoding //p") &&
195 test "z$E" = "z$H" &&
196 git config --unset-all i18n.commitencoding &&
197 git rebase --autosquash -i HEAD^^^ &&
198 git log --oneline >actual &&
Stefano Lattarini3fb04592012-04-11 13:24:01 +0200199 test_line_count = 3 actual
Pat Notzb1a6c0a2010-11-02 13:59:10 -0600200 '
201}
202
203test_commit_autosquash_flags eucJP fixup
204
Johannes Sixt23ce5c32011-08-11 09:05:48 +0200205test_commit_autosquash_flags ISO-2022-JP squash
Pat Notz7951bd32010-11-02 13:59:12 -0600206
Junio C Hamanod2c11a32006-12-27 16:41:33 -0800207test_done