receive-pack: move more work into write_head_info()
[git/jrn.git] / t / t3900-i18n-commit.sh
blob1f62c151b0aa63b4c85f9bc76f501d53967b0260
1 #!/bin/sh
3 # Copyright (c) 2006 Junio C Hamano
6 test_description='commit and log output encodings'
8 . ./test-lib.sh
10 compare_with () {
11 git show -s $1 | sed -e '1,/^$/d' -e 's/^ //' >current &&
12 case "$3" in
13 '')
14 test_cmp "$2" current ;;
15 ?*)
16 iconv -f "$3" -t UTF-8 >current.utf8 <current &&
17 iconv -f "$3" -t UTF-8 >expect.utf8 <"$2" &&
18 test_cmp expect.utf8 current.utf8
20 esac
23 test_expect_success setup '
24 : >F &&
25 git add F &&
26 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
32 test_expect_success 'no encoding header for base case' '
33 E=$(git cat-file commit C0 | sed -ne "s/^encoding //p") &&
34 test z = "z$E"
37 for H in ISO8859-1 eucJP ISO-2022-JP
39 test_expect_success "$H setup" '
40 git config i18n.commitencoding $H &&
41 git checkout -b $H C0 &&
42 echo $H >F &&
43 git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt
45 done
47 for H in ISO8859-1 eucJP ISO-2022-JP
49 test_expect_success "check encoding header for $H" '
50 E=$(git cat-file commit '$H' | sed -ne "s/^encoding //p") &&
51 test "z$E" = "z'$H'"
53 done
55 test_expect_success 'config to remove customization' '
56 git config --unset-all i18n.commitencoding &&
57 if Z=$(git config --get-all i18n.commitencoding)
58 then
59 echo Oops, should have failed.
60 false
61 else
62 test z = "z$Z"
63 fi &&
64 git config i18n.commitencoding UTF-8
67 test_expect_success 'ISO8859-1 should be shown in UTF-8 now' '
68 compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
71 for H in eucJP ISO-2022-JP
73 test_expect_success "$H should be shown in UTF-8 now" '
74 compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
76 done
78 test_expect_success 'config to add customization' '
79 git config --unset-all i18n.commitencoding &&
80 if Z=$(git config --get-all i18n.commitencoding)
81 then
82 echo Oops, should have failed.
83 false
84 else
85 test z = "z$Z"
89 for H in ISO8859-1 eucJP ISO-2022-JP
91 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
95 done
97 test_expect_success 'config to tweak customization' '
98 git config i18n.logoutputencoding UTF-8
101 test_expect_success 'ISO8859-1 should be shown in UTF-8 now' '
102 compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
105 for H in eucJP ISO-2022-JP
107 test_expect_success "$H should be shown in UTF-8 now" '
108 compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
110 done
112 for J in eucJP ISO-2022-JP
114 if test "$J" = ISO-2022-JP
115 then
116 ICONV=$J
117 else
118 ICONV=
120 git config i18n.logoutputencoding $J
121 for H in eucJP ISO-2022-JP
123 test_expect_success "$H should be shown in $J now" '
124 compare_with '$H' "$TEST_DIRECTORY"/t3900/'$J'.txt $ICONV
126 done
127 done
129 for H in ISO8859-1 eucJP ISO-2022-JP
131 test_expect_success "No conversion with $H" '
132 compare_with "--encoding=none '$H'" "$TEST_DIRECTORY"/t3900/'$H'.txt
134 done
136 test_commit_autosquash_flags () {
137 H=$1
138 flag=$2
139 test_expect_success "commit --$flag with $H encoding" '
140 git config i18n.commitencoding $H &&
141 git checkout -b $H-$flag C0 &&
142 echo $H >>F &&
143 git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt &&
144 test_tick &&
145 echo intermediate stuff >>G &&
146 git add G &&
147 git commit -a -m "intermediate commit" &&
148 test_tick &&
149 echo $H $flag >>F &&
150 git commit -a --$flag HEAD~1 &&
151 E=$(git cat-file commit '$H-$flag' |
152 sed -ne "s/^encoding //p") &&
153 test "z$E" = "z$H" &&
154 git config --unset-all i18n.commitencoding &&
155 git rebase --autosquash -i HEAD^^^ &&
156 git log --oneline >actual &&
157 test 3 = $(wc -l <actual)
161 test_commit_autosquash_flags eucJP fixup
163 test_commit_autosquash_flags ISO-2022-JP squash
165 test_done