t3900-i18n-commit.sh 2.5 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/^    //' -e '$d' >current &&
12
	git diff current "$2"
13 14 15 16
}

test_expect_success setup '
	: >F &&
17 18 19 20
	git add F &&
	T=$(git write-tree) &&
	C=$(git commit-tree $T <../t3900/1-UTF-8.txt) &&
	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 35 36 37 38
		git-checkout -b $H C0 &&
		echo $H >F &&
		git-commit -a -F ../t3900/$H.txt
	'
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 60 61 62
'

test_expect_success 'ISO-8859-1 should be shown in UTF-8 now' '
	compare_with ISO-8859-1 ../t3900/1-UTF-8.txt
'

J
Junio C Hamano 已提交
63
for H in EUCJP ISO-2022-JP
64 65 66 67 68 69
do
	test_expect_success "$H should be shown in UTF-8 now" '
		compare_with '$H' ../t3900/2-UTF-8.txt
	'
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 86 87 88
		compare_with '$H' ../t3900/'$H'.txt
	'
done

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

test_expect_success 'ISO-8859-1 should be shown in UTF-8 now' '
	compare_with ISO-8859-1 ../t3900/1-UTF-8.txt
'

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

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

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

122
test_done