git-p4: fix typos
[git/gitster.git] / t / t4205-log-pretty-formats.sh
blob158b49d4b603d10d5fe802fb7888c0257a754d88
1 #!/bin/sh
3 # Copyright (c) 2010, Will Palmer
4 # Copyright (c) 2011, Alexey Shumkin (+ non-UTF-8 commit encoding tests)
7 test_description='Test pretty formats'
8 . ./test-lib.sh
10 # Tested non-UTF-8 encoding
11 test_encoding="ISO8859-1"
13 sample_utf8_part=$(printf "f\303\244ng")
15 commit_msg () {
16 # String "initial. initial" partly in German
17 # (translated with Google Translate),
18 # encoded in UTF-8, used as a commit log message below.
19 msg="initial. an${sample_utf8_part}lich\n"
20 if test -n "$1"
21 then
22 printf "$msg" | iconv -f utf-8 -t "$1"
23 else
24 printf "$msg"
28 test_expect_success 'set up basic repos' '
29 >foo &&
30 >bar &&
31 git add foo &&
32 test_tick &&
33 test_config i18n.commitEncoding $test_encoding &&
34 commit_msg $test_encoding | git commit -F - &&
35 git add bar &&
36 test_tick &&
37 git commit -m "add bar"
40 test_expect_success 'alias builtin format' '
41 git log --pretty=oneline >expected &&
42 test_config pretty.test-alias oneline &&
43 git log --pretty=test-alias >actual &&
44 test_cmp expected actual
47 test_expect_success 'alias masking builtin format' '
48 git log --pretty=oneline >expected &&
49 test_config pretty.oneline "%H" &&
50 git log --pretty=oneline >actual &&
51 test_cmp expected actual
54 test_expect_success 'alias user-defined format' '
55 git log --pretty="format:%h" >expected &&
56 test_config pretty.test-alias "format:%h" &&
57 git log --pretty=test-alias >actual &&
58 test_cmp expected actual
61 test_expect_success 'alias user-defined format is matched case-insensitively' '
62 git log --pretty="format:%h" >expected &&
63 test_config pretty.testone "format:%h" &&
64 test_config pretty.testtwo testOne &&
65 git log --pretty=testTwo >actual &&
66 test_cmp expected actual
69 test_expect_success 'alias user-defined tformat with %s (ISO8859-1 encoding)' '
70 test_config i18n.logOutputEncoding $test_encoding &&
71 git log --oneline >expected-s &&
72 git log --pretty="tformat:%h %s" >actual-s &&
73 test_cmp expected-s actual-s
76 test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' '
77 git log --oneline >expected-s &&
78 git log --pretty="tformat:%h %s" >actual-s &&
79 test_cmp expected-s actual-s
82 test_expect_success 'alias user-defined tformat' '
83 git log --pretty="tformat:%h" >expected &&
84 test_config pretty.test-alias "tformat:%h" &&
85 git log --pretty=test-alias >actual &&
86 test_cmp expected actual
89 test_expect_success 'alias non-existent format' '
90 test_config pretty.test-alias format-that-will-never-exist &&
91 test_must_fail git log --pretty=test-alias
94 test_expect_success 'alias of an alias' '
95 git log --pretty="tformat:%h" >expected &&
96 test_config pretty.test-foo "tformat:%h" &&
97 test_config pretty.test-bar test-foo &&
98 git log --pretty=test-bar >actual && test_cmp expected actual
101 test_expect_success 'alias masking an alias' '
102 git log --pretty=format:"Two %H" >expected &&
103 test_config pretty.duplicate "format:One %H" &&
104 test_config pretty.duplicate "format:Two %H" --add &&
105 git log --pretty=duplicate >actual &&
106 test_cmp expected actual
109 test_expect_success 'alias loop' '
110 test_config pretty.test-foo test-bar &&
111 test_config pretty.test-bar test-foo &&
112 test_must_fail git log --pretty=test-foo
115 test_expect_success 'NUL separation' '
116 printf "add bar\0$(commit_msg)" >expected &&
117 git log -z --pretty="format:%s" >actual &&
118 test_cmp expected actual
121 test_expect_success 'NUL termination' '
122 printf "add bar\0$(commit_msg)\0" >expected &&
123 git log -z --pretty="tformat:%s" >actual &&
124 test_cmp expected actual
127 test_expect_success 'NUL separation with --stat' '
128 stat0_part=$(git diff --stat HEAD^ HEAD) &&
129 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
130 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected &&
131 git log -z --stat --pretty="format:%s" >actual &&
132 test_cmp expected actual
135 test_expect_failure 'NUL termination with --stat' '
136 stat0_part=$(git diff --stat HEAD^ HEAD) &&
137 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
138 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n0" >expected &&
139 git log -z --stat --pretty="tformat:%s" >actual &&
140 test_cmp expected actual
143 for p in short medium full fuller email raw
145 test_expect_success "NUL termination with --reflog --pretty=$p" '
146 revs="$(git rev-list --reflog)" &&
147 for r in $revs
149 git show -s "$r" --pretty="$p" &&
150 printf "\0" || return 1
151 done >expect &&
153 git log -z --reflog --pretty="$p" &&
154 printf "\0"
155 } >actual &&
156 test_cmp expect actual
158 done
160 test_expect_success 'NUL termination with --reflog --pretty=oneline' '
161 revs="$(git rev-list --reflog)" &&
162 for r in $revs
164 git show -s --pretty=oneline "$r" >raw &&
165 lf_to_nul <raw || return 1
166 done >expect &&
167 # the trailing NUL is already produced so we do not need to
168 # output another one
169 git log -z --pretty=oneline --reflog >actual &&
170 test_cmp expect actual
173 test_expect_success 'setup more commits' '
174 test_commit "message one" one one message-one &&
175 test_commit "message two" two two message-two &&
176 head1=$(git rev-parse --verify --short HEAD~0) &&
177 head2=$(git rev-parse --verify --short HEAD~1) &&
178 head3=$(git rev-parse --verify --short HEAD~2) &&
179 head4=$(git rev-parse --verify --short HEAD~3)
182 test_expect_success 'left alignment formatting' '
183 git log --pretty="tformat:%<(40)%s" >actual &&
184 qz_to_tab_space <<-EOF >expected &&
185 message two Z
186 message one Z
187 add bar Z
188 $(commit_msg) Z
190 test_cmp expected actual
193 test_expect_success 'left alignment formatting. i18n.logOutputEncoding' '
194 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(40)%s" >actual &&
195 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
196 message two Z
197 message one Z
198 add bar Z
199 $(commit_msg) Z
201 test_cmp expected actual
204 test_expect_success 'left alignment formatting at the nth column' '
205 git log --pretty="tformat:%h %<|(40)%s" >actual &&
206 qz_to_tab_space <<-EOF >expected &&
207 $head1 message two Z
208 $head2 message one Z
209 $head3 add bar Z
210 $head4 $(commit_msg) Z
212 test_cmp expected actual
215 test_expect_success 'left alignment formatting at the nth column' '
216 COLUMNS=50 git log --pretty="tformat:%h %<|(-10)%s" >actual &&
217 qz_to_tab_space <<-EOF >expected &&
218 $head1 message two Z
219 $head2 message one Z
220 $head3 add bar Z
221 $head4 $(commit_msg) Z
223 test_cmp expected actual
226 test_expect_success 'left alignment formatting at the nth column. i18n.logOutputEncoding' '
227 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %<|(40)%s" >actual &&
228 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
229 $head1 message two Z
230 $head2 message one Z
231 $head3 add bar Z
232 $head4 $(commit_msg) Z
234 test_cmp expected actual
237 test_expect_success 'left alignment formatting with no padding' '
238 git log --pretty="tformat:%<(1)%s" >actual &&
239 cat <<-EOF >expected &&
240 message two
241 message one
242 add bar
243 $(commit_msg)
245 test_cmp expected actual
248 test_expect_success 'left alignment formatting with no padding. i18n.logOutputEncoding' '
249 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(1)%s" >actual &&
250 cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
251 message two
252 message one
253 add bar
254 $(commit_msg)
256 test_cmp expected actual
259 test_expect_success 'left alignment formatting with trunc' '
260 git log --pretty="tformat:%<(10,trunc)%s" >actual &&
261 qz_to_tab_space <<-\EOF >expected &&
262 message ..
263 message ..
264 add bar Z
265 initial...
267 test_cmp expected actual
270 test_expect_success 'left alignment formatting with trunc. i18n.logOutputEncoding' '
271 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s" >actual &&
272 qz_to_tab_space <<-\EOF | iconv -f utf-8 -t $test_encoding >expected &&
273 message ..
274 message ..
275 add bar Z
276 initial...
278 test_cmp expected actual
281 test_expect_success 'left alignment formatting with ltrunc' '
282 git log --pretty="tformat:%<(10,ltrunc)%s" >actual &&
283 qz_to_tab_space <<-EOF >expected &&
284 ..sage two
285 ..sage one
286 add bar Z
287 ..${sample_utf8_part}lich
289 test_cmp expected actual
292 test_expect_success 'left alignment formatting with ltrunc. i18n.logOutputEncoding' '
293 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,ltrunc)%s" >actual &&
294 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
295 ..sage two
296 ..sage one
297 add bar Z
298 ..${sample_utf8_part}lich
300 test_cmp expected actual
303 test_expect_success 'left alignment formatting with mtrunc' '
304 git log --pretty="tformat:%<(10,mtrunc)%s" >actual &&
305 qz_to_tab_space <<-\EOF >expected &&
306 mess.. two
307 mess.. one
308 add bar Z
309 init..lich
311 test_cmp expected actual
314 test_expect_success 'left alignment formatting with mtrunc. i18n.logOutputEncoding' '
315 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,mtrunc)%s" >actual &&
316 qz_to_tab_space <<-\EOF | iconv -f utf-8 -t $test_encoding >expected &&
317 mess.. two
318 mess.. one
319 add bar Z
320 init..lich
322 test_cmp expected actual
325 test_expect_success 'right alignment formatting' '
326 git log --pretty="tformat:%>(40)%s" >actual &&
327 qz_to_tab_space <<-EOF >expected &&
328 Z message two
329 Z message one
330 Z add bar
331 Z $(commit_msg)
333 test_cmp expected actual
336 test_expect_success 'right alignment formatting. i18n.logOutputEncoding' '
337 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(40)%s" >actual &&
338 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
339 Z message two
340 Z message one
341 Z add bar
342 Z $(commit_msg)
344 test_cmp expected actual
347 test_expect_success 'right alignment formatting at the nth column' '
348 git log --pretty="tformat:%h %>|(40)%s" >actual &&
349 qz_to_tab_space <<-EOF >expected &&
350 $head1 message two
351 $head2 message one
352 $head3 add bar
353 $head4 $(commit_msg)
355 test_cmp expected actual
358 test_expect_success 'right alignment formatting at the nth column' '
359 COLUMNS=50 git log --pretty="tformat:%h %>|(-10)%s" >actual &&
360 qz_to_tab_space <<-EOF >expected &&
361 $head1 message two
362 $head2 message one
363 $head3 add bar
364 $head4 $(commit_msg)
366 test_cmp expected actual
369 test_expect_success 'right alignment formatting at the nth column. i18n.logOutputEncoding' '
370 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %>|(40)%s" >actual &&
371 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
372 $head1 message two
373 $head2 message one
374 $head3 add bar
375 $head4 $(commit_msg)
377 test_cmp expected actual
380 # Note: Space between 'message' and 'two' should be in the same column
381 # as in previous test.
382 test_expect_success 'right alignment formatting at the nth column with --graph. i18n.logOutputEncoding' '
383 git -c i18n.logOutputEncoding=$test_encoding log --graph --pretty="tformat:%h %>|(40)%s" >actual &&
384 iconv -f utf-8 -t $test_encoding >expected <<-EOF &&
385 * $head1 message two
386 * $head2 message one
387 * $head3 add bar
388 * $head4 $(commit_msg)
390 test_cmp expected actual
393 test_expect_success 'right alignment formatting with no padding' '
394 git log --pretty="tformat:%>(1)%s" >actual &&
395 cat <<-EOF >expected &&
396 message two
397 message one
398 add bar
399 $(commit_msg)
401 test_cmp expected actual
404 test_expect_success 'right alignment formatting with no padding and with --graph' '
405 git log --graph --pretty="tformat:%>(1)%s" >actual &&
406 cat <<-EOF >expected &&
407 * message two
408 * message one
409 * add bar
410 * $(commit_msg)
412 test_cmp expected actual
415 test_expect_success 'right alignment formatting with no padding. i18n.logOutputEncoding' '
416 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(1)%s" >actual &&
417 cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
418 message two
419 message one
420 add bar
421 $(commit_msg)
423 test_cmp expected actual
426 test_expect_success 'center alignment formatting' '
427 git log --pretty="tformat:%><(40)%s" >actual &&
428 qz_to_tab_space <<-EOF >expected &&
429 Z message two Z
430 Z message one Z
431 Z add bar Z
432 Z $(commit_msg) Z
434 test_cmp expected actual
437 test_expect_success 'center alignment formatting. i18n.logOutputEncoding' '
438 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(40)%s" >actual &&
439 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
440 Z message two Z
441 Z message one Z
442 Z add bar Z
443 Z $(commit_msg) Z
445 test_cmp expected actual
447 test_expect_success 'center alignment formatting at the nth column' '
448 git log --pretty="tformat:%h %><|(40)%s" >actual &&
449 qz_to_tab_space <<-EOF >expected &&
450 $head1 message two Z
451 $head2 message one Z
452 $head3 add bar Z
453 $head4 $(commit_msg) Z
455 test_cmp expected actual
458 test_expect_success 'center alignment formatting at the nth column' '
459 COLUMNS=70 git log --pretty="tformat:%h %><|(-30)%s" >actual &&
460 qz_to_tab_space <<-EOF >expected &&
461 $head1 message two Z
462 $head2 message one Z
463 $head3 add bar Z
464 $head4 $(commit_msg) Z
466 test_cmp expected actual
469 test_expect_success 'center alignment formatting at the nth column. i18n.logOutputEncoding' '
470 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %><|(40)%s" >actual &&
471 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
472 $head1 message two Z
473 $head2 message one Z
474 $head3 add bar Z
475 $head4 $(commit_msg) Z
477 test_cmp expected actual
480 test_expect_success 'center alignment formatting with no padding' '
481 git log --pretty="tformat:%><(1)%s" >actual &&
482 cat <<-EOF >expected &&
483 message two
484 message one
485 add bar
486 $(commit_msg)
488 test_cmp expected actual
491 # save HEAD's SHA-1 digest (with no abbreviations) to use it below
492 # as far as the next test amends HEAD
493 old_head1=$(git rev-parse --verify HEAD~0)
494 test_expect_success 'center alignment formatting with no padding. i18n.logOutputEncoding' '
495 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(1)%s" >actual &&
496 cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
497 message two
498 message one
499 add bar
500 $(commit_msg)
502 test_cmp expected actual
505 test_expect_success 'left/right alignment formatting with stealing' '
506 git commit --amend -m short --author "long long long <long@me.com>" &&
507 git log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
508 cat <<-\EOF >expected &&
509 short long long long
510 message .. A U Thor
511 add bar A U Thor
512 initial... A U Thor
514 test_cmp expected actual
516 test_expect_success 'left/right alignment formatting with stealing. i18n.logOutputEncoding' '
517 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
518 cat <<-\EOF | iconv -f utf-8 -t $test_encoding >expected &&
519 short long long long
520 message .. A U Thor
521 add bar A U Thor
522 initial... A U Thor
524 test_cmp expected actual
527 test_expect_success 'strbuf_utf8_replace() not producing NUL' '
528 git log --color --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)%C(auto)%d" |
529 test_decode_color |
530 nul_to_q >actual &&
531 ! grep Q actual
534 # --date=[XXX] and corresponding %a[X] %c[X] format equivalency
535 test_expect_success '--date=iso-strict %ad%cd is the same as %aI%cI' '
536 git log --format=%ad%n%cd --date=iso-strict >expected &&
537 git log --format=%aI%n%cI >actual &&
538 test_cmp expected actual
541 test_expect_success '--date=short %ad%cd is the same as %as%cs' '
542 git log --format=%ad%n%cd --date=short >expected &&
543 git log --format=%as%n%cs >actual &&
544 test_cmp expected actual
547 test_expect_success '--date=human %ad%cd is the same as %ah%ch' '
548 git log --format=%ad%n%cd --date=human >expected &&
549 git log --format=%ah%n%ch >actual &&
550 test_cmp expected actual
553 # get new digests (with no abbreviations)
554 test_expect_success 'set up log decoration tests' '
555 head1=$(git rev-parse --verify HEAD~0) &&
556 head2=$(git rev-parse --verify HEAD~1)
559 test_expect_success 'log decoration properly follows tag chain' '
560 git tag -a tag1 -m tag1 &&
561 git tag -a tag2 -m tag2 tag1 &&
562 git tag -d tag1 &&
563 git commit --amend -m shorter &&
564 git log --no-walk --tags --pretty="%H %d" --decorate=full >actual &&
565 cat <<-EOF >expected &&
566 $head2 (tag: refs/tags/message-one)
567 $old_head1 (tag: refs/tags/message-two)
568 $head1 (tag: refs/tags/tag2)
570 sort -k3 actual >actual1 &&
571 test_cmp expected actual1
574 test_expect_success 'clean log decoration' '
575 git log --no-walk --tags --pretty="%H %D" --decorate=full >actual &&
576 cat >expected <<-EOF &&
577 $head2 tag: refs/tags/message-one
578 $old_head1 tag: refs/tags/message-two
579 $head1 tag: refs/tags/tag2
581 sort -k3 actual >actual1 &&
582 test_cmp expected actual1
585 test_expect_success 'pretty format %decorate' '
586 git checkout -b foo &&
587 git commit --allow-empty -m "new commit" &&
588 git tag bar &&
589 git branch qux &&
591 echo " (HEAD -> foo, tag: bar, qux)" >expect1 &&
592 git log --format="%(decorate)" -1 >actual1 &&
593 test_cmp expect1 actual1 &&
595 echo "HEAD -> foo, tag: bar, qux" >expect2 &&
596 git log --format="%(decorate:prefix=,suffix=)" -1 >actual2 &&
597 test_cmp expect2 actual2 &&
599 echo "[ bar; qux; foo ]" >expect3 &&
600 git log --format="%(decorate:prefix=[ ,suffix= ],separator=%x3B ,tag=)" \
601 --decorate-refs=refs/ -1 >actual3 &&
602 test_cmp expect3 actual3 &&
604 # Try with a typo (in "separator"), in which case the placeholder should
605 # not be replaced.
606 echo "%(decorate:prefix=[ ,suffix= ],separater=; )" >expect4 &&
607 git log --format="%(decorate:prefix=[ ,suffix= ],separater=%x3B )" \
608 -1 >actual4 &&
609 test_cmp expect4 actual4 &&
611 echo "HEAD->foo bar qux" >expect5 &&
612 git log --format="%(decorate:prefix=,suffix=,separator= ,tag=,pointer=->)" \
613 -1 >actual5 &&
614 test_cmp expect5 actual5
617 cat >trailers <<EOF
618 Signed-off-by: A U Thor <author@example.com>
619 Acked-by: A U Thor <author@example.com>
620 [ v2 updated patch description ]
621 Signed-off-by: A U Thor
622 <author@example.com>
625 unfold () {
626 perl -0pe 's/\n\s+/ /g'
629 test_expect_success 'set up trailer tests' '
630 echo "Some contents" >trailerfile &&
631 git add trailerfile &&
632 git commit -F - <<-EOF
633 trailers: this commit message has trailers
635 This commit is a test commit with trailers at the end. We parse this
636 message and display the trailers using %(trailers).
638 $(cat trailers)
642 test_expect_success 'pretty format %(trailers) shows trailers' '
643 git log --no-walk --pretty="%(trailers)" >actual &&
645 cat trailers &&
646 echo
647 } >expect &&
648 test_cmp expect actual
651 test_expect_success 'pretty format %(trailers:) enables no options' '
652 git log --no-walk --pretty="%(trailers:)" >actual &&
653 # "expect" the same as the test above
654 test_cmp expect actual
657 test_expect_success '%(trailers:only) shows only "key: value" trailers' '
658 git log --no-walk --pretty="%(trailers:only)" >actual &&
660 grep -v patch.description <trailers &&
661 echo
662 } >expect &&
663 test_cmp expect actual
666 test_expect_success '%(trailers:only=yes) shows only "key: value" trailers' '
667 git log --no-walk --pretty=format:"%(trailers:only=yes)" >actual &&
668 grep -v patch.description <trailers >expect &&
669 test_cmp expect actual
672 test_expect_success '%(trailers:only=no) shows all trailers' '
673 git log --no-walk --pretty=format:"%(trailers:only=no)" >actual &&
674 cat trailers >expect &&
675 test_cmp expect actual
678 test_expect_success '%(trailers:only=no,only=true) shows only "key: value" trailers' '
679 git log --no-walk --pretty=format:"%(trailers:only=yes)" >actual &&
680 grep -v patch.description <trailers >expect &&
681 test_cmp expect actual
684 test_expect_success '%(trailers:unfold) unfolds trailers' '
685 git log --no-walk --pretty="%(trailers:unfold)" >actual &&
687 unfold <trailers &&
688 echo
689 } >expect &&
690 test_cmp expect actual
693 test_expect_success ':only and :unfold work together' '
694 git log --no-walk --pretty="%(trailers:only,unfold)" >actual &&
695 git log --no-walk --pretty="%(trailers:unfold,only)" >reverse &&
696 test_cmp actual reverse &&
698 grep -v patch.description <trailers | unfold &&
699 echo
700 } >expect &&
701 test_cmp expect actual
704 test_expect_success 'pretty format %(trailers:key=foo) shows that trailer' '
705 git log --no-walk --pretty="format:%(trailers:key=Acked-by)" >actual &&
706 echo "Acked-by: A U Thor <author@example.com>" >expect &&
707 test_cmp expect actual
710 test_expect_success 'pretty format %(trailers:key=foo) is case insensitive' '
711 git log --no-walk --pretty="format:%(trailers:key=AcKed-bY)" >actual &&
712 echo "Acked-by: A U Thor <author@example.com>" >expect &&
713 test_cmp expect actual
716 test_expect_success 'pretty format %(trailers:key=foo:) trailing colon also works' '
717 git log --no-walk --pretty="format:%(trailers:key=Acked-by:)" >actual &&
718 echo "Acked-by: A U Thor <author@example.com>" >expect &&
719 test_cmp expect actual
722 test_expect_success 'pretty format %(trailers:key=foo) multiple keys' '
723 git log --no-walk --pretty="format:%(trailers:key=Acked-by:,key=Signed-off-By)" >actual &&
724 grep -v patch.description <trailers >expect &&
725 test_cmp expect actual
728 test_expect_success '%(trailers:key=nonexistent) becomes empty' '
729 git log --no-walk --pretty="x%(trailers:key=Nacked-by)x" >actual &&
730 echo "xx" >expect &&
731 test_cmp expect actual
734 test_expect_success '%(trailers:key=foo) handles multiple lines even if folded' '
735 git log --no-walk --pretty="format:%(trailers:key=Signed-Off-by)" >actual &&
736 grep -v patch.description <trailers | grep -v Acked-by >expect &&
737 test_cmp expect actual
740 test_expect_success '%(trailers:key=foo,unfold) properly unfolds' '
741 git log --no-walk --pretty="format:%(trailers:key=Signed-Off-by,unfold)" >actual &&
742 unfold <trailers | grep Signed-off-by >expect &&
743 test_cmp expect actual
746 test_expect_success 'pretty format %(trailers:key=foo,only=no) also includes nontrailer lines' '
747 git log --no-walk --pretty="format:%(trailers:key=Acked-by,only=no)" >actual &&
749 echo "Acked-by: A U Thor <author@example.com>" &&
750 grep patch.description <trailers
751 } >expect &&
752 test_cmp expect actual
755 test_expect_success '%(trailers:key) without value is error' '
756 git log --no-walk --pretty="tformat:%(trailers:key)" >actual &&
757 echo "%(trailers:key)" >expect &&
758 test_cmp expect actual
761 test_expect_success '%(trailers:keyonly) shows only keys' '
762 git log --no-walk --pretty="format:%(trailers:keyonly)" >actual &&
763 test_write_lines \
764 "Signed-off-by" \
765 "Acked-by" \
766 "[ v2 updated patch description ]" \
767 "Signed-off-by" >expect &&
768 test_cmp expect actual
771 test_expect_success '%(trailers:key=foo,keyonly) shows only key' '
772 git log --no-walk --pretty="format:%(trailers:key=Acked-by,keyonly)" >actual &&
773 echo "Acked-by" >expect &&
774 test_cmp expect actual
777 test_expect_success '%(trailers:key=foo,valueonly) shows only value' '
778 git log --no-walk --pretty="format:%(trailers:key=Acked-by,valueonly)" >actual &&
779 echo "A U Thor <author@example.com>" >expect &&
780 test_cmp expect actual
783 test_expect_success '%(trailers:valueonly) shows only values' '
784 git log --no-walk --pretty="format:%(trailers:valueonly)" >actual &&
785 test_write_lines \
786 "A U Thor <author@example.com>" \
787 "A U Thor <author@example.com>" \
788 "[ v2 updated patch description ]" \
789 "A U Thor" \
790 " <author@example.com>" >expect &&
791 test_cmp expect actual
794 test_expect_success '%(trailers:key=foo,keyonly,valueonly) shows nothing' '
795 git log --no-walk --pretty="format:%(trailers:key=Acked-by,keyonly,valueonly)" >actual &&
796 echo >expect &&
797 test_cmp expect actual
800 test_expect_success 'pretty format %(trailers:separator) changes separator' '
801 git log --no-walk --pretty=format:"X%(trailers:separator=%x00)X" >actual &&
803 printf "XSigned-off-by: A U Thor <author@example.com>\0" &&
804 printf "Acked-by: A U Thor <author@example.com>\0" &&
805 printf "[ v2 updated patch description ]\0" &&
806 printf "Signed-off-by: A U Thor\n <author@example.com>X"
807 ) >expect &&
808 test_cmp expect actual
811 test_expect_success 'pretty format %(trailers:separator=X,unfold) changes separator' '
812 git log --no-walk --pretty=format:"X%(trailers:separator=%x00,unfold)X" >actual &&
814 printf "XSigned-off-by: A U Thor <author@example.com>\0" &&
815 printf "Acked-by: A U Thor <author@example.com>\0" &&
816 printf "[ v2 updated patch description ]\0" &&
817 printf "Signed-off-by: A U Thor <author@example.com>X"
818 ) >expect &&
819 test_cmp expect actual
822 test_expect_success 'pretty format %(trailers:key_value_separator) changes key-value separator' '
823 git log --no-walk --pretty=format:"X%(trailers:key_value_separator=%x00)X" >actual &&
825 printf "XSigned-off-by\0A U Thor <author@example.com>\n" &&
826 printf "Acked-by\0A U Thor <author@example.com>\n" &&
827 printf "[ v2 updated patch description ]\n" &&
828 printf "Signed-off-by\0A U Thor\n <author@example.com>\nX"
829 ) >expect &&
830 test_cmp expect actual
833 test_expect_success 'pretty format %(trailers:key_value_separator,unfold) changes key-value separator' '
834 git log --no-walk --pretty=format:"X%(trailers:key_value_separator=%x00,unfold)X" >actual &&
836 printf "XSigned-off-by\0A U Thor <author@example.com>\n" &&
837 printf "Acked-by\0A U Thor <author@example.com>\n" &&
838 printf "[ v2 updated patch description ]\n" &&
839 printf "Signed-off-by\0A U Thor <author@example.com>\nX"
840 ) >expect &&
841 test_cmp expect actual
844 test_expect_success 'pretty format %(trailers:separator,key_value_separator) changes both separators' '
845 git log --no-walk --pretty=format:"%(trailers:separator=%x00,key_value_separator=%x00%x00,unfold)" >actual &&
847 printf "Signed-off-by\0\0A U Thor <author@example.com>\0" &&
848 printf "Acked-by\0\0A U Thor <author@example.com>\0" &&
849 printf "[ v2 updated patch description ]\0" &&
850 printf "Signed-off-by\0\0A U Thor <author@example.com>"
851 ) >expect &&
852 test_cmp expect actual
855 test_expect_success 'pretty format %(trailers) combining separator/key/keyonly/valueonly' '
856 git commit --allow-empty -F - <<-\EOF &&
857 Important fix
859 The fix is explained here
861 Closes: #1234
864 git commit --allow-empty -F - <<-\EOF &&
865 Another fix
867 The fix is explained here
869 Closes: #567
870 Closes: #890
873 git commit --allow-empty -F - <<-\EOF &&
874 Does not close any tickets
877 git log --pretty="%s% (trailers:separator=%x2c%x20,key=Closes,valueonly)" HEAD~3.. >actual &&
878 test_write_lines \
879 "Does not close any tickets" \
880 "Another fix #567, #890" \
881 "Important fix #1234" >expect &&
882 test_cmp expect actual &&
884 git log --pretty="%s% (trailers:separator=%x2c%x20,key=Closes,keyonly)" HEAD~3.. >actual &&
885 test_write_lines \
886 "Does not close any tickets" \
887 "Another fix Closes, Closes" \
888 "Important fix Closes" >expect &&
889 test_cmp expect actual
892 test_expect_success 'trailer parsing not fooled by --- line' '
893 git commit --allow-empty -F - <<-\EOF &&
894 this is the subject
896 This is the body. The message has a "---" line which would confuse a
897 message+patch parser. But here we know we have only a commit message,
898 so we get it right.
900 trailer: wrong
902 This is more body.
904 trailer: right
908 echo "trailer: right" &&
909 echo
910 } >expect &&
911 git log --no-walk --format="%(trailers)" >actual &&
912 test_cmp expect actual
915 test_expect_success 'set up %S tests' '
916 git checkout --orphan source-a &&
917 test_commit one &&
918 test_commit two &&
919 git checkout -b source-b HEAD^ &&
920 test_commit three
923 test_expect_success 'log --format=%S paints branch names' '
924 cat >expect <<-\EOF &&
925 source-b
926 source-a
927 source-b
929 git log --format=%S source-a source-b >actual &&
930 test_cmp expect actual
933 test_expect_success 'log --format=%S paints tag names' '
934 git tag -m tagged source-tag &&
935 cat >expect <<-\EOF &&
936 source-tag
937 source-a
938 source-tag
940 git log --format=%S source-tag source-a >actual &&
941 test_cmp expect actual
944 test_expect_success 'log --format=%S paints symmetric ranges' '
945 cat >expect <<-\EOF &&
946 source-b
947 source-a
949 git log --format=%S source-a...source-b >actual &&
950 test_cmp expect actual
953 test_expect_success '%S in git log --format works with other placeholders (part 1)' '
954 git log --format="source-b %h" source-b >expect &&
955 git log --format="%S %h" source-b >actual &&
956 test_cmp expect actual
959 test_expect_success '%S in git log --format works with other placeholders (part 2)' '
960 git log --format="%h source-b" source-b >expect &&
961 git log --format="%h %S" source-b >actual &&
962 test_cmp expect actual
965 test_expect_success 'setup more commits for %S with --bisect' '
966 test_commit four &&
967 test_commit five &&
969 head1=$(git rev-parse --verify HEAD~0) &&
970 head2=$(git rev-parse --verify HEAD~1) &&
971 head3=$(git rev-parse --verify HEAD~2) &&
972 head4=$(git rev-parse --verify HEAD~3)
975 test_expect_success '%S with --bisect labels commits with refs/bisect/bad ref' '
976 git update-ref refs/bisect/bad-$head1 $head1 &&
977 git update-ref refs/bisect/go $head1 &&
978 git update-ref refs/bisect/bad-$head2 $head2 &&
979 git update-ref refs/bisect/b $head3 &&
980 git update-ref refs/bisect/bad-$head4 $head4 &&
981 git update-ref refs/bisect/good-$head4 $head4 &&
983 # We expect to see the range of commits betwee refs/bisect/good-$head4
984 # and refs/bisect/bad-$head1. The "source" ref is the nearest bisect ref
985 # from which the commit is reachable.
986 cat >expect <<-EOF &&
987 $head1 refs/bisect/bad-$head1
988 $head2 refs/bisect/bad-$head2
989 $head3 refs/bisect/bad-$head2
991 git log --bisect --format="%H %S" >actual &&
992 test_cmp expect actual
995 test_expect_success 'log --pretty=reference' '
996 git log --pretty="tformat:%h (%s, %as)" >expect &&
997 git log --pretty=reference >actual &&
998 test_cmp expect actual
1001 test_expect_success 'log --pretty=reference with log.date is overridden by short date' '
1002 git log --pretty="tformat:%h (%s, %as)" >expect &&
1003 test_config log.date rfc &&
1004 git log --pretty=reference >actual &&
1005 test_cmp expect actual
1008 test_expect_success 'log --pretty=reference with explicit date overrides short date' '
1009 git log --date=rfc --pretty="tformat:%h (%s, %ad)" >expect &&
1010 git log --date=rfc --pretty=reference >actual &&
1011 test_cmp expect actual
1014 test_expect_success 'log --pretty=reference is never unabbreviated' '
1015 git log --pretty="tformat:%h (%s, %as)" >expect &&
1016 git log --no-abbrev-commit --pretty=reference >actual &&
1017 test_cmp expect actual
1020 test_expect_success 'log --pretty=reference is never decorated' '
1021 git log --pretty="tformat:%h (%s, %as)" >expect &&
1022 git log --decorate=short --pretty=reference >actual &&
1023 test_cmp expect actual
1026 test_expect_success 'log --pretty=reference does not output reflog info' '
1027 git log --walk-reflogs --pretty="tformat:%h (%s, %as)" >expect &&
1028 git log --walk-reflogs --pretty=reference >actual &&
1029 test_cmp expect actual
1032 test_expect_success 'log --pretty=reference is colored appropriately' '
1033 git log --color=always --pretty="tformat:%C(auto)%h (%s, %as)" >expect &&
1034 git log --color=always --pretty=reference >actual &&
1035 test_cmp expect actual
1038 test_expect_success '%(describe) vs git describe' '
1039 git log --format="%H" | while read hash
1041 if desc=$(git describe $hash)
1042 then
1043 : >expect-contains-good
1044 else
1045 : >expect-contains-bad
1046 fi &&
1047 echo "$hash $desc" || return 1
1048 done >expect &&
1049 test_path_exists expect-contains-good &&
1050 test_path_exists expect-contains-bad &&
1052 git log --format="%H %(describe)" >actual 2>err &&
1053 test_cmp expect actual &&
1054 test_must_be_empty err
1057 test_expect_success '%(describe:match=...) vs git describe --match ...' '
1058 test_when_finished "git tag -d tag-match" &&
1059 git tag -a -m tagged tag-match &&
1060 git describe --match "*-match" >expect &&
1061 git log -1 --format="%(describe:match=*-match)" >actual &&
1062 test_cmp expect actual
1065 test_expect_success '%(describe:exclude=...) vs git describe --exclude ...' '
1066 test_when_finished "git tag -d tag-exclude" &&
1067 git tag -a -m tagged tag-exclude &&
1068 git describe --exclude "*-exclude" >expect &&
1069 git log -1 --format="%(describe:exclude=*-exclude)" >actual &&
1070 test_cmp expect actual
1073 test_expect_success '%(describe:tags) vs git describe --tags' '
1074 test_when_finished "git tag -d tagname" &&
1075 git tag tagname &&
1076 git describe --tags >expect &&
1077 git log -1 --format="%(describe:tags)" >actual &&
1078 test_cmp expect actual
1081 test_expect_success '%(describe:abbrev=...) vs git describe --abbrev=...' '
1082 test_when_finished "git tag -d tagname" &&
1084 # Case 1: We have commits between HEAD and the most recent tag
1085 # reachable from it
1086 test_commit --no-tag file &&
1087 git describe --abbrev=15 >expect &&
1088 git log -1 --format="%(describe:abbrev=15)" >actual &&
1089 test_cmp expect actual &&
1091 # Make sure the hash used is at least 15 digits long
1092 sed -e "s/^.*-g\([0-9a-f]*\)$/\1/" <actual >hexpart &&
1093 test 16 -le $(wc -c <hexpart) &&
1095 # Case 2: We have a tag at HEAD, describe directly gives the
1096 # name of the tag
1097 git tag -a -m tagged tagname &&
1098 git describe --abbrev=15 >expect &&
1099 git log -1 --format="%(describe:abbrev=15)" >actual &&
1100 test_cmp expect actual &&
1101 test tagname = $(cat actual)
1104 test_expect_success 'log --pretty with space stealing' '
1105 printf mm0 >expect &&
1106 git log -1 --pretty="format:mm%>>|(1)%x30" >actual &&
1107 test_cmp expect actual
1110 test_expect_success 'log --pretty with invalid padding format' '
1111 printf "%s%%<(20" "$(git rev-parse HEAD)" >expect &&
1112 git log -1 --pretty="format:%H%<(20" >actual &&
1113 test_cmp expect actual
1116 test_expect_success 'log --pretty with magical wrapping directives' '
1117 commit_id=$(git commit-tree HEAD^{tree} -m "describe me") &&
1118 git tag describe-me $commit_id &&
1119 printf "\n(tag:\ndescribe-me)%%+w(2)" >expect &&
1120 git log -1 --pretty="format:%w(1)%+d%+w(2)" $commit_id >actual &&
1121 test_cmp expect actual
1124 test_expect_success SIZE_T_IS_64BIT 'log --pretty with overflowing wrapping directive' '
1125 printf "%%w(2147483649,1,1)0" >expect &&
1126 git log -1 --pretty="format:%w(2147483649,1,1)%x30" >actual &&
1127 test_cmp expect actual &&
1128 printf "%%w(1,2147483649,1)0" >expect &&
1129 git log -1 --pretty="format:%w(1,2147483649,1)%x30" >actual &&
1130 test_cmp expect actual &&
1131 printf "%%w(1,1,2147483649)0" >expect &&
1132 git log -1 --pretty="format:%w(1,1,2147483649)%x30" >actual &&
1133 test_cmp expect actual
1136 test_expect_success SIZE_T_IS_64BIT 'log --pretty with overflowing padding directive' '
1137 printf "%%<(2147483649)0" >expect &&
1138 git log -1 --pretty="format:%<(2147483649)%x30" >actual &&
1139 test_cmp expect actual
1142 test_expect_success 'log --pretty with padding and preceding control chars' '
1143 printf "\20\20 0" >expect &&
1144 git log -1 --pretty="format:%x10%x10%>|(4)%x30" >actual &&
1145 test_cmp expect actual
1148 test_expect_success 'log --pretty truncation with control chars' '
1149 test_commit "$(printf "\20\20\20\20xxxx")" file contents commit-with-control-chars &&
1150 printf "\20\20\20\20x.." >expect &&
1151 git log -1 --pretty="format:%<(3,trunc)%s" commit-with-control-chars >actual &&
1152 test_cmp expect actual
1155 test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'log --pretty with huge commit message' '
1156 # We only assert that this command does not crash. This needs to be
1157 # executed with the address sanitizer to demonstrate failure.
1158 git log -1 --pretty="format:%>(2147483646)%x41%41%>(2147483646)%x41" >/dev/null
1161 test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'set up huge commit' '
1162 test-tool genzeros 2147483649 | tr "\000" "1" >expect &&
1163 huge_commit=$(git commit-tree -F expect HEAD^{tree})
1166 test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'log --pretty with huge commit message' '
1167 git log -1 --format="%B%<(1)%x30" $huge_commit >actual &&
1168 echo 0 >>expect &&
1169 test_cmp expect actual
1172 test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'log --pretty with huge commit message does not cause allocation failure' '
1173 test_must_fail git log -1 --format="%<(1)%B" $huge_commit 2>error &&
1174 cat >expect <<-EOF &&
1175 fatal: number too large to represent as int on this platform: 2147483649
1177 test_cmp expect error
1180 # pretty-formats note wide char limitations, and add tests
1181 test_expect_failure 'wide and decomposed characters column counting' '
1183 # from t/lib-unicode-nfc-nfd.sh hex values converted to octal
1184 utf8_nfc=$(printf "\303\251") && # e acute combined.
1185 utf8_nfd=$(printf "\145\314\201") && # e with a combining acute (i.e. decomposed)
1186 utf8_emoji=$(printf "\360\237\221\250") &&
1188 # replacement character when requesting a wide char fits in a single display colum.
1189 # "half wide" alternative could be a plain ASCII dot `.`
1190 utf8_vert_ell=$(printf "\342\213\256") &&
1192 # use ${xxx} here!
1193 nfc10="${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}" &&
1194 nfd10="${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}" &&
1195 emoji5="${utf8_emoji}${utf8_emoji}${utf8_emoji}${utf8_emoji}${utf8_emoji}" &&
1196 # emoji5 uses 10 display columns
1198 test_commit "abcdefghij" &&
1199 test_commit --no-tag "${nfc10}" &&
1200 test_commit --no-tag "${nfd10}" &&
1201 test_commit --no-tag "${emoji5}" &&
1202 printf "${utf8_emoji}..${utf8_emoji}${utf8_vert_ell}\n${utf8_nfd}..${utf8_nfd}${utf8_nfd}\n${utf8_nfc}..${utf8_nfc}${utf8_nfc}\na..ij\n" >expected &&
1203 git log --format="%<(5,mtrunc)%s" -4 >actual &&
1204 test_cmp expected actual
1207 test_done