]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4205-log-pretty-formats.sh
Merge branch 'sb/pack-protocol-doc-nak' into maint
[thirdparty/git.git] / t / t4205-log-pretty-formats.sh
CommitLineData
8028184e
WP
1#!/bin/sh
2#
3# Copyright (c) 2010, Will Palmer
de6029a2 4# Copyright (c) 2011, Alexey Shumkin (+ non-UTF-8 commit encoding tests)
8028184e
WP
5#
6
7test_description='Test pretty formats'
8. ./test-lib.sh
9
ee3efaf6
AS
10# Tested non-UTF-8 encoding
11test_encoding="ISO8859-1"
12
37eb772e
AS
13sample_utf8_part=$(printf "f\303\244ng")
14
de6029a2 15commit_msg () {
17cc2ef1
AS
16 # String "initial. initial" partly in German
17 # (translated with Google Translate),
de6029a2 18 # encoded in UTF-8, used as a commit log message below.
37eb772e 19 msg="initial. an${sample_utf8_part}lich\n"
de6029a2
AS
20 if test -n "$1"
21 then
37eb772e
AS
22 printf "$msg" | iconv -f utf-8 -t "$1"
23 else
24 printf "$msg"
de6029a2 25 fi
de6029a2
AS
26}
27
8028184e
WP
28test_expect_success 'set up basic repos' '
29 >foo &&
30 >bar &&
31 git add foo &&
32 test_tick &&
ee3efaf6 33 git config i18n.commitEncoding $test_encoding &&
e6ce2be2 34 commit_msg $test_encoding | git commit -F - &&
8028184e
WP
35 git add bar &&
36 test_tick &&
de6029a2
AS
37 git commit -m "add bar" &&
38 git config --unset i18n.commitEncoding
8028184e
WP
39'
40
41test_expect_success 'alias builtin format' '
42 git log --pretty=oneline >expected &&
43 git config pretty.test-alias oneline &&
44 git log --pretty=test-alias >actual &&
45 test_cmp expected actual
46'
47
48test_expect_success 'alias masking builtin format' '
49 git log --pretty=oneline >expected &&
50 git config pretty.oneline "%H" &&
51 git log --pretty=oneline >actual &&
52 test_cmp expected actual
53'
54
55test_expect_success 'alias user-defined format' '
56 git log --pretty="format:%h" >expected &&
57 git config pretty.test-alias "format:%h" &&
58 git log --pretty=test-alias >actual &&
59 test_cmp expected actual
60'
61
ee3efaf6
AS
62test_expect_success 'alias user-defined tformat with %s (ISO8859-1 encoding)' '
63 git config i18n.logOutputEncoding $test_encoding &&
de6029a2
AS
64 git log --oneline >expected-s &&
65 git log --pretty="tformat:%h %s" >actual-s &&
66 git config --unset i18n.logOutputEncoding &&
67 test_cmp expected-s actual-s
68'
69
ecaee805 70test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' '
de6029a2
AS
71 git log --oneline >expected-s &&
72 git log --pretty="tformat:%h %s" >actual-s &&
73 test_cmp expected-s actual-s
74'
75
8028184e
WP
76test_expect_success 'alias user-defined tformat' '
77 git log --pretty="tformat:%h" >expected &&
78 git config pretty.test-alias "tformat:%h" &&
79 git log --pretty=test-alias >actual &&
80 test_cmp expected actual
81'
82
7be8b3ba 83test_expect_success 'alias non-existent format' '
8028184e
WP
84 git config pretty.test-alias format-that-will-never-exist &&
85 test_must_fail git log --pretty=test-alias
86'
87
88test_expect_success 'alias of an alias' '
89 git log --pretty="tformat:%h" >expected &&
90 git config pretty.test-foo "tformat:%h" &&
91 git config pretty.test-bar test-foo &&
92 git log --pretty=test-bar >actual && test_cmp expected actual
93'
94
95test_expect_success 'alias masking an alias' '
96 git log --pretty=format:"Two %H" >expected &&
97 git config pretty.duplicate "format:One %H" &&
98 git config --add pretty.duplicate "format:Two %H" &&
99 git log --pretty=duplicate >actual &&
100 test_cmp expected actual
101'
102
103test_expect_success 'alias loop' '
104 git config pretty.test-foo test-bar &&
105 git config pretty.test-bar test-foo &&
106 test_must_fail git log --pretty=test-foo
107'
108
ecaee805 109test_expect_success 'NUL separation' '
de6029a2 110 printf "add bar\0$(commit_msg)" >expected &&
3e065308
JK
111 git log -z --pretty="format:%s" >actual &&
112 test_cmp expected actual
113'
114
ecaee805 115test_expect_success 'NUL termination' '
de6029a2 116 printf "add bar\0$(commit_msg)\0" >expected &&
3e065308
JK
117 git log -z --pretty="tformat:%s" >actual &&
118 test_cmp expected actual
119'
120
ecaee805 121test_expect_success 'NUL separation with --stat' '
fafd3829 122 stat0_part=$(git diff --stat HEAD^ HEAD) &&
74faaa16 123 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
de6029a2 124 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected &&
fafd3829 125 git log -z --stat --pretty="format:%s" >actual &&
b354f11b 126 test_i18ncmp expected actual
fafd3829
JH
127'
128
129test_expect_failure 'NUL termination with --stat' '
130 stat0_part=$(git diff --stat HEAD^ HEAD) &&
74faaa16 131 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
de6029a2 132 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n0" >expected &&
fafd3829 133 git log -z --stat --pretty="tformat:%s" >actual &&
b354f11b 134 test_i18ncmp expected actual
fafd3829
JH
135'
136
a5752342
NTND
137test_expect_success 'setup more commits' '
138 test_commit "message one" one one message-one &&
a742f2a0
AS
139 test_commit "message two" two two message-two &&
140 head1=$(git rev-parse --verify --short HEAD~0) &&
141 head2=$(git rev-parse --verify --short HEAD~1) &&
142 head3=$(git rev-parse --verify --short HEAD~2) &&
143 head4=$(git rev-parse --verify --short HEAD~3)
a5752342
NTND
144'
145
f3445f78 146test_expect_success 'left alignment formatting' '
c82134a9 147 git log --pretty="tformat:%<(40)%s" >actual &&
f3445f78 148 qz_to_tab_space <<EOF >expected &&
a5752342
NTND
149message two Z
150message one Z
151add bar Z
de6029a2 152$(commit_msg) Z
a5752342
NTND
153EOF
154 test_cmp expected actual
f3445f78 155'
a5752342 156
d928d810
AS
157test_expect_success 'left alignment formatting. i18n.logOutputEncoding' '
158 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(40)%s" >actual &&
159 qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
160message two Z
161message one Z
162add bar Z
163$(commit_msg) Z
164EOF
165 test_cmp expected actual
166'
167
f3445f78 168test_expect_success 'left alignment formatting at the nth column' '
c82134a9 169 git log --pretty="tformat:%h %<|(40)%s" >actual &&
f3445f78 170 qz_to_tab_space <<EOF >expected &&
a742f2a0
AS
171$head1 message two Z
172$head2 message one Z
173$head3 add bar Z
de6029a2 174$head4 $(commit_msg) Z
a5752342
NTND
175EOF
176 test_cmp expected actual
f3445f78 177'
a5752342 178
066790d7
NTND
179test_expect_success 'left alignment formatting at the nth column' '
180 COLUMNS=50 git log --pretty="tformat:%h %<|(-10)%s" >actual &&
181 qz_to_tab_space <<EOF >expected &&
182$head1 message two Z
183$head2 message one Z
184$head3 add bar Z
185$head4 $(commit_msg) Z
186EOF
187 test_cmp expected actual
188'
189
d928d810
AS
190test_expect_success 'left alignment formatting at the nth column. i18n.logOutputEncoding' '
191 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %<|(40)%s" >actual &&
192 qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
193$head1 message two Z
194$head2 message one Z
195$head3 add bar Z
196$head4 $(commit_msg) Z
197EOF
198 test_cmp expected actual
199'
200
f3445f78 201test_expect_success 'left alignment formatting with no padding' '
c82134a9 202 git log --pretty="tformat:%<(1)%s" >actual &&
f3445f78 203 cat <<EOF >expected &&
a5752342
NTND
204message two
205message one
206add bar
de6029a2 207$(commit_msg)
a5752342
NTND
208EOF
209 test_cmp expected actual
f3445f78 210'
a5752342 211
d928d810
AS
212test_expect_success 'left alignment formatting with no padding. i18n.logOutputEncoding' '
213 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(1)%s" >actual &&
214 cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
215message two
216message one
217add bar
218$(commit_msg)
219EOF
220 test_cmp expected actual
221'
222
f3445f78 223test_expect_success 'left alignment formatting with trunc' '
c82134a9 224 git log --pretty="tformat:%<(10,trunc)%s" >actual &&
f3445f78 225 qz_to_tab_space <<EOF >expected &&
a7f01c6b
NTND
226message ..
227message ..
228add bar Z
37eb772e 229initial...
a7f01c6b
NTND
230EOF
231 test_cmp expected actual
f3445f78 232'
a7f01c6b 233
7d509878 234test_expect_success 'left alignment formatting with trunc. i18n.logOutputEncoding' '
d928d810
AS
235 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s" >actual &&
236 qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
237message ..
238message ..
239add bar Z
240initial...
241EOF
242 test_cmp expected actual
243'
244
f3445f78 245test_expect_success 'left alignment formatting with ltrunc' '
c82134a9 246 git log --pretty="tformat:%<(10,ltrunc)%s" >actual &&
f3445f78 247 qz_to_tab_space <<EOF >expected &&
a7f01c6b
NTND
248..sage two
249..sage one
250add bar Z
37eb772e 251..${sample_utf8_part}lich
a7f01c6b
NTND
252EOF
253 test_cmp expected actual
f3445f78 254'
a7f01c6b 255
7d509878 256test_expect_success 'left alignment formatting with ltrunc. i18n.logOutputEncoding' '
d928d810
AS
257 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,ltrunc)%s" >actual &&
258 qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
259..sage two
260..sage one
261add bar Z
262..${sample_utf8_part}lich
263EOF
264 test_cmp expected actual
265'
266
f3445f78 267test_expect_success 'left alignment formatting with mtrunc' '
c82134a9 268 git log --pretty="tformat:%<(10,mtrunc)%s" >actual &&
f3445f78 269 qz_to_tab_space <<EOF >expected &&
a7f01c6b
NTND
270mess.. two
271mess.. one
272add bar Z
37eb772e 273init..lich
a7f01c6b
NTND
274EOF
275 test_cmp expected actual
f3445f78 276'
a7f01c6b 277
7d509878 278test_expect_success 'left alignment formatting with mtrunc. i18n.logOutputEncoding' '
d928d810
AS
279 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,mtrunc)%s" >actual &&
280 qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
281mess.. two
282mess.. one
283add bar Z
284init..lich
285EOF
286 test_cmp expected actual
287'
288
f3445f78 289test_expect_success 'right alignment formatting' '
c82134a9 290 git log --pretty="tformat:%>(40)%s" >actual &&
f3445f78 291 qz_to_tab_space <<EOF >expected &&
a5752342
NTND
292Z message two
293Z message one
294Z add bar
de6029a2 295Z $(commit_msg)
a5752342
NTND
296EOF
297 test_cmp expected actual
f3445f78 298'
a5752342 299
d928d810
AS
300test_expect_success 'right alignment formatting. i18n.logOutputEncoding' '
301 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(40)%s" >actual &&
302 qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
303Z message two
304Z message one
305Z add bar
306Z $(commit_msg)
307EOF
308 test_cmp expected actual
309'
310
f3445f78 311test_expect_success 'right alignment formatting at the nth column' '
c82134a9 312 git log --pretty="tformat:%h %>|(40)%s" >actual &&
f3445f78 313 qz_to_tab_space <<EOF >expected &&
a742f2a0
AS
314$head1 message two
315$head2 message one
316$head3 add bar
de6029a2 317$head4 $(commit_msg)
a5752342
NTND
318EOF
319 test_cmp expected actual
f3445f78 320'
a5752342 321
066790d7
NTND
322test_expect_success 'right alignment formatting at the nth column' '
323 COLUMNS=50 git log --pretty="tformat:%h %>|(-10)%s" >actual &&
324 qz_to_tab_space <<EOF >expected &&
325$head1 message two
326$head2 message one
327$head3 add bar
328$head4 $(commit_msg)
329EOF
330 test_cmp expected actual
331'
332
d928d810
AS
333test_expect_success 'right alignment formatting at the nth column. i18n.logOutputEncoding' '
334 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %>|(40)%s" >actual &&
335 qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
336$head1 message two
337$head2 message one
338$head3 add bar
339$head4 $(commit_msg)
340EOF
341 test_cmp expected actual
342'
343
3ad87c80
JK
344# Note: Space between 'message' and 'two' should be in the same column
345# as in previous test.
346test_expect_success 'right alignment formatting at the nth column with --graph. i18n.logOutputEncoding' '
347 git -c i18n.logOutputEncoding=$test_encoding log --graph --pretty="tformat:%h %>|(40)%s" >actual &&
348 iconv -f utf-8 -t $test_encoding >expected <<EOF&&
349* $head1 message two
350* $head2 message one
351* $head3 add bar
352* $head4 $(commit_msg)
353EOF
354 test_cmp expected actual
355'
356
f3445f78 357test_expect_success 'right alignment formatting with no padding' '
c82134a9 358 git log --pretty="tformat:%>(1)%s" >actual &&
f3445f78 359 cat <<EOF >expected &&
a5752342
NTND
360message two
361message one
362add bar
de6029a2 363$(commit_msg)
a5752342
NTND
364EOF
365 test_cmp expected actual
f3445f78 366'
a5752342 367
3ad87c80
JK
368test_expect_success 'right alignment formatting with no padding and with --graph' '
369 git log --graph --pretty="tformat:%>(1)%s" >actual &&
370 cat <<EOF >expected &&
371* message two
372* message one
373* add bar
374* $(commit_msg)
375EOF
376 test_cmp expected actual
377'
378
d928d810
AS
379test_expect_success 'right alignment formatting with no padding. i18n.logOutputEncoding' '
380 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(1)%s" >actual &&
381 cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
382message two
383message one
384add bar
385$(commit_msg)
386EOF
387 test_cmp expected actual
388'
389
f3445f78 390test_expect_success 'center alignment formatting' '
c82134a9 391 git log --pretty="tformat:%><(40)%s" >actual &&
f3445f78 392 qz_to_tab_space <<EOF >expected &&
a5752342
NTND
393Z message two Z
394Z message one Z
395Z add bar Z
de6029a2 396Z $(commit_msg) Z
a5752342
NTND
397EOF
398 test_cmp expected actual
f3445f78 399'
a5752342 400
d928d810
AS
401test_expect_success 'center alignment formatting. i18n.logOutputEncoding' '
402 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(40)%s" >actual &&
403 qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
404Z message two Z
405Z message one Z
406Z add bar Z
407Z $(commit_msg) Z
408EOF
409 test_cmp expected actual
410'
f3445f78 411test_expect_success 'center alignment formatting at the nth column' '
c82134a9 412 git log --pretty="tformat:%h %><|(40)%s" >actual &&
f3445f78 413 qz_to_tab_space <<EOF >expected &&
a742f2a0
AS
414$head1 message two Z
415$head2 message one Z
416$head3 add bar Z
de6029a2 417$head4 $(commit_msg) Z
a5752342
NTND
418EOF
419 test_cmp expected actual
f3445f78 420'
a5752342 421
066790d7
NTND
422test_expect_success 'center alignment formatting at the nth column' '
423 COLUMNS=70 git log --pretty="tformat:%h %><|(-30)%s" >actual &&
424 qz_to_tab_space <<EOF >expected &&
425$head1 message two Z
426$head2 message one Z
427$head3 add bar Z
428$head4 $(commit_msg) Z
429EOF
430 test_cmp expected actual
431'
432
d928d810
AS
433test_expect_success 'center alignment formatting at the nth column. i18n.logOutputEncoding' '
434 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %><|(40)%s" >actual &&
435 qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
436$head1 message two Z
437$head2 message one Z
438$head3 add bar Z
439$head4 $(commit_msg) Z
440EOF
441 test_cmp expected actual
442'
443
f3445f78 444test_expect_success 'center alignment formatting with no padding' '
c82134a9 445 git log --pretty="tformat:%><(1)%s" >actual &&
f3445f78 446 cat <<EOF >expected &&
a5752342
NTND
447message two
448message one
449add bar
de6029a2 450$(commit_msg)
a5752342
NTND
451EOF
452 test_cmp expected actual
f3445f78 453'
a5752342 454
496a6980
AS
455# save HEAD's SHA-1 digest (with no abbreviations) to use it below
456# as far as the next test amends HEAD
457old_head1=$(git rev-parse --verify HEAD~0)
d928d810
AS
458test_expect_success 'center alignment formatting with no padding. i18n.logOutputEncoding' '
459 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(1)%s" >actual &&
460 cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
461message two
462message one
463add bar
464$(commit_msg)
465EOF
466 test_cmp expected actual
467'
496a6980 468
f3445f78
AS
469test_expect_success 'left/right alignment formatting with stealing' '
470 git commit --amend -m short --author "long long long <long@me.com>" &&
c82134a9 471 git log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
f3445f78 472 cat <<EOF >expected &&
1640632b
NTND
473short long long long
474message .. A U Thor
475add bar A U Thor
37eb772e 476initial... A U Thor
1640632b
NTND
477EOF
478 test_cmp expected actual
f3445f78 479'
7d509878 480test_expect_success 'left/right alignment formatting with stealing. i18n.logOutputEncoding' '
d928d810
AS
481 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
482 cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
483short long long long
484message .. A U Thor
485add bar A U Thor
486initial... A U Thor
487EOF
488 test_cmp expected actual
489'
1640632b 490
43087596
NTND
491test_expect_success 'strbuf_utf8_replace() not producing NUL' '
492 git log --color --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)%C(auto)%d" |
493 test_decode_color |
494 nul_to_q >actual &&
495 ! grep Q actual
496'
497
466fb674
BB
498# ISO strict date format
499test_expect_success 'ISO and ISO-strict date formats display the same values' '
500 git log --format=%ai%n%ci |
501 sed -e "s/ /T/; s/ //; s/..\$/:&/" >expected &&
502 git log --format=%aI%n%cI >actual &&
503 test_cmp expected actual
504'
505
496a6980
AS
506# get new digests (with no abbreviations)
507head1=$(git rev-parse --verify HEAD~0) &&
508head2=$(git rev-parse --verify HEAD~1) &&
509
5e1361cc 510test_expect_success 'log decoration properly follows tag chain' '
511 git tag -a tag1 -m tag1 &&
512 git tag -a tag2 -m tag2 tag1 &&
513 git tag -d tag1 &&
514 git commit --amend -m shorter &&
515 git log --no-walk --tags --pretty="%H %d" --decorate=full >actual &&
516 cat <<EOF >expected &&
496a6980
AS
517$head1 (tag: refs/tags/tag2)
518$head2 (tag: refs/tags/message-one)
519$old_head1 (tag: refs/tags/message-two)
5e1361cc 520EOF
521 sort actual >actual1 &&
522 test_cmp expected actual1
523'
524
9271095c
HJ
525test_expect_success 'clean log decoration' '
526 git log --no-walk --tags --pretty="%H %D" --decorate=full >actual &&
527 cat >expected <<EOF &&
528$head1 tag: refs/tags/tag2
529$head2 tag: refs/tags/message-one
530$old_head1 tag: refs/tags/message-two
531EOF
532 sort actual >actual1 &&
533 test_cmp expected actual1
534'
535
8028184e 536test_done