t6006: be explicit about the encoding of test strings for msysgit
[git/mingw/4msysgit.git] / t / t6006-rev-list-format.sh
blob07cd8e5f0ba35a6080a09065734bff770143c170
1 #!/bin/sh
3 # Copyright (c) 2009 Jens Lehmann
4 # Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests)
6 test_description='git rev-list --pretty=format test'
8 . ./test-lib.sh
9 . "$TEST_DIRECTORY"/lib-terminal.sh
11 test_tick
12 # String "added" in German
13 # (translated with Google Translate),
14 # encoded in UTF-8, used as a commit log message below.
15 added=$(printf "added (hinzugef\303\274gt) foo")
16 added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso8859-1)
17 # same but "changed"
18 changed=$(printf "changed (ge\303\244ndert) foo")
19 changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t iso8859-1)
21 test_expect_success 'setup' '
22 : >foo &&
23 git add foo &&
24 git config i18n.commitEncoding iso8859-1 &&
25 echo "$added_iso88591" > commit-msg &&
26 git commit -F commit-msg &&
27 head1=$(git rev-parse --verify HEAD) &&
28 head1_short=$(git rev-parse --verify --short $head1) &&
29 tree1=$(git rev-parse --verify HEAD:) &&
30 tree1_short=$(git rev-parse --verify --short $tree1) &&
31 echo "$changed" > foo &&
32 echo "$changed_iso88591" > commit-msg &&
33 git commit -a -F commit-msg &&
34 head2=$(git rev-parse --verify HEAD) &&
35 head2_short=$(git rev-parse --verify --short $head2) &&
36 tree2=$(git rev-parse --verify HEAD:) &&
37 tree2_short=$(git rev-parse --verify --short $tree2)
38 git config --unset i18n.commitEncoding
41 # usage: test_format name format_string [failure] <expected_output
42 test_format () {
43 cat >expect.$1
44 test_expect_${3:-success} "format $1" "
45 git rev-list --pretty=format:'$2' master >output.$1 &&
46 test_cmp expect.$1 output.$1
50 # Feed to --format to provide predictable colored sequences.
51 AUTO_COLOR='%C(auto,red)foo%C(auto,reset)'
52 has_color () {
53 printf '\033[31mfoo\033[m\n' >expect &&
54 test_cmp expect "$1"
57 has_no_color () {
58 echo foo >expect &&
59 test_cmp expect "$1"
62 test_format percent %%h <<EOF
63 commit $head2
65 commit $head1
67 EOF
69 test_format hash %H%n%h <<EOF
70 commit $head2
71 $head2
72 $head2_short
73 commit $head1
74 $head1
75 $head1_short
76 EOF
78 test_format tree %T%n%t <<EOF
79 commit $head2
80 $tree2
81 $tree2_short
82 commit $head1
83 $tree1
84 $tree1_short
85 EOF
87 test_format parents %P%n%p <<EOF
88 commit $head2
89 $head1
90 $head1_short
91 commit $head1
94 EOF
96 # we don't test relative here
97 test_format author %an%n%ae%n%ad%n%aD%n%at <<EOF
98 commit $head2
99 A U Thor
100 author@example.com
101 Thu Apr 7 15:13:13 2005 -0700
102 Thu, 7 Apr 2005 15:13:13 -0700
103 1112911993
104 commit $head1
105 A U Thor
106 author@example.com
107 Thu Apr 7 15:13:13 2005 -0700
108 Thu, 7 Apr 2005 15:13:13 -0700
109 1112911993
112 test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<EOF
113 commit $head2
114 C O Mitter
115 committer@example.com
116 Thu Apr 7 15:13:13 2005 -0700
117 Thu, 7 Apr 2005 15:13:13 -0700
118 1112911993
119 commit $head1
120 C O Mitter
121 committer@example.com
122 Thu Apr 7 15:13:13 2005 -0700
123 Thu, 7 Apr 2005 15:13:13 -0700
124 1112911993
127 test_format encoding %e <<EOF
128 commit $head2
129 iso8859-1
130 commit $head1
131 iso8859-1
134 test_format subject %s <<EOF
135 commit $head2
136 $changed
137 commit $head1
138 $added
141 test_format body %b <<EOF
142 commit $head2
143 commit $head1
146 test_format raw-body %B <<EOF
147 commit $head2
148 $changed
150 commit $head1
151 $added
155 test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<EOF
156 commit $head2
157 \e[31mfoo\e[32mbar\e[34mbaz\e[mxyzzy
158 commit $head1
159 \e[31mfoo\e[32mbar\e[34mbaz\e[mxyzzy
162 test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<EOF
163 commit $head2
164 \e[1;31;43mfoo\e[m
165 commit $head1
166 \e[1;31;43mfoo\e[m
169 test_expect_success '%C(auto) does not enable color by default' '
170 git log --format=$AUTO_COLOR -1 >actual &&
171 has_no_color actual
174 test_expect_success '%C(auto) enables colors for color.diff' '
175 git -c color.diff=always log --format=$AUTO_COLOR -1 >actual &&
176 has_color actual
179 test_expect_success '%C(auto) enables colors for color.ui' '
180 git -c color.ui=always log --format=$AUTO_COLOR -1 >actual &&
181 has_color actual
184 test_expect_success '%C(auto) respects --color' '
185 git log --format=$AUTO_COLOR -1 --color >actual &&
186 has_color actual
189 test_expect_success '%C(auto) respects --no-color' '
190 git -c color.ui=always log --format=$AUTO_COLOR -1 --no-color >actual &&
191 has_no_color actual
194 test_expect_success TTY '%C(auto) respects --color=auto (stdout is tty)' '
196 TERM=vt100 && export TERM &&
197 test_terminal \
198 git log --format=$AUTO_COLOR -1 --color=auto >actual &&
199 has_color actual
203 test_expect_success '%C(auto) respects --color=auto (stdout not tty)' '
205 TERM=vt100 && export TERM &&
206 git log --format=$AUTO_COLOR -1 --color=auto >actual &&
207 has_no_color actual
211 printf "Test printing of complex bodies
213 This commit message is much longer than the others,
214 and it will be encoded in iso8859-1. We should therefore
215 include an iso8859 character: \302\241bueno!
216 " | iconv -f utf-8 -t iso8859-1 > commit-msg
218 test_expect_success 'setup complex body' '
219 git config i18n.commitencoding iso8859-1 &&
220 echo change2 >foo && git commit -a -F commit-msg &&
221 head3=$(git rev-parse --verify HEAD) &&
222 head3_short=$(git rev-parse --short $head3)
225 test_format complex-encoding %e <<EOF
226 commit $head3
227 iso8859-1
228 commit $head2
229 iso8859-1
230 commit $head1
231 iso8859-1
234 test_format complex-subject %s <<EOF
235 commit $head3
236 Test printing of complex bodies
237 commit $head2
238 $changed_iso88591
239 commit $head1
240 $added_iso88591
243 test_expect_success 'prepare expected messages (for test %b)' '
244 cat <<-EOF >expected.utf-8 &&
245 commit $head3
246 This commit message is much longer than the others,
247 and it will be encoded in iso8859-1. We should therefore
248 include an iso8859 character: ¡bueno!
250 commit $head2
251 commit $head1
253 iconv -f utf-8 -t iso8859-1 expected.utf-8 >expected.iso8859-1
256 test_format complex-body %b <expected.iso8859-1
258 # Git uses i18n.commitEncoding if no i18n.logOutputEncoding set
259 # so unset i18n.commitEncoding to test encoding conversion
260 git config --unset i18n.commitEncoding
262 test_format complex-subject-commitencoding-unset %s <<EOF
263 commit $head3
264 Test printing of complex bodies
265 commit $head2
266 $changed
267 commit $head1
268 $added
271 test_format complex-body-commitencoding-unset %b <expected.utf-8
273 test_expect_success '%x00 shows NUL' '
274 echo >expect commit $head3 &&
275 echo >>expect fooQbar &&
276 git rev-list -1 --format=foo%x00bar HEAD >actual.nul &&
277 nul_to_q <actual.nul >actual &&
278 test_cmp expect actual
281 test_expect_success '%ad respects --date=' '
282 echo 2005-04-07 >expect.ad-short &&
283 git log -1 --date=short --pretty=tformat:%ad >output.ad-short master &&
284 test_cmp expect.ad-short output.ad-short
287 test_expect_success 'empty email' '
288 test_tick &&
289 C=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} </dev/null) &&
290 A=$(git show --pretty=format:%an,%ae,%ad%n -s $C) &&
291 test "$A" = "A U Thor,,Thu Apr 7 15:14:13 2005 -0700" || {
292 echo "Eh? $A" >failure
293 false
297 test_expect_success 'del LF before empty (1)' '
298 git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD^^ >actual &&
299 test_line_count = 2 actual
302 test_expect_success 'del LF before empty (2)' '
303 git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD >actual &&
304 test_line_count = 6 actual &&
305 grep "^$" actual
308 test_expect_success 'add LF before non-empty (1)' '
309 git show -s --pretty=format:"%s%+b%nThanks%n" HEAD^^ >actual &&
310 test_line_count = 2 actual
313 test_expect_success 'add LF before non-empty (2)' '
314 git show -s --pretty=format:"%s%+b%nThanks%n" HEAD >actual &&
315 test_line_count = 6 actual &&
316 grep "^$" actual
319 test_expect_success 'add SP before non-empty (1)' '
320 git show -s --pretty=format:"%s% bThanks" HEAD^^ >actual &&
321 test $(wc -w <actual) = 3
324 test_expect_success 'add SP before non-empty (2)' '
325 git show -s --pretty=format:"%s% sThanks" HEAD^^ >actual &&
326 test $(wc -w <actual) = 6
329 test_expect_success '--abbrev' '
330 echo SHORT SHORT SHORT >expect2 &&
331 echo LONG LONG LONG >expect3 &&
332 git log -1 --format="%h %h %h" HEAD >actual1 &&
333 git log -1 --abbrev=5 --format="%h %h %h" HEAD >actual2 &&
334 git log -1 --abbrev=5 --format="%H %H %H" HEAD >actual3 &&
335 sed -e "s/$_x40/LONG/g" -e "s/$_x05/SHORT/g" <actual2 >fuzzy2 &&
336 sed -e "s/$_x40/LONG/g" -e "s/$_x05/SHORT/g" <actual3 >fuzzy3 &&
337 test_cmp expect2 fuzzy2 &&
338 test_cmp expect3 fuzzy3 &&
339 ! test_cmp actual1 actual2
342 test_expect_success '%H is not affected by --abbrev-commit' '
343 git log -1 --format=%H --abbrev-commit --abbrev=20 HEAD >actual &&
344 len=$(wc -c <actual) &&
345 test $len = 41
348 test_expect_success '%h is not affected by --abbrev-commit' '
349 git log -1 --format=%h --abbrev-commit --abbrev=20 HEAD >actual &&
350 len=$(wc -c <actual) &&
351 test $len = 21
354 test_expect_success '"%h %gD: %gs" is same as git-reflog' '
355 git reflog >expect &&
356 git log -g --format="%h %gD: %gs" >actual &&
357 test_cmp expect actual
360 test_expect_success '"%h %gD: %gs" is same as git-reflog (with date)' '
361 git reflog --date=raw >expect &&
362 git log -g --format="%h %gD: %gs" --date=raw >actual &&
363 test_cmp expect actual
366 test_expect_success '"%h %gD: %gs" is same as git-reflog (with --abbrev)' '
367 git reflog --abbrev=13 --date=raw >expect &&
368 git log -g --abbrev=13 --format="%h %gD: %gs" --date=raw >actual &&
369 test_cmp expect actual
372 test_expect_success '%gd shortens ref name' '
373 echo "master@{0}" >expect.gd-short &&
374 git log -g -1 --format=%gd refs/heads/master >actual.gd-short &&
375 test_cmp expect.gd-short actual.gd-short
378 test_expect_success 'reflog identity' '
379 echo "C O Mitter:committer@example.com" >expect &&
380 git log -g -1 --format="%gn:%ge" >actual &&
381 test_cmp expect actual
384 test_expect_success 'oneline with empty message' '
385 git commit -m "dummy" --allow-empty &&
386 git commit -m "dummy" --allow-empty &&
387 git filter-branch --msg-filter "sed -e s/dummy//" HEAD^^.. &&
388 git rev-list --oneline HEAD >test.txt &&
389 test_line_count = 5 test.txt &&
390 git rev-list --oneline --graph HEAD >testg.txt &&
391 test_line_count = 5 testg.txt
394 test_expect_success 'single-character name is parsed correctly' '
395 git commit --author="a <a@example.com>" --allow-empty -m foo &&
396 echo "a <a@example.com>" >expect &&
397 git log -1 --format="%an <%ae>" >actual &&
398 test_cmp expect actual
401 test_done