]>
Commit | Line | Data |
---|---|---|
d2c11a38 JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2006 Junio C Hamano | |
4 | # | |
5 | ||
6 | test_description='commit and log output encodings' | |
7 | ||
8 | . ./test-lib.sh | |
9 | ||
10 | compare_with () { | |
304b5af6 | 11 | git show -s $1 | sed -e '1,/^$/d' -e 's/^ //' >current && |
eb127887 JH |
12 | case "$3" in |
13 | '') | |
14 | test_cmp "$2" current ;; | |
15 | ?*) | |
39d404d1 AR |
16 | iconv -f "$3" -t UTF-8 >current.utf8 <current && |
17 | iconv -f "$3" -t UTF-8 >expect.utf8 <"$2" && | |
eb127887 JH |
18 | test_cmp expect.utf8 current.utf8 |
19 | ;; | |
20 | esac | |
d2c11a38 JH |
21 | } |
22 | ||
23 | test_expect_success setup ' | |
24 | : >F && | |
5be60078 JH |
25 | git add F && |
26 | T=$(git write-tree) && | |
bfdbee98 | 27 | C=$(git commit-tree $T <"$TEST_DIRECTORY"/t3900/1-UTF-8.txt) && |
5be60078 | 28 | git update-ref HEAD $C && |
0cb0e143 | 29 | git tag C0 |
d2c11a38 JH |
30 | ' |
31 | ||
32 | test_expect_success 'no encoding header for base case' ' | |
5be60078 | 33 | E=$(git cat-file commit C0 | sed -ne "s/^encoding //p") && |
d2c11a38 JH |
34 | test z = "z$E" |
35 | ' | |
36 | ||
37576c14 NTND |
37 | test_expect_failure 'UTF-16 refused because of NULs' ' |
38 | echo UTF-16 >F && | |
39 | git commit -a -F "$TEST_DIRECTORY"/t3900/UTF-16.txt | |
40 | ' | |
41 | ||
42 | ||
5ae93dfd | 43 | for H in ISO8859-1 eucJP ISO-2022-JP |
d2c11a38 JH |
44 | do |
45 | test_expect_success "$H setup" ' | |
5be60078 | 46 | git config i18n.commitencoding $H && |
0cb0e143 | 47 | git checkout -b $H C0 && |
d2c11a38 | 48 | echo $H >F && |
9b8ae93a | 49 | git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt |
d2c11a38 JH |
50 | ' |
51 | done | |
52 | ||
5ae93dfd | 53 | for H in ISO8859-1 eucJP ISO-2022-JP |
d2c11a38 JH |
54 | do |
55 | test_expect_success "check encoding header for $H" ' | |
5be60078 | 56 | E=$(git cat-file commit '$H' | sed -ne "s/^encoding //p") && |
d2c11a38 JH |
57 | test "z$E" = "z'$H'" |
58 | ' | |
59 | done | |
60 | ||
e0d10e1c | 61 | test_expect_success 'config to remove customization' ' |
5be60078 JH |
62 | git config --unset-all i18n.commitencoding && |
63 | if Z=$(git config --get-all i18n.commitencoding) | |
d2c11a38 JH |
64 | then |
65 | echo Oops, should have failed. | |
66 | false | |
67 | else | |
68 | test z = "z$Z" | |
69 | fi && | |
5ae93dfd | 70 | git config i18n.commitencoding UTF-8 |
d2c11a38 JH |
71 | ' |
72 | ||
5ae93dfd BC |
73 | test_expect_success 'ISO8859-1 should be shown in UTF-8 now' ' |
74 | compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt | |
d2c11a38 JH |
75 | ' |
76 | ||
5ae93dfd | 77 | for H in eucJP ISO-2022-JP |
d2c11a38 JH |
78 | do |
79 | test_expect_success "$H should be shown in UTF-8 now" ' | |
bfdbee98 | 80 | compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt |
d2c11a38 JH |
81 | ' |
82 | done | |
83 | ||
e0d10e1c | 84 | test_expect_success 'config to add customization' ' |
5be60078 JH |
85 | git config --unset-all i18n.commitencoding && |
86 | if Z=$(git config --get-all i18n.commitencoding) | |
d2c11a38 JH |
87 | then |
88 | echo Oops, should have failed. | |
89 | false | |
90 | else | |
91 | test z = "z$Z" | |
92 | fi | |
93 | ' | |
94 | ||
5ae93dfd | 95 | for H in ISO8859-1 eucJP ISO-2022-JP |
d2c11a38 JH |
96 | do |
97 | test_expect_success "$H should be shown in itself now" ' | |
5be60078 | 98 | git config i18n.commitencoding '$H' && |
bfdbee98 | 99 | compare_with '$H' "$TEST_DIRECTORY"/t3900/'$H'.txt |
d2c11a38 JH |
100 | ' |
101 | done | |
102 | ||
e0d10e1c | 103 | test_expect_success 'config to tweak customization' ' |
5ae93dfd | 104 | git config i18n.logoutputencoding UTF-8 |
d2c11a38 JH |
105 | ' |
106 | ||
5ae93dfd BC |
107 | test_expect_success 'ISO8859-1 should be shown in UTF-8 now' ' |
108 | compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt | |
d2c11a38 JH |
109 | ' |
110 | ||
5ae93dfd | 111 | for H in eucJP ISO-2022-JP |
d2c11a38 JH |
112 | do |
113 | test_expect_success "$H should be shown in UTF-8 now" ' | |
bfdbee98 | 114 | compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt |
d2c11a38 JH |
115 | ' |
116 | done | |
117 | ||
5ae93dfd | 118 | for J in eucJP ISO-2022-JP |
7255ff04 | 119 | do |
eb127887 JH |
120 | if test "$J" = ISO-2022-JP |
121 | then | |
122 | ICONV=$J | |
123 | else | |
124 | ICONV= | |
125 | fi | |
5be60078 | 126 | git config i18n.logoutputencoding $J |
5ae93dfd | 127 | for H in eucJP ISO-2022-JP |
7255ff04 JH |
128 | do |
129 | test_expect_success "$H should be shown in $J now" ' | |
eb127887 | 130 | compare_with '$H' "$TEST_DIRECTORY"/t3900/'$J'.txt $ICONV |
7255ff04 JH |
131 | ' |
132 | done | |
133 | done | |
134 | ||
5ae93dfd | 135 | for H in ISO8859-1 eucJP ISO-2022-JP |
00079283 JH |
136 | do |
137 | test_expect_success "No conversion with $H" ' | |
bfdbee98 | 138 | compare_with "--encoding=none '$H'" "$TEST_DIRECTORY"/t3900/'$H'.txt |
00079283 JH |
139 | ' |
140 | done | |
141 | ||
b1a6c0a9 PN |
142 | test_commit_autosquash_flags () { |
143 | H=$1 | |
144 | flag=$2 | |
145 | test_expect_success "commit --$flag with $H encoding" ' | |
146 | git config i18n.commitencoding $H && | |
147 | git checkout -b $H-$flag C0 && | |
148 | echo $H >>F && | |
149 | git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt && | |
150 | test_tick && | |
151 | echo intermediate stuff >>G && | |
152 | git add G && | |
153 | git commit -a -m "intermediate commit" && | |
154 | test_tick && | |
155 | echo $H $flag >>F && | |
23ce5c39 | 156 | git commit -a --$flag HEAD~1 && |
b1a6c0a9 PN |
157 | E=$(git cat-file commit '$H-$flag' | |
158 | sed -ne "s/^encoding //p") && | |
159 | test "z$E" = "z$H" && | |
160 | git config --unset-all i18n.commitencoding && | |
161 | git rebase --autosquash -i HEAD^^^ && | |
162 | git log --oneline >actual && | |
163 | test 3 = $(wc -l <actual) | |
164 | ' | |
165 | } | |
166 | ||
167 | test_commit_autosquash_flags eucJP fixup | |
168 | ||
23ce5c39 | 169 | test_commit_autosquash_flags ISO-2022-JP squash |
7951bd30 | 170 | |
d2c11a38 | 171 | test_done |