t3900-i18n-commit.sh 2.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
#!/bin/sh
#
# Copyright (c) 2006 Junio C Hamano
#

test_description='commit and log output encodings'

. ./test-lib.sh

compare_with () {
11
	git show -s $1 | sed -e '1,/^$/d' -e 's/^    //' >current &&
12 13 14 15 16 17 18 19 20
	case "$3" in
	'')
		test_cmp "$2" current ;;
	?*)
		iconv -f "$3" -t utf8 >current.utf8 <current &&
		iconv -f "$3" -t utf8 >expect.utf8 <"$2" &&
		test_cmp expect.utf8 current.utf8
		;;
	esac
21 22 23 24
}

test_expect_success setup '
	: >F &&
25 26
	git add F &&
	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 35 36
	test z = "z$E"
'

J
Junio C Hamano 已提交
37
for H in ISO-8859-1 EUCJP ISO-2022-JP
38 39
do
	test_expect_success "$H setup" '
40
		git config i18n.commitencoding $H &&
41
		git checkout -b $H C0 &&
42
		echo $H >F &&
J
Junio C Hamano 已提交
43
		git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt
44 45 46
	'
done

J
Junio C Hamano 已提交
47
for H in ISO-8859-1 EUCJP ISO-2022-JP
48 49
do
	test_expect_success "check encoding header for $H" '
50
		E=$(git cat-file commit '$H' | sed -ne "s/^encoding //p") &&
51 52 53 54
		test "z$E" = "z'$H'"
	'
done

55
test_expect_success 'config to remove customization' '
56 57
	git config --unset-all i18n.commitencoding &&
	if Z=$(git config --get-all i18n.commitencoding)
58 59 60 61 62 63
	then
		echo Oops, should have failed.
		false
	else
		test z = "z$Z"
	fi &&
64
	git config i18n.commitencoding utf-8
65 66 67
'

test_expect_success 'ISO-8859-1 should be shown in UTF-8 now' '
68
	compare_with ISO-8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
69 70
'

J
Junio C Hamano 已提交
71
for H in EUCJP ISO-2022-JP
72 73
do
	test_expect_success "$H should be shown in UTF-8 now" '
74
		compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
75 76 77
	'
done

78
test_expect_success 'config to add customization' '
79 80
	git config --unset-all i18n.commitencoding &&
	if Z=$(git config --get-all i18n.commitencoding)
81 82 83 84 85 86 87 88
	then
		echo Oops, should have failed.
		false
	else
		test z = "z$Z"
	fi
'

J
Junio C Hamano 已提交
89
for H in ISO-8859-1 EUCJP ISO-2022-JP
90 91
do
	test_expect_success "$H should be shown in itself now" '
92
		git config i18n.commitencoding '$H' &&
93
		compare_with '$H' "$TEST_DIRECTORY"/t3900/'$H'.txt
94 95 96
	'
done

97
test_expect_success 'config to tweak customization' '
98
	git config i18n.logoutputencoding utf-8
99 100 101
'

test_expect_success 'ISO-8859-1 should be shown in UTF-8 now' '
102
	compare_with ISO-8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
103 104
'

J
Junio C Hamano 已提交
105
for H in EUCJP ISO-2022-JP
106 107
do
	test_expect_success "$H should be shown in UTF-8 now" '
108
		compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
109 110 111
	'
done

112 113
for J in EUCJP ISO-2022-JP
do
114 115 116 117 118 119
	if test "$J" = ISO-2022-JP
	then
		ICONV=$J
	else
		ICONV=
	fi
120
	git config i18n.logoutputencoding $J
121 122 123
	for H in EUCJP ISO-2022-JP
	do
		test_expect_success "$H should be shown in $J now" '
124
			compare_with '$H' "$TEST_DIRECTORY"/t3900/'$J'.txt $ICONV
125 126 127 128
		'
	done
done

J
Junio C Hamano 已提交
129 130 131
for H in ISO-8859-1 EUCJP ISO-2022-JP
do
	test_expect_success "No conversion with $H" '
132
		compare_with "--encoding=none '$H'" "$TEST_DIRECTORY"/t3900/'$H'.txt
J
Junio C Hamano 已提交
133 134 135
	'
done

136
test_done