]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4205-log-pretty-formats.sh
path.c: don't call the match function without value in trie_find()
[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
0d75bfe6 129test_expect_failure C_LOCALE_OUTPUT 'NUL termination with --stat' '
fafd3829 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 &&
0d75bfe6 134 test_cmp 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 &&
9d1ca1da
JK
148 qz_to_tab_space <<-EOF >expected &&
149 message two Z
150 message one Z
151 add bar Z
152 $(commit_msg) Z
153 EOF
a5752342 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 &&
9d1ca1da
JK
159 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
160 message two Z
161 message one Z
162 add bar Z
163 $(commit_msg) Z
164 EOF
d928d810
AS
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 &&
9d1ca1da
JK
170 qz_to_tab_space <<-EOF >expected &&
171 $head1 message two Z
172 $head2 message one Z
173 $head3 add bar Z
174 $head4 $(commit_msg) Z
175 EOF
a5752342 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 &&
9d1ca1da
JK
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
186 EOF
066790d7
NTND
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 &&
9d1ca1da
JK
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
197 EOF
d928d810
AS
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 &&
9d1ca1da
JK
203 cat <<-EOF >expected &&
204 message two
205 message one
206 add bar
207 $(commit_msg)
208 EOF
a5752342 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 &&
9d1ca1da
JK
214 cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
215 message two
216 message one
217 add bar
218 $(commit_msg)
219 EOF
d928d810
AS
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 &&
9d1ca1da
JK
225 qz_to_tab_space <<-\EOF >expected &&
226 message ..
227 message ..
228 add bar Z
229 initial...
230 EOF
a7f01c6b 231 test_cmp expected actual
f3445f78 232'
a7f01c6b 233
7d509878 234test_expect_success 'left alignment formatting with trunc. i18n.logOutputEncoding' '
d928d810 235 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s" >actual &&
9d1ca1da
JK
236 qz_to_tab_space <<-\EOF | iconv -f utf-8 -t $test_encoding >expected &&
237 message ..
238 message ..
239 add bar Z
240 initial...
241 EOF
d928d810
AS
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 &&
9d1ca1da
JK
247 qz_to_tab_space <<-EOF >expected &&
248 ..sage two
249 ..sage one
250 add bar Z
251 ..${sample_utf8_part}lich
252 EOF
a7f01c6b 253 test_cmp expected actual
f3445f78 254'
a7f01c6b 255
7d509878 256test_expect_success 'left alignment formatting with ltrunc. i18n.logOutputEncoding' '
d928d810 257 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,ltrunc)%s" >actual &&
9d1ca1da
JK
258 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
259 ..sage two
260 ..sage one
261 add bar Z
262 ..${sample_utf8_part}lich
263 EOF
d928d810
AS
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 &&
9d1ca1da
JK
269 qz_to_tab_space <<-\EOF >expected &&
270 mess.. two
271 mess.. one
272 add bar Z
273 init..lich
274 EOF
a7f01c6b 275 test_cmp expected actual
f3445f78 276'
a7f01c6b 277
7d509878 278test_expect_success 'left alignment formatting with mtrunc. i18n.logOutputEncoding' '
d928d810 279 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,mtrunc)%s" >actual &&
9d1ca1da
JK
280 qz_to_tab_space <<-\EOF | iconv -f utf-8 -t $test_encoding >expected &&
281 mess.. two
282 mess.. one
283 add bar Z
284 init..lich
285 EOF
d928d810
AS
286 test_cmp expected actual
287'
288
f3445f78 289test_expect_success 'right alignment formatting' '
c82134a9 290 git log --pretty="tformat:%>(40)%s" >actual &&
9d1ca1da
JK
291 qz_to_tab_space <<-EOF >expected &&
292 Z message two
293 Z message one
294 Z add bar
295 Z $(commit_msg)
296 EOF
a5752342 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 &&
9d1ca1da
JK
302 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
303 Z message two
304 Z message one
305 Z add bar
306 Z $(commit_msg)
307 EOF
d928d810
AS
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 &&
9d1ca1da
JK
313 qz_to_tab_space <<-EOF >expected &&
314 $head1 message two
315 $head2 message one
316 $head3 add bar
317 $head4 $(commit_msg)
318 EOF
a5752342 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 &&
9d1ca1da
JK
324 qz_to_tab_space <<-EOF >expected &&
325 $head1 message two
326 $head2 message one
327 $head3 add bar
328 $head4 $(commit_msg)
329 EOF
066790d7
NTND
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 &&
9d1ca1da
JK
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)
340 EOF
d928d810
AS
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 &&
9d1ca1da
JK
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)
353 EOF
3ad87c80
JK
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 &&
9d1ca1da
JK
359 cat <<-EOF >expected &&
360 message two
361 message one
362 add bar
363 $(commit_msg)
364 EOF
a5752342 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 &&
9d1ca1da
JK
370 cat <<-EOF >expected &&
371 * message two
372 * message one
373 * add bar
374 * $(commit_msg)
375 EOF
3ad87c80
JK
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 &&
9d1ca1da
JK
381 cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
382 message two
383 message one
384 add bar
385 $(commit_msg)
386 EOF
d928d810
AS
387 test_cmp expected actual
388'
389
f3445f78 390test_expect_success 'center alignment formatting' '
c82134a9 391 git log --pretty="tformat:%><(40)%s" >actual &&
9d1ca1da
JK
392 qz_to_tab_space <<-EOF >expected &&
393 Z message two Z
394 Z message one Z
395 Z add bar Z
396 Z $(commit_msg) Z
397 EOF
a5752342 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 &&
9d1ca1da
JK
403 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
404 Z message two Z
405 Z message one Z
406 Z add bar Z
407 Z $(commit_msg) Z
408 EOF
d928d810
AS
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 &&
9d1ca1da
JK
413 qz_to_tab_space <<-EOF >expected &&
414 $head1 message two Z
415 $head2 message one Z
416 $head3 add bar Z
417 $head4 $(commit_msg) Z
418 EOF
a5752342 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 &&
9d1ca1da
JK
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
429 EOF
066790d7
NTND
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 &&
9d1ca1da
JK
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
440 EOF
d928d810
AS
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 &&
9d1ca1da
JK
446 cat <<-EOF >expected &&
447 message two
448 message one
449 add bar
450 $(commit_msg)
451 EOF
a5752342 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 &&
9d1ca1da
JK
460 cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
461 message two
462 message one
463 add bar
464 $(commit_msg)
465 EOF
d928d810
AS
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 &&
9d1ca1da
JK
472 cat <<-\EOF >expected &&
473 short long long long
474 message .. A U Thor
475 add bar A U Thor
476 initial... A U Thor
477 EOF
1640632b 478 test_cmp expected actual
f3445f78 479'
7d509878 480test_expect_success 'left/right alignment formatting with stealing. i18n.logOutputEncoding' '
d928d810 481 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
9d1ca1da
JK
482 cat <<-\EOF | iconv -f utf-8 -t $test_encoding >expected &&
483 short long long long
484 message .. A U Thor
485 add bar A U Thor
486 initial... A U Thor
487 EOF
d928d810
AS
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 506# get new digests (with no abbreviations)
1bd37509
JK
507test_expect_success 'set up log decoration tests' '
508 head1=$(git rev-parse --verify HEAD~0) &&
509 head2=$(git rev-parse --verify HEAD~1)
510'
496a6980 511
5e1361cc 512test_expect_success 'log decoration properly follows tag chain' '
513 git tag -a tag1 -m tag1 &&
514 git tag -a tag2 -m tag2 tag1 &&
515 git tag -d tag1 &&
516 git commit --amend -m shorter &&
517 git log --no-walk --tags --pretty="%H %d" --decorate=full >actual &&
9d1ca1da 518 cat <<-EOF >expected &&
9d1ca1da
JK
519 $head2 (tag: refs/tags/message-one)
520 $old_head1 (tag: refs/tags/message-two)
2a73022e 521 $head1 (tag: refs/tags/tag2)
9d1ca1da 522 EOF
2a73022e 523 sort -k3 actual >actual1 &&
5e1361cc 524 test_cmp expected actual1
525'
526
9271095c
HJ
527test_expect_success 'clean log decoration' '
528 git log --no-walk --tags --pretty="%H %D" --decorate=full >actual &&
9d1ca1da 529 cat >expected <<-EOF &&
9d1ca1da
JK
530 $head2 tag: refs/tags/message-one
531 $old_head1 tag: refs/tags/message-two
2a73022e 532 $head1 tag: refs/tags/tag2
9d1ca1da 533 EOF
2a73022e 534 sort -k3 actual >actual1 &&
9271095c
HJ
535 test_cmp expected actual1
536'
537
d9f31fbf
JK
538cat >trailers <<EOF
539Signed-off-by: A U Thor <author@example.com>
540Acked-by: A U Thor <author@example.com>
541[ v2 updated patch description ]
cc1735c4
JK
542Signed-off-by: A U Thor
543 <author@example.com>
d9f31fbf
JK
544EOF
545
58311c66 546unfold () {
6f5c77a1 547 perl -0pe 's/\n\s+/ /g'
58311c66
JK
548}
549
cc1735c4 550test_expect_success 'set up trailer tests' '
d9f31fbf
JK
551 echo "Some contents" >trailerfile &&
552 git add trailerfile &&
cc1735c4 553 git commit -F - <<-EOF
d9f31fbf
JK
554 trailers: this commit message has trailers
555
556 This commit is a test commit with trailers at the end. We parse this
cc1735c4 557 message and display the trailers using %(trailers).
d9f31fbf
JK
558
559 $(cat trailers)
560 EOF
cc1735c4 561'
d9f31fbf 562
cc1735c4
JK
563test_expect_success 'pretty format %(trailers) shows trailers' '
564 git log --no-walk --pretty="%(trailers)" >actual &&
565 {
566 cat trailers &&
567 echo
568 } >expect &&
d9f31fbf
JK
569 test_cmp expect actual
570'
571
58311c66
JK
572test_expect_success '%(trailers:only) shows only "key: value" trailers' '
573 git log --no-walk --pretty="%(trailers:only)" >actual &&
574 {
575 grep -v patch.description <trailers &&
576 echo
577 } >expect &&
578 test_cmp expect actual
579'
580
4f732e0f
AW
581test_expect_success '%(trailers:only=yes) shows only "key: value" trailers' '
582 git log --no-walk --pretty=format:"%(trailers:only=yes)" >actual &&
583 grep -v patch.description <trailers >expect &&
584 test_cmp expect actual
585'
586
587test_expect_success '%(trailers:only=no) shows all trailers' '
588 git log --no-walk --pretty=format:"%(trailers:only=no)" >actual &&
589 cat trailers >expect &&
590 test_cmp expect actual
591'
592
593test_expect_success '%(trailers:only=no,only=true) shows only "key: value" trailers' '
594 git log --no-walk --pretty=format:"%(trailers:only=yes)" >actual &&
595 grep -v patch.description <trailers >expect &&
596 test_cmp expect actual
58311c66
JK
597'
598
599test_expect_success '%(trailers:unfold) unfolds trailers' '
600 git log --no-walk --pretty="%(trailers:unfold)" >actual &&
601 {
602 unfold <trailers &&
603 echo
604 } >expect &&
605 test_cmp expect actual
606'
607
608test_expect_success ':only and :unfold work together' '
84ff053d
TB
609 git log --no-walk --pretty="%(trailers:only,unfold)" >actual &&
610 git log --no-walk --pretty="%(trailers:unfold,only)" >reverse &&
58311c66
JK
611 test_cmp actual reverse &&
612 {
613 grep -v patch.description <trailers | unfold &&
614 echo
615 } >expect &&
616 test_cmp expect actual
617'
618
250bea0c
AW
619test_expect_success 'pretty format %(trailers:key=foo) shows that trailer' '
620 git log --no-walk --pretty="format:%(trailers:key=Acked-by)" >actual &&
621 echo "Acked-by: A U Thor <author@example.com>" >expect &&
622 test_cmp expect actual
623'
624
625test_expect_success 'pretty format %(trailers:key=foo) is case insensitive' '
626 git log --no-walk --pretty="format:%(trailers:key=AcKed-bY)" >actual &&
627 echo "Acked-by: A U Thor <author@example.com>" >expect &&
628 test_cmp expect actual
629'
630
631test_expect_success 'pretty format %(trailers:key=foo:) trailing colon also works' '
632 git log --no-walk --pretty="format:%(trailers:key=Acked-by:)" >actual &&
633 echo "Acked-by: A U Thor <author@example.com>" >expect &&
634 test_cmp expect actual
635'
636
637test_expect_success 'pretty format %(trailers:key=foo) multiple keys' '
638 git log --no-walk --pretty="format:%(trailers:key=Acked-by:,key=Signed-off-By)" >actual &&
639 grep -v patch.description <trailers >expect &&
640 test_cmp expect actual
641'
642
643test_expect_success '%(trailers:key=nonexistant) becomes empty' '
644 git log --no-walk --pretty="x%(trailers:key=Nacked-by)x" >actual &&
645 echo "xx" >expect &&
646 test_cmp expect actual
647'
648
649test_expect_success '%(trailers:key=foo) handles multiple lines even if folded' '
650 git log --no-walk --pretty="format:%(trailers:key=Signed-Off-by)" >actual &&
651 grep -v patch.description <trailers | grep -v Acked-by >expect &&
652 test_cmp expect actual
653'
654
655test_expect_success '%(trailers:key=foo,unfold) properly unfolds' '
656 git log --no-walk --pretty="format:%(trailers:key=Signed-Off-by,unfold)" >actual &&
657 unfold <trailers | grep Signed-off-by >expect &&
658 test_cmp expect actual
659'
660
661test_expect_success 'pretty format %(trailers:key=foo,only=no) also includes nontrailer lines' '
662 git log --no-walk --pretty="format:%(trailers:key=Acked-by,only=no)" >actual &&
663 {
664 echo "Acked-by: A U Thor <author@example.com>" &&
665 grep patch.description <trailers
666 } >expect &&
667 test_cmp expect actual
668'
669
670test_expect_success '%(trailers:key) without value is error' '
671 git log --no-walk --pretty="tformat:%(trailers:key)" >actual &&
672 echo "%(trailers:key)" >expect &&
673 test_cmp expect actual
674'
675
d9b936db
AW
676test_expect_success '%(trailers:key=foo,valueonly) shows only value' '
677 git log --no-walk --pretty="format:%(trailers:key=Acked-by,valueonly)" >actual &&
678 echo "A U Thor <author@example.com>" >expect &&
679 test_cmp expect actual
680'
681
0b691d86
AW
682test_expect_success 'pretty format %(trailers:separator) changes separator' '
683 git log --no-walk --pretty=format:"X%(trailers:separator=%x00,unfold)X" >actual &&
684 printf "XSigned-off-by: A U Thor <author@example.com>\0Acked-by: A U Thor <author@example.com>\0[ v2 updated patch description ]\0Signed-off-by: A U Thor <author@example.com>X" >expect &&
685 test_cmp expect actual
686'
687
688test_expect_success 'pretty format %(trailers) combining separator/key/valueonly' '
689 git commit --allow-empty -F - <<-\EOF &&
690 Important fix
691
692 The fix is explained here
693
694 Closes: #1234
695 EOF
696
697 git commit --allow-empty -F - <<-\EOF &&
698 Another fix
699
700 The fix is explained here
701
702 Closes: #567
703 Closes: #890
704 EOF
705
706 git commit --allow-empty -F - <<-\EOF &&
707 Does not close any tickets
708 EOF
709
710 git log --pretty="%s% (trailers:separator=%x2c%x20,key=Closes,valueonly)" HEAD~3.. >actual &&
711 test_write_lines \
712 "Does not close any tickets" \
713 "Another fix #567, #890" \
714 "Important fix #1234" >expect &&
715 test_cmp expect actual
716'
717
e5fba5d5
JK
718test_expect_success 'trailer parsing not fooled by --- line' '
719 git commit --allow-empty -F - <<-\EOF &&
720 this is the subject
721
722 This is the body. The message has a "---" line which would confuse a
723 message+patch parser. But here we know we have only a commit message,
724 so we get it right.
725
726 trailer: wrong
727 ---
728 This is more body.
729
730 trailer: right
731 EOF
732
733 {
734 echo "trailer: right" &&
735 echo
736 } >expect &&
737 git log --no-walk --format="%(trailers)" >actual &&
738 test_cmp expect actual
739'
740
ad6f028f
IT
741test_expect_success 'set up %S tests' '
742 git checkout --orphan source-a &&
743 test_commit one &&
744 test_commit two &&
745 git checkout -b source-b HEAD^ &&
746 test_commit three
747'
748
749test_expect_success 'log --format=%S paints branch names' '
750 cat >expect <<-\EOF &&
751 source-b
752 source-a
753 source-b
754 EOF
755 git log --format=%S source-a source-b >actual &&
756 test_cmp expect actual
757'
758
759test_expect_success 'log --format=%S paints tag names' '
760 git tag -m tagged source-tag &&
761 cat >expect <<-\EOF &&
762 source-tag
763 source-a
764 source-tag
765 EOF
766 git log --format=%S source-tag source-a >actual &&
767 test_cmp expect actual
768'
769
770test_expect_success 'log --format=%S paints symmetric ranges' '
771 cat >expect <<-\EOF &&
772 source-b
773 source-a
774 EOF
775 git log --format=%S source-a...source-b >actual &&
776 test_cmp expect actual
777'
778
779test_expect_success '%S in git log --format works with other placeholders (part 1)' '
780 git log --format="source-b %h" source-b >expect &&
781 git log --format="%S %h" source-b >actual &&
782 test_cmp expect actual
783'
784
785test_expect_success '%S in git log --format works with other placeholders (part 2)' '
786 git log --format="%h source-b" source-b >expect &&
787 git log --format="%h %S" source-b >actual &&
788 test_cmp expect actual
789'
790
8028184e 791test_done