3 # Copyright (c) 2010, Will Palmer
4 # Copyright (c) 2011, Alexey Shumkin (+ non-UTF-8 commit encoding tests)
7 test_description
='Test pretty formats'
10 # Tested non-UTF-8 encoding
11 test_encoding
="ISO8859-1"
13 sample_utf8_part
=$
(printf "f\303\244ng")
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"
22 printf "$msg" |
iconv -f utf-8
-t "$1"
28 test_expect_success
'set up basic repos' '
33 git config i18n.commitEncoding $test_encoding &&
34 commit_msg $test_encoding | git commit -F - &&
37 git commit -m "add bar" &&
38 git config --unset i18n.commitEncoding
41 test_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
48 test_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
55 test_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
62 test_expect_success
'alias user-defined tformat with %s (ISO8859-1 encoding)' '
63 git config i18n.logOutputEncoding $test_encoding &&
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
70 test_expect_success
'alias user-defined tformat with %s (utf-8 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' '
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
83 test_expect_success
'alias non-existent format' '
84 git config pretty.test-alias format-that-will-never-exist &&
85 test_must_fail git log --pretty=test-alias
88 test_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
95 test_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
103 test_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
109 test_expect_success
'NUL separation' '
110 printf "add bar\0$(commit_msg)" >expected &&
111 git log -z --pretty="format:%s" >actual &&
112 test_cmp expected actual
115 test_expect_success
'NUL termination' '
116 printf "add bar\0$(commit_msg)\0" >expected &&
117 git log -z --pretty="tformat:%s" >actual &&
118 test_cmp expected actual
121 test_expect_success
'NUL separation with --stat' '
122 stat0_part=$(git diff --stat HEAD^ HEAD) &&
123 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
124 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected &&
125 git log -z --stat --pretty="format:%s" >actual &&
126 test_cmp expected actual
129 test_expect_failure
'NUL termination with --stat' '
130 stat0_part=$(git diff --stat HEAD^ HEAD) &&
131 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
132 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n0" >expected &&
133 git log -z --stat --pretty="tformat:%s" >actual &&
134 test_cmp expected actual
137 for p
in short medium full fuller email raw
139 test_expect_success
"NUL termination with --reflog --pretty=$p" '
140 revs="$(git rev-list --reflog)" &&
143 git show -s "$r" --pretty="$p" &&
144 printf "\0" || return 1
147 git log -z --reflog --pretty="$p" &&
150 test_cmp expect actual
154 test_expect_success
'NUL termination with --reflog --pretty=oneline' '
155 revs="$(git rev-list --reflog)" &&
158 git show -s --pretty=oneline "$r" >raw &&
159 cat raw | lf_to_nul || return 1
161 # the trailing NUL is already produced so we do not need to
163 git log -z --pretty=oneline --reflog >actual &&
164 test_cmp expect actual
167 test_expect_success
'setup more commits' '
168 test_commit "message one" one one message-one &&
169 test_commit "message two" two two message-two &&
170 head1=$(git rev-parse --verify --short HEAD~0) &&
171 head2=$(git rev-parse --verify --short HEAD~1) &&
172 head3=$(git rev-parse --verify --short HEAD~2) &&
173 head4=$(git rev-parse --verify --short HEAD~3)
176 test_expect_success
'left alignment formatting' '
177 git log --pretty="tformat:%<(40)%s" >actual &&
178 qz_to_tab_space <<-EOF >expected &&
184 test_cmp expected actual
187 test_expect_success
'left alignment formatting. i18n.logOutputEncoding' '
188 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(40)%s" >actual &&
189 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
195 test_cmp expected actual
198 test_expect_success
'left alignment formatting at the nth column' '
199 git log --pretty="tformat:%h %<|(40)%s" >actual &&
200 qz_to_tab_space <<-EOF >expected &&
204 $head4 $(commit_msg) Z
206 test_cmp expected actual
209 test_expect_success
'left alignment formatting at the nth column' '
210 COLUMNS=50 git log --pretty="tformat:%h %<|(-10)%s" >actual &&
211 qz_to_tab_space <<-EOF >expected &&
215 $head4 $(commit_msg) Z
217 test_cmp expected actual
220 test_expect_success
'left alignment formatting at the nth column. i18n.logOutputEncoding' '
221 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %<|(40)%s" >actual &&
222 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
226 $head4 $(commit_msg) Z
228 test_cmp expected actual
231 test_expect_success
'left alignment formatting with no padding' '
232 git log --pretty="tformat:%<(1)%s" >actual &&
233 cat <<-EOF >expected &&
239 test_cmp expected actual
242 test_expect_success
'left alignment formatting with no padding. i18n.logOutputEncoding' '
243 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(1)%s" >actual &&
244 cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
250 test_cmp expected actual
253 test_expect_success
'left alignment formatting with trunc' '
254 git log --pretty="tformat:%<(10,trunc)%s" >actual &&
255 qz_to_tab_space <<-\EOF >expected &&
261 test_cmp expected actual
264 test_expect_success
'left alignment formatting with trunc. i18n.logOutputEncoding' '
265 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s" >actual &&
266 qz_to_tab_space <<-\EOF | iconv -f utf-8 -t $test_encoding >expected &&
272 test_cmp expected actual
275 test_expect_success
'left alignment formatting with ltrunc' '
276 git log --pretty="tformat:%<(10,ltrunc)%s" >actual &&
277 qz_to_tab_space <<-EOF >expected &&
281 ..${sample_utf8_part}lich
283 test_cmp expected actual
286 test_expect_success
'left alignment formatting with ltrunc. i18n.logOutputEncoding' '
287 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,ltrunc)%s" >actual &&
288 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
292 ..${sample_utf8_part}lich
294 test_cmp expected actual
297 test_expect_success
'left alignment formatting with mtrunc' '
298 git log --pretty="tformat:%<(10,mtrunc)%s" >actual &&
299 qz_to_tab_space <<-\EOF >expected &&
305 test_cmp expected actual
308 test_expect_success
'left alignment formatting with mtrunc. i18n.logOutputEncoding' '
309 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,mtrunc)%s" >actual &&
310 qz_to_tab_space <<-\EOF | iconv -f utf-8 -t $test_encoding >expected &&
316 test_cmp expected actual
319 test_expect_success
'right alignment formatting' '
320 git log --pretty="tformat:%>(40)%s" >actual &&
321 qz_to_tab_space <<-EOF >expected &&
327 test_cmp expected actual
330 test_expect_success
'right alignment formatting. i18n.logOutputEncoding' '
331 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(40)%s" >actual &&
332 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
338 test_cmp expected actual
341 test_expect_success
'right alignment formatting at the nth column' '
342 git log --pretty="tformat:%h %>|(40)%s" >actual &&
343 qz_to_tab_space <<-EOF >expected &&
349 test_cmp expected actual
352 test_expect_success
'right alignment formatting at the nth column' '
353 COLUMNS=50 git log --pretty="tformat:%h %>|(-10)%s" >actual &&
354 qz_to_tab_space <<-EOF >expected &&
360 test_cmp expected actual
363 test_expect_success
'right alignment formatting at the nth column. i18n.logOutputEncoding' '
364 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %>|(40)%s" >actual &&
365 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
371 test_cmp expected actual
374 # Note: Space between 'message' and 'two' should be in the same column
375 # as in previous test.
376 test_expect_success
'right alignment formatting at the nth column with --graph. i18n.logOutputEncoding' '
377 git -c i18n.logOutputEncoding=$test_encoding log --graph --pretty="tformat:%h %>|(40)%s" >actual &&
378 iconv -f utf-8 -t $test_encoding >expected <<-EOF &&
382 * $head4 $(commit_msg)
384 test_cmp expected actual
387 test_expect_success
'right alignment formatting with no padding' '
388 git log --pretty="tformat:%>(1)%s" >actual &&
389 cat <<-EOF >expected &&
395 test_cmp expected actual
398 test_expect_success
'right alignment formatting with no padding and with --graph' '
399 git log --graph --pretty="tformat:%>(1)%s" >actual &&
400 cat <<-EOF >expected &&
406 test_cmp expected actual
409 test_expect_success
'right alignment formatting with no padding. i18n.logOutputEncoding' '
410 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(1)%s" >actual &&
411 cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
417 test_cmp expected actual
420 test_expect_success
'center alignment formatting' '
421 git log --pretty="tformat:%><(40)%s" >actual &&
422 qz_to_tab_space <<-EOF >expected &&
428 test_cmp expected actual
431 test_expect_success
'center alignment formatting. i18n.logOutputEncoding' '
432 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(40)%s" >actual &&
433 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
439 test_cmp expected actual
441 test_expect_success
'center alignment formatting at the nth column' '
442 git log --pretty="tformat:%h %><|(40)%s" >actual &&
443 qz_to_tab_space <<-EOF >expected &&
447 $head4 $(commit_msg) Z
449 test_cmp expected actual
452 test_expect_success
'center alignment formatting at the nth column' '
453 COLUMNS=70 git log --pretty="tformat:%h %><|(-30)%s" >actual &&
454 qz_to_tab_space <<-EOF >expected &&
458 $head4 $(commit_msg) Z
460 test_cmp expected actual
463 test_expect_success
'center alignment formatting at the nth column. i18n.logOutputEncoding' '
464 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %><|(40)%s" >actual &&
465 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
469 $head4 $(commit_msg) Z
471 test_cmp expected actual
474 test_expect_success
'center alignment formatting with no padding' '
475 git log --pretty="tformat:%><(1)%s" >actual &&
476 cat <<-EOF >expected &&
482 test_cmp expected actual
485 # save HEAD's SHA-1 digest (with no abbreviations) to use it below
486 # as far as the next test amends HEAD
487 old_head1
=$
(git rev-parse
--verify HEAD~
0)
488 test_expect_success
'center alignment formatting with no padding. i18n.logOutputEncoding' '
489 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(1)%s" >actual &&
490 cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
496 test_cmp expected actual
499 test_expect_success
'left/right alignment formatting with stealing' '
500 git commit --amend -m short --author "long long long <long@me.com>" &&
501 git log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
502 cat <<-\EOF >expected &&
508 test_cmp expected actual
510 test_expect_success
'left/right alignment formatting with stealing. i18n.logOutputEncoding' '
511 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
512 cat <<-\EOF | iconv -f utf-8 -t $test_encoding >expected &&
518 test_cmp expected actual
521 test_expect_success
'strbuf_utf8_replace() not producing NUL' '
522 git log --color --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)%C(auto)%d" |
528 # --date=[XXX] and corresponding %a[X] %c[X] format equivalency
529 test_expect_success
'--date=iso-strict %ad%cd is the same as %aI%cI' '
530 git log --format=%ad%n%cd --date=iso-strict >expected &&
531 git log --format=%aI%n%cI >actual &&
532 test_cmp expected actual
535 test_expect_success
'--date=short %ad%cd is the same as %as%cs' '
536 git log --format=%ad%n%cd --date=short >expected &&
537 git log --format=%as%n%cs >actual &&
538 test_cmp expected actual
541 test_expect_success
'--date=human %ad%cd is the same as %ah%ch' '
542 git log --format=%ad%n%cd --date=human >expected &&
543 git log --format=%ah%n%ch >actual &&
544 test_cmp expected actual
547 # get new digests (with no abbreviations)
548 test_expect_success
'set up log decoration tests' '
549 head1=$(git rev-parse --verify HEAD~0) &&
550 head2=$(git rev-parse --verify HEAD~1)
553 test_expect_success
'log decoration properly follows tag chain' '
554 git tag -a tag1 -m tag1 &&
555 git tag -a tag2 -m tag2 tag1 &&
557 git commit --amend -m shorter &&
558 git log --no-walk --tags --pretty="%H %d" --decorate=full >actual &&
559 cat <<-EOF >expected &&
560 $head2 (tag: refs/tags/message-one)
561 $old_head1 (tag: refs/tags/message-two)
562 $head1 (tag: refs/tags/tag2)
564 sort -k3 actual >actual1 &&
565 test_cmp expected actual1
568 test_expect_success
'clean log decoration' '
569 git log --no-walk --tags --pretty="%H %D" --decorate=full >actual &&
570 cat >expected <<-EOF &&
571 $head2 tag: refs/tags/message-one
572 $old_head1 tag: refs/tags/message-two
573 $head1 tag: refs/tags/tag2
575 sort -k3 actual >actual1 &&
576 test_cmp expected actual1
579 test_expect_success
'pretty format %decorate' '
580 git checkout -b foo &&
581 git commit --allow-empty -m "new commit" &&
585 echo " (HEAD -> foo, tag: bar, qux)" >expect1 &&
586 git log --format="%(decorate)" -1 >actual1 &&
587 test_cmp expect1 actual1 &&
589 echo "HEAD -> foo, tag: bar, qux" >expect2 &&
590 git log --format="%(decorate:prefix=,suffix=)" -1 >actual2 &&
591 test_cmp expect2 actual2 &&
593 echo "[ bar; qux; foo ]" >expect3 &&
594 git log --format="%(decorate:prefix=[ ,suffix= ],separator=%x3B ,tag=)" \
595 --decorate-refs=refs/ -1 >actual3 &&
596 test_cmp expect3 actual3 &&
598 # Try with a typo (in "separator"), in which case the placeholder should
600 echo "%(decorate:prefix=[ ,suffix= ],separater=; )" >expect4 &&
601 git log --format="%(decorate:prefix=[ ,suffix= ],separater=%x3B )" \
603 test_cmp expect4 actual4 &&
605 echo "HEAD->foo bar qux" >expect5 &&
606 git log --format="%(decorate:prefix=,suffix=,separator= ,tag=,pointer=->)" \
608 test_cmp expect5 actual5
612 Signed-off-by: A U Thor <author@example.com>
613 Acked-by: A U Thor <author@example.com>
614 [ v2 updated patch description ]
615 Signed-off-by: A U Thor
620 perl
-0pe 's/\n\s+/ /g'
623 test_expect_success
'set up trailer tests' '
624 echo "Some contents" >trailerfile &&
625 git add trailerfile &&
626 git commit -F - <<-EOF
627 trailers: this commit message has trailers
629 This commit is a test commit with trailers at the end. We parse this
630 message and display the trailers using %(trailers).
636 test_expect_success
'pretty format %(trailers) shows trailers' '
637 git log --no-walk --pretty="%(trailers)" >actual &&
642 test_cmp expect actual
645 test_expect_success
'pretty format %(trailers:) enables no options' '
646 git log --no-walk --pretty="%(trailers:)" >actual &&
647 # "expect" the same as the test above
648 test_cmp expect actual
651 test_expect_success
'%(trailers:only) shows only "key: value" trailers' '
652 git log --no-walk --pretty="%(trailers:only)" >actual &&
654 grep -v patch.description <trailers &&
657 test_cmp expect actual
660 test_expect_success
'%(trailers:only=yes) shows only "key: value" trailers' '
661 git log --no-walk --pretty=format:"%(trailers:only=yes)" >actual &&
662 grep -v patch.description <trailers >expect &&
663 test_cmp expect actual
666 test_expect_success
'%(trailers:only=no) shows all trailers' '
667 git log --no-walk --pretty=format:"%(trailers:only=no)" >actual &&
668 cat trailers >expect &&
669 test_cmp expect actual
672 test_expect_success
'%(trailers:only=no,only=true) shows only "key: value" trailers' '
673 git log --no-walk --pretty=format:"%(trailers:only=yes)" >actual &&
674 grep -v patch.description <trailers >expect &&
675 test_cmp expect actual
678 test_expect_success
'%(trailers:unfold) unfolds trailers' '
679 git log --no-walk --pretty="%(trailers:unfold)" >actual &&
684 test_cmp expect actual
687 test_expect_success
':only and :unfold work together' '
688 git log --no-walk --pretty="%(trailers:only,unfold)" >actual &&
689 git log --no-walk --pretty="%(trailers:unfold,only)" >reverse &&
690 test_cmp actual reverse &&
692 grep -v patch.description <trailers | unfold &&
695 test_cmp expect actual
698 test_expect_success
'pretty format %(trailers:key=foo) shows that trailer' '
699 git log --no-walk --pretty="format:%(trailers:key=Acked-by)" >actual &&
700 echo "Acked-by: A U Thor <author@example.com>" >expect &&
701 test_cmp expect actual
704 test_expect_success
'pretty format %(trailers:key=foo) is case insensitive' '
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:) trailing colon also works' '
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) multiple keys' '
717 git log --no-walk --pretty="format:%(trailers:key=Acked-by:,key=Signed-off-By)" >actual &&
718 grep -v patch.description <trailers >expect &&
719 test_cmp expect actual
722 test_expect_success
'%(trailers:key=nonexistent) becomes empty' '
723 git log --no-walk --pretty="x%(trailers:key=Nacked-by)x" >actual &&
725 test_cmp expect actual
728 test_expect_success
'%(trailers:key=foo) handles multiple lines even if folded' '
729 git log --no-walk --pretty="format:%(trailers:key=Signed-Off-by)" >actual &&
730 grep -v patch.description <trailers | grep -v Acked-by >expect &&
731 test_cmp expect actual
734 test_expect_success
'%(trailers:key=foo,unfold) properly unfolds' '
735 git log --no-walk --pretty="format:%(trailers:key=Signed-Off-by,unfold)" >actual &&
736 unfold <trailers | grep Signed-off-by >expect &&
737 test_cmp expect actual
740 test_expect_success
'pretty format %(trailers:key=foo,only=no) also includes nontrailer lines' '
741 git log --no-walk --pretty="format:%(trailers:key=Acked-by,only=no)" >actual &&
743 echo "Acked-by: A U Thor <author@example.com>" &&
744 grep patch.description <trailers
746 test_cmp expect actual
749 test_expect_success
'%(trailers:key) without value is error' '
750 git log --no-walk --pretty="tformat:%(trailers:key)" >actual &&
751 echo "%(trailers:key)" >expect &&
752 test_cmp expect actual
755 test_expect_success
'%(trailers:keyonly) shows only keys' '
756 git log --no-walk --pretty="format:%(trailers:keyonly)" >actual &&
760 "[ v2 updated patch description ]" \
761 "Signed-off-by" >expect &&
762 test_cmp expect actual
765 test_expect_success
'%(trailers:key=foo,keyonly) shows only key' '
766 git log --no-walk --pretty="format:%(trailers:key=Acked-by,keyonly)" >actual &&
767 echo "Acked-by" >expect &&
768 test_cmp expect actual
771 test_expect_success
'%(trailers:key=foo,valueonly) shows only value' '
772 git log --no-walk --pretty="format:%(trailers:key=Acked-by,valueonly)" >actual &&
773 echo "A U Thor <author@example.com>" >expect &&
774 test_cmp expect actual
777 test_expect_success
'%(trailers:valueonly) shows only values' '
778 git log --no-walk --pretty="format:%(trailers:valueonly)" >actual &&
780 "A U Thor <author@example.com>" \
781 "A U Thor <author@example.com>" \
782 "[ v2 updated patch description ]" \
784 " <author@example.com>" >expect &&
785 test_cmp expect actual
788 test_expect_success
'%(trailers:key=foo,keyonly,valueonly) shows nothing' '
789 git log --no-walk --pretty="format:%(trailers:key=Acked-by,keyonly,valueonly)" >actual &&
791 test_cmp expect actual
794 test_expect_success
'pretty format %(trailers:separator) changes separator' '
795 git log --no-walk --pretty=format:"X%(trailers:separator=%x00)X" >actual &&
797 printf "XSigned-off-by: A U Thor <author@example.com>\0" &&
798 printf "Acked-by: A U Thor <author@example.com>\0" &&
799 printf "[ v2 updated patch description ]\0" &&
800 printf "Signed-off-by: A U Thor\n <author@example.com>X"
802 test_cmp expect actual
805 test_expect_success
'pretty format %(trailers:separator=X,unfold) changes separator' '
806 git log --no-walk --pretty=format:"X%(trailers:separator=%x00,unfold)X" >actual &&
808 printf "XSigned-off-by: A U Thor <author@example.com>\0" &&
809 printf "Acked-by: A U Thor <author@example.com>\0" &&
810 printf "[ v2 updated patch description ]\0" &&
811 printf "Signed-off-by: A U Thor <author@example.com>X"
813 test_cmp expect actual
816 test_expect_success
'pretty format %(trailers:key_value_separator) changes key-value separator' '
817 git log --no-walk --pretty=format:"X%(trailers:key_value_separator=%x00)X" >actual &&
819 printf "XSigned-off-by\0A U Thor <author@example.com>\n" &&
820 printf "Acked-by\0A U Thor <author@example.com>\n" &&
821 printf "[ v2 updated patch description ]\n" &&
822 printf "Signed-off-by\0A U Thor\n <author@example.com>\nX"
824 test_cmp expect actual
827 test_expect_success
'pretty format %(trailers:key_value_separator,unfold) changes key-value separator' '
828 git log --no-walk --pretty=format:"X%(trailers:key_value_separator=%x00,unfold)X" >actual &&
830 printf "XSigned-off-by\0A U Thor <author@example.com>\n" &&
831 printf "Acked-by\0A U Thor <author@example.com>\n" &&
832 printf "[ v2 updated patch description ]\n" &&
833 printf "Signed-off-by\0A U Thor <author@example.com>\nX"
835 test_cmp expect actual
838 test_expect_success
'pretty format %(trailers:separator,key_value_separator) changes both separators' '
839 git log --no-walk --pretty=format:"%(trailers:separator=%x00,key_value_separator=%x00%x00,unfold)" >actual &&
841 printf "Signed-off-by\0\0A U Thor <author@example.com>\0" &&
842 printf "Acked-by\0\0A U Thor <author@example.com>\0" &&
843 printf "[ v2 updated patch description ]\0" &&
844 printf "Signed-off-by\0\0A U Thor <author@example.com>"
846 test_cmp expect actual
849 test_expect_success
'pretty format %(trailers) combining separator/key/keyonly/valueonly' '
850 git commit --allow-empty -F - <<-\EOF &&
853 The fix is explained here
858 git commit --allow-empty -F - <<-\EOF &&
861 The fix is explained here
867 git commit --allow-empty -F - <<-\EOF &&
868 Does not close any tickets
871 git log --pretty="%s% (trailers:separator=%x2c%x20,key=Closes,valueonly)" HEAD~3.. >actual &&
873 "Does not close any tickets" \
874 "Another fix #567, #890" \
875 "Important fix #1234" >expect &&
876 test_cmp expect actual &&
878 git log --pretty="%s% (trailers:separator=%x2c%x20,key=Closes,keyonly)" HEAD~3.. >actual &&
880 "Does not close any tickets" \
881 "Another fix Closes, Closes" \
882 "Important fix Closes" >expect &&
883 test_cmp expect actual
886 test_expect_success
'trailer parsing not fooled by --- line' '
887 git commit --allow-empty -F - <<-\EOF &&
890 This is the body. The message has a "---" line which would confuse a
891 message+patch parser. But here we know we have only a commit message,
902 echo "trailer: right" &&
905 git log --no-walk --format="%(trailers)" >actual &&
906 test_cmp expect actual
909 test_expect_success
'set up %S tests' '
910 git checkout --orphan source-a &&
913 git checkout -b source-b HEAD^ &&
917 test_expect_success
'log --format=%S paints branch names' '
918 cat >expect <<-\EOF &&
923 git log --format=%S source-a source-b >actual &&
924 test_cmp expect actual
927 test_expect_success
'log --format=%S paints tag names' '
928 git tag -m tagged source-tag &&
929 cat >expect <<-\EOF &&
934 git log --format=%S source-tag source-a >actual &&
935 test_cmp expect actual
938 test_expect_success
'log --format=%S paints symmetric ranges' '
939 cat >expect <<-\EOF &&
943 git log --format=%S source-a...source-b >actual &&
944 test_cmp expect actual
947 test_expect_success
'%S in git log --format works with other placeholders (part 1)' '
948 git log --format="source-b %h" source-b >expect &&
949 git log --format="%S %h" source-b >actual &&
950 test_cmp expect actual
953 test_expect_success
'%S in git log --format works with other placeholders (part 2)' '
954 git log --format="%h source-b" source-b >expect &&
955 git log --format="%h %S" source-b >actual &&
956 test_cmp expect actual
959 test_expect_success
'setup more commits for %S with --bisect' '
963 head1=$(git rev-parse --verify HEAD~0) &&
964 head2=$(git rev-parse --verify HEAD~1) &&
965 head3=$(git rev-parse --verify HEAD~2) &&
966 head4=$(git rev-parse --verify HEAD~3)
969 test_expect_success
'%S with --bisect labels commits with refs/bisect/bad ref' '
970 git update-ref refs/bisect/bad-$head1 $head1 &&
971 git update-ref refs/bisect/go $head1 &&
972 git update-ref refs/bisect/bad-$head2 $head2 &&
973 git update-ref refs/bisect/b $head3 &&
974 git update-ref refs/bisect/bad-$head4 $head4 &&
975 git update-ref refs/bisect/good-$head4 $head4 &&
977 # We expect to see the range of commits betwee refs/bisect/good-$head4
978 # and refs/bisect/bad-$head1. The "source" ref is the nearest bisect ref
979 # from which the commit is reachable.
980 cat >expect <<-EOF &&
981 $head1 refs/bisect/bad-$head1
982 $head2 refs/bisect/bad-$head2
983 $head3 refs/bisect/bad-$head2
985 git log --bisect --format="%H %S" >actual &&
986 test_cmp expect actual
989 test_expect_success
'log --pretty=reference' '
990 git log --pretty="tformat:%h (%s, %as)" >expect &&
991 git log --pretty=reference >actual &&
992 test_cmp expect actual
995 test_expect_success
'log --pretty=reference with log.date is overridden by short date' '
996 git log --pretty="tformat:%h (%s, %as)" >expect &&
997 test_config log.date rfc &&
998 git log --pretty=reference >actual &&
999 test_cmp expect actual
1002 test_expect_success
'log --pretty=reference with explicit date overrides short date' '
1003 git log --date=rfc --pretty="tformat:%h (%s, %ad)" >expect &&
1004 git log --date=rfc --pretty=reference >actual &&
1005 test_cmp expect actual
1008 test_expect_success
'log --pretty=reference is never unabbreviated' '
1009 git log --pretty="tformat:%h (%s, %as)" >expect &&
1010 git log --no-abbrev-commit --pretty=reference >actual &&
1011 test_cmp expect actual
1014 test_expect_success
'log --pretty=reference is never decorated' '
1015 git log --pretty="tformat:%h (%s, %as)" >expect &&
1016 git log --decorate=short --pretty=reference >actual &&
1017 test_cmp expect actual
1020 test_expect_success
'log --pretty=reference does not output reflog info' '
1021 git log --walk-reflogs --pretty="tformat:%h (%s, %as)" >expect &&
1022 git log --walk-reflogs --pretty=reference >actual &&
1023 test_cmp expect actual
1026 test_expect_success
'log --pretty=reference is colored appropriately' '
1027 git log --color=always --pretty="tformat:%C(auto)%h (%s, %as)" >expect &&
1028 git log --color=always --pretty=reference >actual &&
1029 test_cmp expect actual
1032 test_expect_success
'%(describe) vs git describe' '
1033 git log --format="%H" | while read hash
1035 if desc=$(git describe $hash)
1037 : >expect-contains-good
1039 : >expect-contains-bad
1041 echo "$hash $desc" || return 1
1043 test_path_exists expect-contains-good &&
1044 test_path_exists expect-contains-bad &&
1046 git log --format="%H %(describe)" >actual 2>err &&
1047 test_cmp expect actual &&
1048 test_must_be_empty err
1051 test_expect_success
'%(describe:match=...) vs git describe --match ...' '
1052 test_when_finished "git tag -d tag-match" &&
1053 git tag -a -m tagged tag-match &&
1054 git describe --match "*-match" >expect &&
1055 git log -1 --format="%(describe:match=*-match)" >actual &&
1056 test_cmp expect actual
1059 test_expect_success
'%(describe:exclude=...) vs git describe --exclude ...' '
1060 test_when_finished "git tag -d tag-exclude" &&
1061 git tag -a -m tagged tag-exclude &&
1062 git describe --exclude "*-exclude" >expect &&
1063 git log -1 --format="%(describe:exclude=*-exclude)" >actual &&
1064 test_cmp expect actual
1067 test_expect_success
'%(describe:tags) vs git describe --tags' '
1068 test_when_finished "git tag -d tagname" &&
1070 git describe --tags >expect &&
1071 git log -1 --format="%(describe:tags)" >actual &&
1072 test_cmp expect actual
1075 test_expect_success
'%(describe:abbrev=...) vs git describe --abbrev=...' '
1076 test_when_finished "git tag -d tagname" &&
1078 # Case 1: We have commits between HEAD and the most recent tag
1080 test_commit --no-tag file &&
1081 git describe --abbrev=15 >expect &&
1082 git log -1 --format="%(describe:abbrev=15)" >actual &&
1083 test_cmp expect actual &&
1085 # Make sure the hash used is at least 15 digits long
1086 sed -e "s/^.*-g\([0-9a-f]*\)$/\1/" <actual >hexpart &&
1087 test 16 -le $(wc -c <hexpart) &&
1089 # Case 2: We have a tag at HEAD, describe directly gives the
1091 git tag -a -m tagged tagname &&
1092 git describe --abbrev=15 >expect &&
1093 git log -1 --format="%(describe:abbrev=15)" >actual &&
1094 test_cmp expect actual &&
1095 test tagname = $(cat actual)
1098 test_expect_success
'log --pretty with space stealing' '
1099 printf mm0 >expect &&
1100 git log -1 --pretty="format:mm%>>|(1)%x30" >actual &&
1101 test_cmp expect actual
1104 test_expect_success
'log --pretty with invalid padding format' '
1105 printf "%s%%<(20" "$(git rev-parse HEAD)" >expect &&
1106 git log -1 --pretty="format:%H%<(20" >actual &&
1107 test_cmp expect actual
1110 test_expect_success
'log --pretty with magical wrapping directives' '
1111 commit_id=$(git commit-tree HEAD^{tree} -m "describe me") &&
1112 git tag describe-me $commit_id &&
1113 printf "\n(tag:\ndescribe-me)%%+w(2)" >expect &&
1114 git log -1 --pretty="format:%w(1)%+d%+w(2)" $commit_id >actual &&
1115 test_cmp expect actual
1118 test_expect_success SIZE_T_IS_64BIT
'log --pretty with overflowing wrapping directive' '
1119 printf "%%w(2147483649,1,1)0" >expect &&
1120 git log -1 --pretty="format:%w(2147483649,1,1)%x30" >actual &&
1121 test_cmp expect actual &&
1122 printf "%%w(1,2147483649,1)0" >expect &&
1123 git log -1 --pretty="format:%w(1,2147483649,1)%x30" >actual &&
1124 test_cmp expect actual &&
1125 printf "%%w(1,1,2147483649)0" >expect &&
1126 git log -1 --pretty="format:%w(1,1,2147483649)%x30" >actual &&
1127 test_cmp expect actual
1130 test_expect_success SIZE_T_IS_64BIT
'log --pretty with overflowing padding directive' '
1131 printf "%%<(2147483649)0" >expect &&
1132 git log -1 --pretty="format:%<(2147483649)%x30" >actual &&
1133 test_cmp expect actual
1136 test_expect_success
'log --pretty with padding and preceding control chars' '
1137 printf "\20\20 0" >expect &&
1138 git log -1 --pretty="format:%x10%x10%>|(4)%x30" >actual &&
1139 test_cmp expect actual
1142 test_expect_success
'log --pretty truncation with control chars' '
1143 test_commit "$(printf "\20\20\20\20xxxx")" file contents commit-with-control-chars &&
1144 printf "\20\20\20\20x.." >expect &&
1145 git log -1 --pretty="format:%<(3,trunc)%s" commit-with-control-chars >actual &&
1146 test_cmp expect actual
1149 test_expect_success EXPENSIVE
,SIZE_T_IS_64BIT
'log --pretty with huge commit message' '
1150 # We only assert that this command does not crash. This needs to be
1151 # executed with the address sanitizer to demonstrate failure.
1152 git log -1 --pretty="format:%>(2147483646)%x41%41%>(2147483646)%x41" >/dev/null
1155 test_expect_success EXPENSIVE
,SIZE_T_IS_64BIT
'set up huge commit' '
1156 test-tool genzeros 2147483649 | tr "\000" "1" >expect &&
1157 huge_commit=$(git commit-tree -F expect HEAD^{tree})
1160 test_expect_success EXPENSIVE
,SIZE_T_IS_64BIT
'log --pretty with huge commit message' '
1161 git log -1 --format="%B%<(1)%x30" $huge_commit >actual &&
1163 test_cmp expect actual
1166 test_expect_success EXPENSIVE
,SIZE_T_IS_64BIT
'log --pretty with huge commit message does not cause allocation failure' '
1167 test_must_fail git log -1 --format="%<(1)%B" $huge_commit 2>error &&
1168 cat >expect <<-EOF &&
1169 fatal: number too large to represent as int on this platform: 2147483649
1171 test_cmp expect error
1174 # pretty-formats note wide char limitations, and add tests
1175 test_expect_failure
'wide and decomposed characters column counting' '
1177 # from t/lib-unicode-nfc-nfd.sh hex values converted to octal
1178 utf8_nfc=$(printf "\303\251") && # e acute combined.
1179 utf8_nfd=$(printf "\145\314\201") && # e with a combining acute (i.e. decomposed)
1180 utf8_emoji=$(printf "\360\237\221\250") &&
1182 # replacement character when requesting a wide char fits in a single display colum.
1183 # "half wide" alternative could be a plain ASCII dot `.`
1184 utf8_vert_ell=$(printf "\342\213\256") &&
1187 nfc10="${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}" &&
1188 nfd10="${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}" &&
1189 emoji5="${utf8_emoji}${utf8_emoji}${utf8_emoji}${utf8_emoji}${utf8_emoji}" &&
1190 # emoji5 uses 10 display columns
1192 test_commit "abcdefghij" &&
1193 test_commit --no-tag "${nfc10}" &&
1194 test_commit --no-tag "${nfd10}" &&
1195 test_commit --no-tag "${emoji5}" &&
1196 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 &&
1197 git log --format="%<(5,mtrunc)%s" -4 >actual &&
1198 test_cmp expected actual