2006-12-28 00:41:33 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2006 Junio C Hamano
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='commit and log output encodings'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
compare_with () {
|
2007-10-09 16:35:22 +00:00
|
|
|
git show -s $1 | sed -e '1,/^$/d' -e 's/^ //' >current &&
|
2009-05-12 09:01:51 +00:00
|
|
|
case "$3" in
|
|
|
|
'')
|
|
|
|
test_cmp "$2" current ;;
|
|
|
|
?*)
|
2009-05-14 12:55:54 +00:00
|
|
|
iconv -f "$3" -t UTF-8 >current.utf8 <current &&
|
|
|
|
iconv -f "$3" -t UTF-8 >expect.utf8 <"$2" &&
|
2009-05-12 09:01:51 +00:00
|
|
|
test_cmp expect.utf8 current.utf8
|
|
|
|
;;
|
|
|
|
esac
|
2006-12-28 00:41:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
: >F &&
|
2007-07-03 05:52:14 +00:00
|
|
|
git add F &&
|
|
|
|
T=$(git write-tree) &&
|
2008-08-08 09:26:28 +00:00
|
|
|
C=$(git commit-tree $T <"$TEST_DIRECTORY"/t3900/1-UTF-8.txt) &&
|
2007-07-03 05:52:14 +00:00
|
|
|
git update-ref HEAD $C &&
|
2008-09-03 08:59:27 +00:00
|
|
|
git tag C0
|
2006-12-28 00:41:33 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'no encoding header for base case' '
|
2007-07-03 05:52:14 +00:00
|
|
|
E=$(git cat-file commit C0 | sed -ne "s/^encoding //p") &&
|
2006-12-28 00:41:33 +00:00
|
|
|
test z = "z$E"
|
|
|
|
'
|
|
|
|
|
2013-08-05 16:47:11 +00:00
|
|
|
test_expect_success 'UTF-16 refused because of NULs' '
|
2011-12-15 13:47:23 +00:00
|
|
|
echo UTF-16 >F &&
|
2013-08-05 16:47:11 +00:00
|
|
|
test_must_fail git commit -a -F "$TEST_DIRECTORY"/t3900/UTF-16.txt
|
2011-12-15 13:47:23 +00:00
|
|
|
'
|
|
|
|
|
2013-07-04 17:19:43 +00:00
|
|
|
test_expect_success 'UTF-8 invalid characters refused' '
|
2018-01-10 09:58:32 +00:00
|
|
|
test_when_finished "rm -f \"\$HOME/stderr\" \"\$HOME/invalid\"" &&
|
2013-07-04 17:19:43 +00:00
|
|
|
echo "UTF-8 characters" >F &&
|
|
|
|
printf "Commit message\n\nInvalid surrogate:\355\240\200\n" \
|
|
|
|
>"$HOME/invalid" &&
|
|
|
|
git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
|
2016-09-19 13:08:16 +00:00
|
|
|
test_i18ngrep "did not conform" "$HOME"/stderr
|
2013-07-04 17:20:34 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'UTF-8 overlong sequences rejected' '
|
2018-01-10 09:58:32 +00:00
|
|
|
test_when_finished "rm -f \"\$HOME/stderr\" \"\$HOME/invalid\"" &&
|
2013-07-04 17:20:34 +00:00
|
|
|
rm -f "$HOME/stderr" "$HOME/invalid" &&
|
|
|
|
echo "UTF-8 overlong" >F &&
|
|
|
|
printf "\340\202\251ommit message\n\nThis is not a space:\300\240\n" \
|
|
|
|
>"$HOME/invalid" &&
|
|
|
|
git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
|
2016-09-19 13:08:16 +00:00
|
|
|
test_i18ngrep "did not conform" "$HOME"/stderr
|
2013-07-09 11:16:33 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'UTF-8 non-characters refused' '
|
2018-01-10 09:58:32 +00:00
|
|
|
test_when_finished "rm -f \"\$HOME/stderr\" \"\$HOME/invalid\"" &&
|
2013-07-09 11:16:33 +00:00
|
|
|
echo "UTF-8 non-character 1" >F &&
|
|
|
|
printf "Commit message\n\nNon-character:\364\217\277\276\n" \
|
|
|
|
>"$HOME/invalid" &&
|
|
|
|
git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
|
2016-09-19 13:08:16 +00:00
|
|
|
test_i18ngrep "did not conform" "$HOME"/stderr
|
2013-07-09 11:16:33 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'UTF-8 non-characters refused' '
|
2018-01-10 09:58:32 +00:00
|
|
|
test_when_finished "rm -f \"\$HOME/stderr\" \"\$HOME/invalid\"" &&
|
2013-07-09 11:16:33 +00:00
|
|
|
echo "UTF-8 non-character 2." >F &&
|
|
|
|
printf "Commit message\n\nNon-character:\357\267\220\n" \
|
|
|
|
>"$HOME/invalid" &&
|
|
|
|
git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
|
2016-09-19 13:08:16 +00:00
|
|
|
test_i18ngrep "did not conform" "$HOME"/stderr
|
2013-07-04 17:19:43 +00:00
|
|
|
'
|
2011-12-15 13:47:23 +00:00
|
|
|
|
2009-05-18 23:44:38 +00:00
|
|
|
for H in ISO8859-1 eucJP ISO-2022-JP
|
2006-12-28 00:41:33 +00:00
|
|
|
do
|
|
|
|
test_expect_success "$H setup" '
|
2007-07-03 05:52:14 +00:00
|
|
|
git config i18n.commitencoding $H &&
|
2008-09-03 08:59:27 +00:00
|
|
|
git checkout -b $H C0 &&
|
2006-12-28 00:41:33 +00:00
|
|
|
echo $H >F &&
|
2008-09-03 23:08:23 +00:00
|
|
|
git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt
|
2006-12-28 00:41:33 +00:00
|
|
|
'
|
|
|
|
done
|
|
|
|
|
2009-05-18 23:44:38 +00:00
|
|
|
for H in ISO8859-1 eucJP ISO-2022-JP
|
2006-12-28 00:41:33 +00:00
|
|
|
do
|
|
|
|
test_expect_success "check encoding header for $H" '
|
2007-07-03 05:52:14 +00:00
|
|
|
E=$(git cat-file commit '$H' | sed -ne "s/^encoding //p") &&
|
2006-12-28 00:41:33 +00:00
|
|
|
test "z$E" = "z'$H'"
|
|
|
|
'
|
|
|
|
done
|
|
|
|
|
2007-01-29 00:16:53 +00:00
|
|
|
test_expect_success 'config to remove customization' '
|
2007-07-03 05:52:14 +00:00
|
|
|
git config --unset-all i18n.commitencoding &&
|
|
|
|
if Z=$(git config --get-all i18n.commitencoding)
|
2006-12-28 00:41:33 +00:00
|
|
|
then
|
|
|
|
echo Oops, should have failed.
|
|
|
|
false
|
|
|
|
else
|
|
|
|
test z = "z$Z"
|
|
|
|
fi &&
|
2009-05-18 23:44:38 +00:00
|
|
|
git config i18n.commitencoding UTF-8
|
2006-12-28 00:41:33 +00:00
|
|
|
'
|
|
|
|
|
2009-05-18 23:44:38 +00:00
|
|
|
test_expect_success 'ISO8859-1 should be shown in UTF-8 now' '
|
|
|
|
compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
|
2006-12-28 00:41:33 +00:00
|
|
|
'
|
|
|
|
|
2009-05-18 23:44:38 +00:00
|
|
|
for H in eucJP ISO-2022-JP
|
2006-12-28 00:41:33 +00:00
|
|
|
do
|
|
|
|
test_expect_success "$H should be shown in UTF-8 now" '
|
2008-08-08 09:26:28 +00:00
|
|
|
compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
|
2006-12-28 00:41:33 +00:00
|
|
|
'
|
|
|
|
done
|
|
|
|
|
2007-01-29 00:16:53 +00:00
|
|
|
test_expect_success 'config to add customization' '
|
2007-07-03 05:52:14 +00:00
|
|
|
git config --unset-all i18n.commitencoding &&
|
|
|
|
if Z=$(git config --get-all i18n.commitencoding)
|
2006-12-28 00:41:33 +00:00
|
|
|
then
|
|
|
|
echo Oops, should have failed.
|
|
|
|
false
|
|
|
|
else
|
|
|
|
test z = "z$Z"
|
|
|
|
fi
|
|
|
|
'
|
|
|
|
|
2009-05-18 23:44:38 +00:00
|
|
|
for H in ISO8859-1 eucJP ISO-2022-JP
|
2006-12-28 00:41:33 +00:00
|
|
|
do
|
|
|
|
test_expect_success "$H should be shown in itself now" '
|
2007-07-03 05:52:14 +00:00
|
|
|
git config i18n.commitencoding '$H' &&
|
2008-08-08 09:26:28 +00:00
|
|
|
compare_with '$H' "$TEST_DIRECTORY"/t3900/'$H'.txt
|
2006-12-28 00:41:33 +00:00
|
|
|
'
|
|
|
|
done
|
|
|
|
|
2007-01-29 00:16:53 +00:00
|
|
|
test_expect_success 'config to tweak customization' '
|
2009-05-18 23:44:38 +00:00
|
|
|
git config i18n.logoutputencoding UTF-8
|
2006-12-28 00:41:33 +00:00
|
|
|
'
|
|
|
|
|
2009-05-18 23:44:38 +00:00
|
|
|
test_expect_success 'ISO8859-1 should be shown in UTF-8 now' '
|
|
|
|
compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
|
2006-12-28 00:41:33 +00:00
|
|
|
'
|
|
|
|
|
2009-05-18 23:44:38 +00:00
|
|
|
for H in eucJP ISO-2022-JP
|
2006-12-28 00:41:33 +00:00
|
|
|
do
|
|
|
|
test_expect_success "$H should be shown in UTF-8 now" '
|
2008-08-08 09:26:28 +00:00
|
|
|
compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
|
2006-12-28 00:41:33 +00:00
|
|
|
'
|
|
|
|
done
|
|
|
|
|
2009-05-18 23:44:38 +00:00
|
|
|
for J in eucJP ISO-2022-JP
|
2006-12-29 01:36:35 +00:00
|
|
|
do
|
2009-05-12 09:01:51 +00:00
|
|
|
if test "$J" = ISO-2022-JP
|
|
|
|
then
|
|
|
|
ICONV=$J
|
|
|
|
else
|
|
|
|
ICONV=
|
|
|
|
fi
|
2007-07-03 05:52:14 +00:00
|
|
|
git config i18n.logoutputencoding $J
|
2009-05-18 23:44:38 +00:00
|
|
|
for H in eucJP ISO-2022-JP
|
2006-12-29 01:36:35 +00:00
|
|
|
do
|
|
|
|
test_expect_success "$H should be shown in $J now" '
|
2009-05-12 09:01:51 +00:00
|
|
|
compare_with '$H' "$TEST_DIRECTORY"/t3900/'$J'.txt $ICONV
|
2006-12-29 01:36:35 +00:00
|
|
|
'
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
2009-05-18 23:44:38 +00:00
|
|
|
for H in ISO8859-1 eucJP ISO-2022-JP
|
2006-12-30 10:35:14 +00:00
|
|
|
do
|
|
|
|
test_expect_success "No conversion with $H" '
|
2008-08-08 09:26:28 +00:00
|
|
|
compare_with "--encoding=none '$H'" "$TEST_DIRECTORY"/t3900/'$H'.txt
|
2006-12-30 10:35:14 +00:00
|
|
|
'
|
|
|
|
done
|
|
|
|
|
2010-11-02 19:59:10 +00:00
|
|
|
test_commit_autosquash_flags () {
|
|
|
|
H=$1
|
|
|
|
flag=$2
|
|
|
|
test_expect_success "commit --$flag with $H encoding" '
|
|
|
|
git config i18n.commitencoding $H &&
|
|
|
|
git checkout -b $H-$flag C0 &&
|
|
|
|
echo $H >>F &&
|
|
|
|
git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt &&
|
|
|
|
test_tick &&
|
|
|
|
echo intermediate stuff >>G &&
|
|
|
|
git add G &&
|
|
|
|
git commit -a -m "intermediate commit" &&
|
|
|
|
test_tick &&
|
|
|
|
echo $H $flag >>F &&
|
2011-08-11 07:05:48 +00:00
|
|
|
git commit -a --$flag HEAD~1 &&
|
2010-11-02 19:59:10 +00:00
|
|
|
E=$(git cat-file commit '$H-$flag' |
|
|
|
|
sed -ne "s/^encoding //p") &&
|
|
|
|
test "z$E" = "z$H" &&
|
|
|
|
git config --unset-all i18n.commitencoding &&
|
|
|
|
git rebase --autosquash -i HEAD^^^ &&
|
|
|
|
git log --oneline >actual &&
|
2012-04-11 11:24:01 +00:00
|
|
|
test_line_count = 3 actual
|
2010-11-02 19:59:10 +00:00
|
|
|
'
|
|
|
|
}
|
|
|
|
|
|
|
|
test_commit_autosquash_flags eucJP fixup
|
|
|
|
|
2011-08-11 07:05:48 +00:00
|
|
|
test_commit_autosquash_flags ISO-2022-JP squash
|
2010-11-02 19:59:12 +00:00
|
|
|
|
2006-12-28 00:41:33 +00:00
|
|
|
test_done
|