t3900-i18n-commit.sh 2.6 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
	test_cmp current "$2"
13 14 15 16
}

test_expect_success setup '
	: >F &&
17 18
	git add F &&
	T=$(git write-tree) &&
19
	C=$(git commit-tree $T <"$TEST_DIRECTORY"/t3900/1-UTF-8.txt) &&
20
	git update-ref HEAD $C &&
21 22 23 24
	git-tag C0
'

test_expect_success 'no encoding header for base case' '
25
	E=$(git cat-file commit C0 | sed -ne "s/^encoding //p") &&
26 27 28
	test z = "z$E"
'

J
Junio C Hamano 已提交
29
for H in ISO-8859-1 EUCJP ISO-2022-JP
30 31
do
	test_expect_success "$H setup" '
32
		git config i18n.commitencoding $H &&
33 34
		git-checkout -b $H C0 &&
		echo $H >F &&
35
		git-commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt
36 37 38
	'
done

J
Junio C Hamano 已提交
39
for H in ISO-8859-1 EUCJP ISO-2022-JP
40 41
do
	test_expect_success "check encoding header for $H" '
42
		E=$(git cat-file commit '$H' | sed -ne "s/^encoding //p") &&
43 44 45 46
		test "z$E" = "z'$H'"
	'
done

47
test_expect_success 'config to remove customization' '
48 49
	git config --unset-all i18n.commitencoding &&
	if Z=$(git config --get-all i18n.commitencoding)
50 51 52 53 54 55
	then
		echo Oops, should have failed.
		false
	else
		test z = "z$Z"
	fi &&
56
	git config i18n.commitencoding utf-8
57 58 59
'

test_expect_success 'ISO-8859-1 should be shown in UTF-8 now' '
60
	compare_with ISO-8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
61 62
'

J
Junio C Hamano 已提交
63
for H in EUCJP ISO-2022-JP
64 65
do
	test_expect_success "$H should be shown in UTF-8 now" '
66
		compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
67 68 69
	'
done

70
test_expect_success 'config to add customization' '
71 72
	git config --unset-all i18n.commitencoding &&
	if Z=$(git config --get-all i18n.commitencoding)
73 74 75 76 77 78 79 80
	then
		echo Oops, should have failed.
		false
	else
		test z = "z$Z"
	fi
'

J
Junio C Hamano 已提交
81
for H in ISO-8859-1 EUCJP ISO-2022-JP
82 83
do
	test_expect_success "$H should be shown in itself now" '
84
		git config i18n.commitencoding '$H' &&
85
		compare_with '$H' "$TEST_DIRECTORY"/t3900/'$H'.txt
86 87 88
	'
done

89
test_expect_success 'config to tweak customization' '
90
	git config i18n.logoutputencoding utf-8
91 92 93
'

test_expect_success 'ISO-8859-1 should be shown in UTF-8 now' '
94
	compare_with ISO-8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
95 96
'

J
Junio C Hamano 已提交
97
for H in EUCJP ISO-2022-JP
98 99
do
	test_expect_success "$H should be shown in UTF-8 now" '
100
		compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
101 102 103
	'
done

104 105
for J in EUCJP ISO-2022-JP
do
106
	git config i18n.logoutputencoding $J
107 108 109
	for H in EUCJP ISO-2022-JP
	do
		test_expect_success "$H should be shown in $J now" '
110
			compare_with '$H' "$TEST_DIRECTORY"/t3900/'$J'.txt
111 112 113 114
		'
	done
done

J
Junio C Hamano 已提交
115 116 117
for H in ISO-8859-1 EUCJP ISO-2022-JP
do
	test_expect_success "No conversion with $H" '
118
		compare_with "--encoding=none '$H'" "$TEST_DIRECTORY"/t3900/'$H'.txt
J
Junio C Hamano 已提交
119 120 121
	'
done

122
test_done