blob: 1f62c151b0aa63b4c85f9bc76f501d53967b0260 [file] [log] [blame]
Junio C Hamanod2c11a32006-12-27 16:41:33 -08001#!/bin/sh
2#
3# Copyright (c) 2006 Junio C Hamano
4#
5
6test_description='commit and log output encodings'
7
8. ./test-lib.sh
9
10compare_with () {
Linus Torvalds304b5af2007-10-09 09:35:22 -070011 git show -s $1 | sed -e '1,/^$/d' -e 's/^ //' >current &&
Junio C Hamanoeb127882009-05-12 02:01:51 -070012 case "$3" in
13 '')
14 test_cmp "$2" current ;;
15 ?*)
Alex Riesen39d404d2009-05-14 14:55:54 +020016 iconv -f "$3" -t UTF-8 >current.utf8 <current &&
17 iconv -f "$3" -t UTF-8 >expect.utf8 <"$2" &&
Junio C Hamanoeb127882009-05-12 02:01:51 -070018 test_cmp expect.utf8 current.utf8
19 ;;
20 esac
Junio C Hamanod2c11a32006-12-27 16:41:33 -080021}
22
23test_expect_success setup '
24 : >F &&
Junio C Hamano5be60072007-07-02 22:52:14 -070025 git add F &&
26 T=$(git write-tree) &&
Junio C Hamanobfdbee92008-08-08 02:26:28 -070027 C=$(git commit-tree $T <"$TEST_DIRECTORY"/t3900/1-UTF-8.txt) &&
Junio C Hamano5be60072007-07-02 22:52:14 -070028 git update-ref HEAD $C &&
Nanako Shiraishi0cb0e142008-09-03 17:59:27 +090029 git tag C0
Junio C Hamanod2c11a32006-12-27 16:41:33 -080030'
31
32test_expect_success 'no encoding header for base case' '
Junio C Hamano5be60072007-07-02 22:52:14 -070033 E=$(git cat-file commit C0 | sed -ne "s/^encoding //p") &&
Junio C Hamanod2c11a32006-12-27 16:41:33 -080034 test z = "z$E"
35'
36
Brandon Casey5ae93df2009-05-18 18:44:38 -050037for H in ISO8859-1 eucJP ISO-2022-JP
Junio C Hamanod2c11a32006-12-27 16:41:33 -080038do
39 test_expect_success "$H setup" '
Junio C Hamano5be60072007-07-02 22:52:14 -070040 git config i18n.commitencoding $H &&
Nanako Shiraishi0cb0e142008-09-03 17:59:27 +090041 git checkout -b $H C0 &&
Junio C Hamanod2c11a32006-12-27 16:41:33 -080042 echo $H >F &&
Junio C Hamano9b8ae932008-09-03 16:08:23 -070043 git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt
Junio C Hamanod2c11a32006-12-27 16:41:33 -080044 '
45done
46
Brandon Casey5ae93df2009-05-18 18:44:38 -050047for H in ISO8859-1 eucJP ISO-2022-JP
Junio C Hamanod2c11a32006-12-27 16:41:33 -080048do
49 test_expect_success "check encoding header for $H" '
Junio C Hamano5be60072007-07-02 22:52:14 -070050 E=$(git cat-file commit '$H' | sed -ne "s/^encoding //p") &&
Junio C Hamanod2c11a32006-12-27 16:41:33 -080051 test "z$E" = "z'$H'"
52 '
53done
54
Tom Princee0d10e12007-01-28 16:16:53 -080055test_expect_success 'config to remove customization' '
Junio C Hamano5be60072007-07-02 22:52:14 -070056 git config --unset-all i18n.commitencoding &&
57 if Z=$(git config --get-all i18n.commitencoding)
Junio C Hamanod2c11a32006-12-27 16:41:33 -080058 then
59 echo Oops, should have failed.
60 false
61 else
62 test z = "z$Z"
63 fi &&
Brandon Casey5ae93df2009-05-18 18:44:38 -050064 git config i18n.commitencoding UTF-8
Junio C Hamanod2c11a32006-12-27 16:41:33 -080065'
66
Brandon Casey5ae93df2009-05-18 18:44:38 -050067test_expect_success 'ISO8859-1 should be shown in UTF-8 now' '
68 compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
Junio C Hamanod2c11a32006-12-27 16:41:33 -080069'
70
Brandon Casey5ae93df2009-05-18 18:44:38 -050071for H in eucJP ISO-2022-JP
Junio C Hamanod2c11a32006-12-27 16:41:33 -080072do
73 test_expect_success "$H should be shown in UTF-8 now" '
Junio C Hamanobfdbee92008-08-08 02:26:28 -070074 compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
Junio C Hamanod2c11a32006-12-27 16:41:33 -080075 '
76done
77
Tom Princee0d10e12007-01-28 16:16:53 -080078test_expect_success 'config to add customization' '
Junio C Hamano5be60072007-07-02 22:52:14 -070079 git config --unset-all i18n.commitencoding &&
80 if Z=$(git config --get-all i18n.commitencoding)
Junio C Hamanod2c11a32006-12-27 16:41:33 -080081 then
82 echo Oops, should have failed.
83 false
84 else
85 test z = "z$Z"
86 fi
87'
88
Brandon Casey5ae93df2009-05-18 18:44:38 -050089for H in ISO8859-1 eucJP ISO-2022-JP
Junio C Hamanod2c11a32006-12-27 16:41:33 -080090do
91 test_expect_success "$H should be shown in itself now" '
Junio C Hamano5be60072007-07-02 22:52:14 -070092 git config i18n.commitencoding '$H' &&
Junio C Hamanobfdbee92008-08-08 02:26:28 -070093 compare_with '$H' "$TEST_DIRECTORY"/t3900/'$H'.txt
Junio C Hamanod2c11a32006-12-27 16:41:33 -080094 '
95done
96
Tom Princee0d10e12007-01-28 16:16:53 -080097test_expect_success 'config to tweak customization' '
Brandon Casey5ae93df2009-05-18 18:44:38 -050098 git config i18n.logoutputencoding UTF-8
Junio C Hamanod2c11a32006-12-27 16:41:33 -080099'
100
Brandon Casey5ae93df2009-05-18 18:44:38 -0500101test_expect_success 'ISO8859-1 should be shown in UTF-8 now' '
102 compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
Junio C Hamanod2c11a32006-12-27 16:41:33 -0800103'
104
Brandon Casey5ae93df2009-05-18 18:44:38 -0500105for H in eucJP ISO-2022-JP
Junio C Hamanod2c11a32006-12-27 16:41:33 -0800106do
107 test_expect_success "$H should be shown in UTF-8 now" '
Junio C Hamanobfdbee92008-08-08 02:26:28 -0700108 compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
Junio C Hamanod2c11a32006-12-27 16:41:33 -0800109 '
110done
111
Brandon Casey5ae93df2009-05-18 18:44:38 -0500112for J in eucJP ISO-2022-JP
Junio C Hamano7255ff02006-12-28 17:36:35 -0800113do
Junio C Hamanoeb127882009-05-12 02:01:51 -0700114 if test "$J" = ISO-2022-JP
115 then
116 ICONV=$J
117 else
118 ICONV=
119 fi
Junio C Hamano5be60072007-07-02 22:52:14 -0700120 git config i18n.logoutputencoding $J
Brandon Casey5ae93df2009-05-18 18:44:38 -0500121 for H in eucJP ISO-2022-JP
Junio C Hamano7255ff02006-12-28 17:36:35 -0800122 do
123 test_expect_success "$H should be shown in $J now" '
Junio C Hamanoeb127882009-05-12 02:01:51 -0700124 compare_with '$H' "$TEST_DIRECTORY"/t3900/'$J'.txt $ICONV
Junio C Hamano7255ff02006-12-28 17:36:35 -0800125 '
126 done
127done
128
Brandon Casey5ae93df2009-05-18 18:44:38 -0500129for H in ISO8859-1 eucJP ISO-2022-JP
Junio C Hamano00079282006-12-30 02:35:14 -0800130do
131 test_expect_success "No conversion with $H" '
Junio C Hamanobfdbee92008-08-08 02:26:28 -0700132 compare_with "--encoding=none '$H'" "$TEST_DIRECTORY"/t3900/'$H'.txt
Junio C Hamano00079282006-12-30 02:35:14 -0800133 '
134done
135
Pat Notzb1a6c0a2010-11-02 13:59:10 -0600136test_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 &&
Johannes Sixt23ce5c32011-08-11 09:05:48 +0200150 git commit -a --$flag HEAD~1 &&
Pat Notzb1a6c0a2010-11-02 13:59:10 -0600151 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)
158 '
159}
160
161test_commit_autosquash_flags eucJP fixup
162
Johannes Sixt23ce5c32011-08-11 09:05:48 +0200163test_commit_autosquash_flags ISO-2022-JP squash
Pat Notz7951bd32010-11-02 13:59:12 -0600164
Junio C Hamanod2c11a32006-12-27 16:41:33 -0800165test_done