Git fork
at reftables-rust 1224 lines 39 kB view raw
1#!/bin/sh 2# 3# Copyright (c) 2010, Will Palmer 4# Copyright (c) 2011, Alexey Shumkin (+ non-UTF-8 commit encoding tests) 5# 6 7test_description='Test pretty formats' 8 9. ./test-lib.sh 10 11# Tested non-UTF-8 encoding 12test_encoding="ISO8859-1" 13 14sample_utf8_part=$(printf "f\303\244ng") 15 16commit_msg () { 17 # String "initial. initial" partly in German 18 # (translated with Google Translate), 19 # encoded in UTF-8, used as a commit log message below. 20 msg="initial. an${sample_utf8_part}lich\n" 21 if test -n "$1" 22 then 23 printf "$msg" | iconv -f utf-8 -t "$1" 24 else 25 printf "$msg" 26 fi 27} 28 29test_expect_success 'set up basic repos' ' 30 >foo && 31 >bar && 32 git add foo && 33 test_tick && 34 test_config i18n.commitEncoding $test_encoding && 35 commit_msg $test_encoding | git commit -F - && 36 git add bar && 37 test_tick && 38 git commit -m "add bar" 39' 40 41test_expect_success 'alias builtin format' ' 42 git log --pretty=oneline >expected && 43 test_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 test_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 test_config pretty.test-alias "format:%h" && 58 git log --pretty=test-alias >actual && 59 test_cmp expected actual 60' 61 62test_expect_success 'alias user-defined format is matched case-insensitively' ' 63 git log --pretty="format:%h" >expected && 64 test_config pretty.testone "format:%h" && 65 test_config pretty.testtwo testOne && 66 git log --pretty=testTwo >actual && 67 test_cmp expected actual 68' 69 70test_expect_success 'alias user-defined tformat with %s (ISO8859-1 encoding)' ' 71 test_config i18n.logOutputEncoding $test_encoding && 72 git log --oneline >expected-s && 73 git log --pretty="tformat:%h %s" >actual-s && 74 test_cmp expected-s actual-s 75' 76 77test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' ' 78 git log --oneline >expected-s && 79 git log --pretty="tformat:%h %s" >actual-s && 80 test_cmp expected-s actual-s 81' 82 83test_expect_success 'alias user-defined tformat' ' 84 git log --pretty="tformat:%h" >expected && 85 test_config pretty.test-alias "tformat:%h" && 86 git log --pretty=test-alias >actual && 87 test_cmp expected actual 88' 89 90test_expect_success 'alias non-existent format' ' 91 test_config pretty.test-alias format-that-will-never-exist && 92 test_must_fail git log --pretty=test-alias 93' 94 95test_expect_success 'alias of an alias' ' 96 git log --pretty="tformat:%h" >expected && 97 test_config pretty.test-foo "tformat:%h" && 98 test_config pretty.test-bar test-foo && 99 git log --pretty=test-bar >actual && test_cmp expected actual 100' 101 102test_expect_success 'alias masking an alias' ' 103 git log --pretty=format:"Two %H" >expected && 104 test_config pretty.duplicate "format:One %H" && 105 test_config pretty.duplicate "format:Two %H" --add && 106 git log --pretty=duplicate >actual && 107 test_cmp expected actual 108' 109 110test_expect_success 'alias loop' ' 111 test_config pretty.test-foo test-bar && 112 test_config pretty.test-bar test-foo && 113 test_must_fail git log --pretty=test-foo 114' 115 116test_expect_success ICONV 'NUL separation' ' 117 printf "add bar\0$(commit_msg)" >expected && 118 git log -z --pretty="format:%s" >actual && 119 test_cmp expected actual 120' 121 122test_expect_success ICONV 'NUL termination' ' 123 printf "add bar\0$(commit_msg)\0" >expected && 124 git log -z --pretty="tformat:%s" >actual && 125 test_cmp expected actual 126' 127 128test_expect_success ICONV 'NUL separation with --stat' ' 129 stat0_part=$(git diff --stat HEAD^ HEAD) && 130 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) && 131 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected && 132 git log -z --stat --pretty="format:%s" >actual && 133 test_cmp expected actual 134' 135 136test_expect_failure 'NUL termination with --stat' ' 137 stat0_part=$(git diff --stat HEAD^ HEAD) && 138 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) && 139 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n\0" >expected && 140 git log -z --stat --pretty="tformat:%s" >actual && 141 test_cmp expected actual 142' 143 144for p in short medium full fuller email raw 145do 146 test_expect_success "NUL termination with --reflog --pretty=$p" ' 147 revs="$(git rev-list --reflog)" && 148 for r in $revs 149 do 150 git show -s "$r" --pretty="$p" && 151 printf "\0" || return 1 152 done >expect && 153 { 154 git log -z --reflog --pretty="$p" && 155 printf "\0" 156 } >actual && 157 test_cmp expect actual 158 ' 159done 160 161test_expect_success 'NUL termination with --reflog --pretty=oneline' ' 162 revs="$(git rev-list --reflog)" && 163 for r in $revs 164 do 165 git show -s --pretty=oneline "$r" >raw && 166 lf_to_nul <raw || return 1 167 done >expect && 168 # the trailing NUL is already produced so we do not need to 169 # output another one 170 git log -z --pretty=oneline --reflog >actual && 171 test_cmp expect actual 172' 173 174test_expect_success 'setup more commits' ' 175 test_commit "message one" one one message-one && 176 test_commit "message two" two two message-two && 177 head1=$(git rev-parse --verify --short HEAD~0) && 178 head2=$(git rev-parse --verify --short HEAD~1) && 179 head3=$(git rev-parse --verify --short HEAD~2) && 180 head4=$(git rev-parse --verify --short HEAD~3) 181' 182 183test_expect_success ICONV 'left alignment formatting' ' 184 git log --pretty="tformat:%<(40)%s" >actual && 185 qz_to_tab_space <<-EOF >expected && 186 message two Z 187 message one Z 188 add bar Z 189 $(commit_msg) Z 190 EOF 191 test_cmp expected actual 192' 193 194test_expect_success ICONV 'left alignment formatting. i18n.logOutputEncoding' ' 195 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(40)%s" >actual && 196 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected && 197 message two Z 198 message one Z 199 add bar Z 200 $(commit_msg) Z 201 EOF 202 test_cmp expected actual 203' 204 205test_expect_success ICONV 'left alignment formatting at the nth column' ' 206 git log --pretty="tformat:%h %<|(40)%s" >actual && 207 qz_to_tab_space <<-EOF >expected && 208 $head1 message two Z 209 $head2 message one Z 210 $head3 add bar Z 211 $head4 $(commit_msg) Z 212 EOF 213 test_cmp expected actual 214' 215 216test_expect_success ICONV 'left alignment formatting at the nth column' ' 217 COLUMNS=50 git log --pretty="tformat:%h %<|(-10)%s" >actual && 218 qz_to_tab_space <<-EOF >expected && 219 $head1 message two Z 220 $head2 message one Z 221 $head3 add bar Z 222 $head4 $(commit_msg) Z 223 EOF 224 test_cmp expected actual 225' 226 227test_expect_success ICONV 'left alignment formatting at the nth column. i18n.logOutputEncoding' ' 228 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %<|(40)%s" >actual && 229 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected && 230 $head1 message two Z 231 $head2 message one Z 232 $head3 add bar Z 233 $head4 $(commit_msg) Z 234 EOF 235 test_cmp expected actual 236' 237 238test_expect_success ICONV 'left alignment formatting with no padding' ' 239 git log --pretty="tformat:%<(1)%s" >actual && 240 cat <<-EOF >expected && 241 message two 242 message one 243 add bar 244 $(commit_msg) 245 EOF 246 test_cmp expected actual 247' 248 249test_expect_success 'left alignment formatting with no padding. i18n.logOutputEncoding' ' 250 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(1)%s" >actual && 251 cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected && 252 message two 253 message one 254 add bar 255 $(commit_msg) 256 EOF 257 test_cmp expected actual 258' 259 260test_expect_success ICONV 'left alignment formatting with trunc' ' 261 git log --pretty="tformat:%<(10,trunc)%s" >actual && 262 qz_to_tab_space <<-\EOF >expected && 263 message .. 264 message .. 265 add bar Z 266 initial... 267 EOF 268 test_cmp expected actual 269' 270 271test_expect_success ICONV 'left alignment formatting with trunc. i18n.logOutputEncoding' ' 272 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s" >actual && 273 qz_to_tab_space <<-\EOF | iconv -f utf-8 -t $test_encoding >expected && 274 message .. 275 message .. 276 add bar Z 277 initial... 278 EOF 279 test_cmp expected actual 280' 281 282test_expect_success ICONV 'left alignment formatting with ltrunc' ' 283 git log --pretty="tformat:%<(10,ltrunc)%s" >actual && 284 qz_to_tab_space <<-EOF >expected && 285 ..sage two 286 ..sage one 287 add bar Z 288 ..${sample_utf8_part}lich 289 EOF 290 test_cmp expected actual 291' 292 293test_expect_success ICONV 'left alignment formatting with ltrunc. i18n.logOutputEncoding' ' 294 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,ltrunc)%s" >actual && 295 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected && 296 ..sage two 297 ..sage one 298 add bar Z 299 ..${sample_utf8_part}lich 300 EOF 301 test_cmp expected actual 302' 303 304test_expect_success ICONV 'left alignment formatting with mtrunc' ' 305 git log --pretty="tformat:%<(10,mtrunc)%s" >actual && 306 qz_to_tab_space <<-\EOF >expected && 307 mess.. two 308 mess.. one 309 add bar Z 310 init..lich 311 EOF 312 test_cmp expected actual 313' 314 315test_expect_success ICONV 'left alignment formatting with mtrunc. i18n.logOutputEncoding' ' 316 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,mtrunc)%s" >actual && 317 qz_to_tab_space <<-\EOF | iconv -f utf-8 -t $test_encoding >expected && 318 mess.. two 319 mess.. one 320 add bar Z 321 init..lich 322 EOF 323 test_cmp expected actual 324' 325 326test_expect_success ICONV 'right alignment formatting' ' 327 git log --pretty="tformat:%>(40)%s" >actual && 328 qz_to_tab_space <<-EOF >expected && 329 Z message two 330 Z message one 331 Z add bar 332 Z $(commit_msg) 333 EOF 334 test_cmp expected actual 335' 336 337test_expect_success ICONV 'right alignment formatting. i18n.logOutputEncoding' ' 338 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(40)%s" >actual && 339 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected && 340 Z message two 341 Z message one 342 Z add bar 343 Z $(commit_msg) 344 EOF 345 test_cmp expected actual 346' 347 348test_expect_success ICONV 'right alignment formatting at the nth column' ' 349 git log --pretty="tformat:%h %>|(40)%s" >actual && 350 qz_to_tab_space <<-EOF >expected && 351 $head1 message two 352 $head2 message one 353 $head3 add bar 354 $head4 $(commit_msg) 355 EOF 356 test_cmp expected actual 357' 358 359test_expect_success ICONV 'right alignment formatting at the nth column' ' 360 COLUMNS=50 git log --pretty="tformat:%h %>|(-10)%s" >actual && 361 qz_to_tab_space <<-EOF >expected && 362 $head1 message two 363 $head2 message one 364 $head3 add bar 365 $head4 $(commit_msg) 366 EOF 367 test_cmp expected actual 368' 369 370test_expect_success ICONV 'right alignment formatting at the nth column. i18n.logOutputEncoding' ' 371 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %>|(40)%s" >actual && 372 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected && 373 $head1 message two 374 $head2 message one 375 $head3 add bar 376 $head4 $(commit_msg) 377 EOF 378 test_cmp expected actual 379' 380 381# Note: Space between 'message' and 'two' should be in the same column 382# as in previous test. 383test_expect_success ICONV 'right alignment formatting at the nth column with --graph. i18n.logOutputEncoding' ' 384 git -c i18n.logOutputEncoding=$test_encoding log --graph --pretty="tformat:%h %>|(40)%s" >actual && 385 iconv -f utf-8 -t $test_encoding >expected <<-EOF && 386 * $head1 message two 387 * $head2 message one 388 * $head3 add bar 389 * $head4 $(commit_msg) 390 EOF 391 test_cmp expected actual 392' 393 394test_expect_success ICONV 'right alignment formatting with no padding' ' 395 git log --pretty="tformat:%>(1)%s" >actual && 396 cat <<-EOF >expected && 397 message two 398 message one 399 add bar 400 $(commit_msg) 401 EOF 402 test_cmp expected actual 403' 404 405test_expect_success ICONV 'right alignment formatting with no padding and with --graph' ' 406 git log --graph --pretty="tformat:%>(1)%s" >actual && 407 cat <<-EOF >expected && 408 * message two 409 * message one 410 * add bar 411 * $(commit_msg) 412 EOF 413 test_cmp expected actual 414' 415 416test_expect_success ICONV 'right alignment formatting with no padding. i18n.logOutputEncoding' ' 417 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(1)%s" >actual && 418 cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected && 419 message two 420 message one 421 add bar 422 $(commit_msg) 423 EOF 424 test_cmp expected actual 425' 426 427test_expect_success ICONV 'center alignment formatting' ' 428 git log --pretty="tformat:%><(40)%s" >actual && 429 qz_to_tab_space <<-EOF >expected && 430 Z message two Z 431 Z message one Z 432 Z add bar Z 433 Z $(commit_msg) Z 434 EOF 435 test_cmp expected actual 436' 437 438test_expect_success ICONV 'center alignment formatting. i18n.logOutputEncoding' ' 439 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(40)%s" >actual && 440 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected && 441 Z message two Z 442 Z message one Z 443 Z add bar Z 444 Z $(commit_msg) Z 445 EOF 446 test_cmp expected actual 447' 448test_expect_success ICONV 'center alignment formatting at the nth column' ' 449 git log --pretty="tformat:%h %><|(40)%s" >actual && 450 qz_to_tab_space <<-EOF >expected && 451 $head1 message two Z 452 $head2 message one Z 453 $head3 add bar Z 454 $head4 $(commit_msg) Z 455 EOF 456 test_cmp expected actual 457' 458 459test_expect_success ICONV 'center alignment formatting at the nth column' ' 460 COLUMNS=70 git log --pretty="tformat:%h %><|(-30)%s" >actual && 461 qz_to_tab_space <<-EOF >expected && 462 $head1 message two Z 463 $head2 message one Z 464 $head3 add bar Z 465 $head4 $(commit_msg) Z 466 EOF 467 test_cmp expected actual 468' 469 470test_expect_success ICONV 'center alignment formatting at the nth column. i18n.logOutputEncoding' ' 471 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %><|(40)%s" >actual && 472 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected && 473 $head1 message two Z 474 $head2 message one Z 475 $head3 add bar Z 476 $head4 $(commit_msg) Z 477 EOF 478 test_cmp expected actual 479' 480 481test_expect_success ICONV 'center alignment formatting with no padding' ' 482 git log --pretty="tformat:%><(1)%s" >actual && 483 cat <<-EOF >expected && 484 message two 485 message one 486 add bar 487 $(commit_msg) 488 EOF 489 test_cmp expected actual 490' 491 492# save HEAD's SHA-1 digest (with no abbreviations) to use it below 493# as far as the next test amends HEAD 494old_head1=$(git rev-parse --verify HEAD~0) 495test_expect_success ICONV 'center alignment formatting with no padding. i18n.logOutputEncoding' ' 496 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(1)%s" >actual && 497 cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected && 498 message two 499 message one 500 add bar 501 $(commit_msg) 502 EOF 503 test_cmp expected actual 504' 505 506test_expect_success ICONV 'left/right alignment formatting with stealing' ' 507 git commit --amend -m short --author "long long long <long@me.com>" && 508 git log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && 509 cat <<-\EOF >expected && 510 short long long long 511 message .. A U Thor 512 add bar A U Thor 513 initial... A U Thor 514 EOF 515 test_cmp expected actual 516' 517test_expect_success ICONV 'left/right alignment formatting with stealing. i18n.logOutputEncoding' ' 518 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && 519 cat <<-\EOF | iconv -f utf-8 -t $test_encoding >expected && 520 short long long long 521 message .. A U Thor 522 add bar A U Thor 523 initial... A U Thor 524 EOF 525 test_cmp expected actual 526' 527 528test_expect_success 'strbuf_utf8_replace() not producing NUL' ' 529 git log --color --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)%C(auto)%d" | 530 test_decode_color | 531 nul_to_q >actual && 532 ! grep Q actual 533' 534 535# --date=[XXX] and corresponding %a[X] %c[X] format equivalency 536test_expect_success '--date=iso-strict %ad%cd is the same as %aI%cI' ' 537 git log --format=%ad%n%cd --date=iso-strict >expected && 538 git log --format=%aI%n%cI >actual && 539 test_cmp expected actual 540' 541 542test_expect_success '--date=short %ad%cd is the same as %as%cs' ' 543 git log --format=%ad%n%cd --date=short >expected && 544 git log --format=%as%n%cs >actual && 545 test_cmp expected actual 546' 547 548test_expect_success '--date=human %ad%cd is the same as %ah%ch' ' 549 git log --format=%ad%n%cd --date=human >expected && 550 git log --format=%ah%n%ch >actual && 551 test_cmp expected actual 552' 553 554# get new digests (with no abbreviations) 555test_expect_success 'set up log decoration tests' ' 556 head1=$(git rev-parse --verify HEAD~0) && 557 head2=$(git rev-parse --verify HEAD~1) 558' 559 560test_expect_success 'log decoration properly follows tag chain' ' 561 git tag -a tag1 -m tag1 && 562 git tag -a tag2 -m tag2 tag1 && 563 git tag -d tag1 && 564 git commit --amend -m shorter && 565 git log --no-walk --tags --pretty="%H %d" --decorate=full >actual && 566 if test_have_prereq ICONV 567 then 568 cat <<-EOF >expected 569 $head2 (tag: refs/tags/message-one) 570 $old_head1 (tag: refs/tags/message-two) 571 $head1 (tag: refs/tags/tag2) 572 EOF 573 else 574 cat <<-EOF >expected 575 $head2 (tag: refs/tags/message-one) 576 $old_head1 (tag: refs/tags/tag2, tag: refs/tags/message-two) 577 EOF 578 fi && 579 sort -k3 actual >actual1 && 580 test_cmp expected actual1 581' 582 583test_expect_success 'clean log decoration' ' 584 git log --no-walk --tags --pretty="%H %D" --decorate=full >actual && 585 if test_have_prereq ICONV 586 then 587 cat <<-EOF >expected 588 $head2 tag: refs/tags/message-one 589 $old_head1 tag: refs/tags/message-two 590 $head1 tag: refs/tags/tag2 591 EOF 592 else 593 cat <<-EOF >expected 594 $head2 tag: refs/tags/message-one 595 $old_head1 tag: refs/tags/tag2, tag: refs/tags/message-two 596 EOF 597 fi && 598 sort -k3 actual >actual1 && 599 test_cmp expected actual1 600' 601 602test_expect_success 'pretty format %decorate' ' 603 git checkout -b foo && 604 git commit --allow-empty -m "new commit" && 605 git tag bar && 606 git branch qux && 607 608 echo " (HEAD -> foo, tag: bar, qux)" >expect1 && 609 git log --format="%(decorate)" -1 >actual1 && 610 test_cmp expect1 actual1 && 611 612 echo "HEAD -> foo, tag: bar, qux" >expect2 && 613 git log --format="%(decorate:prefix=,suffix=)" -1 >actual2 && 614 test_cmp expect2 actual2 && 615 616 echo "[ bar; qux; foo ]" >expect3 && 617 git log --format="%(decorate:prefix=[ ,suffix= ],separator=%x3B ,tag=)" \ 618 --decorate-refs=refs/ -1 >actual3 && 619 test_cmp expect3 actual3 && 620 621 # Try with a typo (in "separator"), in which case the placeholder should 622 # not be replaced. 623 echo "%(decorate:prefix=[ ,suffix= ],separater=; )" >expect4 && 624 git log --format="%(decorate:prefix=[ ,suffix= ],separater=%x3B )" \ 625 -1 >actual4 && 626 test_cmp expect4 actual4 && 627 628 echo "HEAD->foo bar qux" >expect5 && 629 git log --format="%(decorate:prefix=,suffix=,separator= ,tag=,pointer=->)" \ 630 -1 >actual5 && 631 test_cmp expect5 actual5 632' 633 634cat >trailers <<EOF 635Signed-off-by: A U Thor <author@example.com> 636Acked-by: A U Thor <author@example.com> 637[ v2 updated patch description ] 638Signed-off-by: A U Thor 639 <author@example.com> 640EOF 641 642unfold () { 643 perl -0pe 's/\n\s+/ /g' 644} 645 646test_expect_success 'set up trailer tests' ' 647 echo "Some contents" >trailerfile && 648 git add trailerfile && 649 git commit -F - <<-EOF 650 trailers: this commit message has trailers 651 652 This commit is a test commit with trailers at the end. We parse this 653 message and display the trailers using %(trailers). 654 655 $(cat trailers) 656 EOF 657' 658 659test_expect_success 'pretty format %(trailers) shows trailers' ' 660 git log --no-walk --pretty="%(trailers)" >actual && 661 { 662 cat trailers && 663 echo 664 } >expect && 665 test_cmp expect actual 666' 667 668test_expect_success 'pretty format %(trailers:) enables no options' ' 669 git log --no-walk --pretty="%(trailers:)" >actual && 670 # "expect" the same as the test above 671 test_cmp expect actual 672' 673 674test_expect_success '%(trailers:only) shows only "key: value" trailers' ' 675 git log --no-walk --pretty="%(trailers:only)" >actual && 676 { 677 grep -v patch.description <trailers && 678 echo 679 } >expect && 680 test_cmp expect actual 681' 682 683test_expect_success '%(trailers:only=yes) shows only "key: value" trailers' ' 684 git log --no-walk --pretty=format:"%(trailers:only=yes)" >actual && 685 grep -v patch.description <trailers >expect && 686 test_cmp expect actual 687' 688 689test_expect_success '%(trailers:only=no) shows all trailers' ' 690 git log --no-walk --pretty=format:"%(trailers:only=no)" >actual && 691 cat trailers >expect && 692 test_cmp expect actual 693' 694 695test_expect_success '%(trailers:only=no,only=true) shows only "key: value" trailers' ' 696 git log --no-walk --pretty=format:"%(trailers:only=yes)" >actual && 697 grep -v patch.description <trailers >expect && 698 test_cmp expect actual 699' 700 701test_expect_success PERL_TEST_HELPERS '%(trailers:unfold) unfolds trailers' ' 702 git log --no-walk --pretty="%(trailers:unfold)" >actual && 703 { 704 unfold <trailers && 705 echo 706 } >expect && 707 test_cmp expect actual 708' 709 710test_expect_success PERL_TEST_HELPERS ':only and :unfold work together' ' 711 git log --no-walk --pretty="%(trailers:only,unfold)" >actual && 712 git log --no-walk --pretty="%(trailers:unfold,only)" >reverse && 713 test_cmp actual reverse && 714 { 715 grep -v patch.description <trailers | unfold && 716 echo 717 } >expect && 718 test_cmp expect actual 719' 720 721test_expect_success 'pretty format %(trailers:key=foo) shows that trailer' ' 722 git log --no-walk --pretty="format:%(trailers:key=Acked-by)" >actual && 723 echo "Acked-by: A U Thor <author@example.com>" >expect && 724 test_cmp expect actual 725' 726 727test_expect_success 'pretty format %(trailers:key=foo) is case insensitive' ' 728 git log --no-walk --pretty="format:%(trailers:key=AcKed-bY)" >actual && 729 echo "Acked-by: A U Thor <author@example.com>" >expect && 730 test_cmp expect actual 731' 732 733test_expect_success 'pretty format %(trailers:key=foo:) trailing colon also works' ' 734 git log --no-walk --pretty="format:%(trailers:key=Acked-by:)" >actual && 735 echo "Acked-by: A U Thor <author@example.com>" >expect && 736 test_cmp expect actual 737' 738 739test_expect_success 'pretty format %(trailers:key=foo) multiple keys' ' 740 git log --no-walk --pretty="format:%(trailers:key=Acked-by:,key=Signed-off-By)" >actual && 741 grep -v patch.description <trailers >expect && 742 test_cmp expect actual 743' 744 745test_expect_success '%(trailers:key=nonexistent) becomes empty' ' 746 git log --no-walk --pretty="x%(trailers:key=Nacked-by)x" >actual && 747 echo "xx" >expect && 748 test_cmp expect actual 749' 750 751test_expect_success '%(trailers:key=foo) handles multiple lines even if folded' ' 752 git log --no-walk --pretty="format:%(trailers:key=Signed-Off-by)" >actual && 753 grep -v patch.description <trailers | grep -v Acked-by >expect && 754 test_cmp expect actual 755' 756 757test_expect_success PERL_TEST_HELPERS '%(trailers:key=foo,unfold) properly unfolds' ' 758 git log --no-walk --pretty="format:%(trailers:key=Signed-Off-by,unfold)" >actual && 759 unfold <trailers | grep Signed-off-by >expect && 760 test_cmp expect actual 761' 762 763test_expect_success 'pretty format %(trailers:key=foo,only=no) also includes nontrailer lines' ' 764 git log --no-walk --pretty="format:%(trailers:key=Acked-by,only=no)" >actual && 765 { 766 echo "Acked-by: A U Thor <author@example.com>" && 767 grep patch.description <trailers 768 } >expect && 769 test_cmp expect actual 770' 771 772test_expect_success '%(trailers:key) without value is error' ' 773 git log --no-walk --pretty="tformat:%(trailers:key)" >actual && 774 echo "%(trailers:key)" >expect && 775 test_cmp expect actual 776' 777 778test_expect_success '%(trailers:keyonly) shows only keys' ' 779 git log --no-walk --pretty="format:%(trailers:keyonly)" >actual && 780 test_write_lines \ 781 "Signed-off-by" \ 782 "Acked-by" \ 783 "[ v2 updated patch description ]" \ 784 "Signed-off-by" >expect && 785 test_cmp expect actual 786' 787 788test_expect_success '%(trailers:key=foo,keyonly) shows only key' ' 789 git log --no-walk --pretty="format:%(trailers:key=Acked-by,keyonly)" >actual && 790 echo "Acked-by" >expect && 791 test_cmp expect actual 792' 793 794test_expect_success '%(trailers:key=foo,valueonly) shows only value' ' 795 git log --no-walk --pretty="format:%(trailers:key=Acked-by,valueonly)" >actual && 796 echo "A U Thor <author@example.com>" >expect && 797 test_cmp expect actual 798' 799 800test_expect_success '%(trailers:valueonly) shows only values' ' 801 git log --no-walk --pretty="format:%(trailers:valueonly)" >actual && 802 test_write_lines \ 803 "A U Thor <author@example.com>" \ 804 "A U Thor <author@example.com>" \ 805 "[ v2 updated patch description ]" \ 806 "A U Thor" \ 807 " <author@example.com>" >expect && 808 test_cmp expect actual 809' 810 811test_expect_success '%(trailers:key=foo,keyonly,valueonly) shows nothing' ' 812 git log --no-walk --pretty="format:%(trailers:key=Acked-by,keyonly,valueonly)" >actual && 813 echo >expect && 814 test_cmp expect actual 815' 816 817test_expect_success 'pretty format %(trailers:separator) changes separator' ' 818 git log --no-walk --pretty=format:"X%(trailers:separator=%x00)X" >actual && 819 ( 820 printf "XSigned-off-by: A U Thor <author@example.com>\0" && 821 printf "Acked-by: A U Thor <author@example.com>\0" && 822 printf "[ v2 updated patch description ]\0" && 823 printf "Signed-off-by: A U Thor\n <author@example.com>X" 824 ) >expect && 825 test_cmp expect actual 826' 827 828test_expect_success 'pretty format %(trailers:separator=X,unfold) changes separator' ' 829 git log --no-walk --pretty=format:"X%(trailers:separator=%x00,unfold)X" >actual && 830 ( 831 printf "XSigned-off-by: A U Thor <author@example.com>\0" && 832 printf "Acked-by: A U Thor <author@example.com>\0" && 833 printf "[ v2 updated patch description ]\0" && 834 printf "Signed-off-by: A U Thor <author@example.com>X" 835 ) >expect && 836 test_cmp expect actual 837' 838 839test_expect_success 'pretty format %(trailers:key_value_separator) changes key-value separator' ' 840 git log --no-walk --pretty=format:"X%(trailers:key_value_separator=%x00)X" >actual && 841 ( 842 printf "XSigned-off-by\0A U Thor <author@example.com>\n" && 843 printf "Acked-by\0A U Thor <author@example.com>\n" && 844 printf "[ v2 updated patch description ]\n" && 845 printf "Signed-off-by\0A U Thor\n <author@example.com>\nX" 846 ) >expect && 847 test_cmp expect actual 848' 849 850test_expect_success 'pretty format %(trailers:key_value_separator,unfold) changes key-value separator' ' 851 git log --no-walk --pretty=format:"X%(trailers:key_value_separator=%x00,unfold)X" >actual && 852 ( 853 printf "XSigned-off-by\0A U Thor <author@example.com>\n" && 854 printf "Acked-by\0A U Thor <author@example.com>\n" && 855 printf "[ v2 updated patch description ]\n" && 856 printf "Signed-off-by\0A U Thor <author@example.com>\nX" 857 ) >expect && 858 test_cmp expect actual 859' 860 861test_expect_success 'pretty format %(trailers:separator,key_value_separator) changes both separators' ' 862 git log --no-walk --pretty=format:"%(trailers:separator=%x00,key_value_separator=%x00%x00,unfold)" >actual && 863 ( 864 printf "Signed-off-by\0\0A U Thor <author@example.com>\0" && 865 printf "Acked-by\0\0A U Thor <author@example.com>\0" && 866 printf "[ v2 updated patch description ]\0" && 867 printf "Signed-off-by\0\0A U Thor <author@example.com>" 868 ) >expect && 869 test_cmp expect actual 870' 871 872test_expect_success 'pretty format %(trailers) combining separator/key/keyonly/valueonly' ' 873 git commit --allow-empty -F - <<-\EOF && 874 Important fix 875 876 The fix is explained here 877 878 Closes: #1234 879 EOF 880 881 git commit --allow-empty -F - <<-\EOF && 882 Another fix 883 884 The fix is explained here 885 886 Closes: #567 887 Closes: #890 888 EOF 889 890 git commit --allow-empty -F - <<-\EOF && 891 Does not close any tickets 892 EOF 893 894 git log --pretty="%s% (trailers:separator=%x2c%x20,key=Closes,valueonly)" HEAD~3.. >actual && 895 test_write_lines \ 896 "Does not close any tickets" \ 897 "Another fix #567, #890" \ 898 "Important fix #1234" >expect && 899 test_cmp expect actual && 900 901 git log --pretty="%s% (trailers:separator=%x2c%x20,key=Closes,keyonly)" HEAD~3.. >actual && 902 test_write_lines \ 903 "Does not close any tickets" \ 904 "Another fix Closes, Closes" \ 905 "Important fix Closes" >expect && 906 test_cmp expect actual 907' 908 909test_expect_success 'trailer parsing not fooled by --- line' ' 910 git commit --allow-empty -F - <<-\EOF && 911 this is the subject 912 913 This is the body. The message has a "---" line which would confuse a 914 message+patch parser. But here we know we have only a commit message, 915 so we get it right. 916 917 trailer: wrong 918 --- 919 This is more body. 920 921 trailer: right 922 EOF 923 924 { 925 echo "trailer: right" && 926 echo 927 } >expect && 928 git log --no-walk --format="%(trailers)" >actual && 929 test_cmp expect actual 930' 931 932test_expect_success 'set up %S tests' ' 933 git checkout --orphan source-a && 934 test_commit one && 935 test_commit two && 936 git checkout -b source-b HEAD^ && 937 test_commit three 938' 939 940test_expect_success 'log --format=%S paints branch names' ' 941 cat >expect <<-\EOF && 942 source-b 943 source-a 944 source-b 945 EOF 946 git log --format=%S source-a source-b >actual && 947 test_cmp expect actual 948' 949 950test_expect_success 'log --format=%S paints tag names' ' 951 git tag -m tagged source-tag && 952 cat >expect <<-\EOF && 953 source-tag 954 source-a 955 source-tag 956 EOF 957 git log --format=%S source-tag source-a >actual && 958 test_cmp expect actual 959' 960 961test_expect_success 'log --format=%S paints symmetric ranges' ' 962 cat >expect <<-\EOF && 963 source-b 964 source-a 965 EOF 966 git log --format=%S source-a...source-b >actual && 967 test_cmp expect actual 968' 969 970test_expect_success '%S in git log --format works with other placeholders (part 1)' ' 971 git log --format="source-b %h" source-b >expect && 972 git log --format="%S %h" source-b >actual && 973 test_cmp expect actual 974' 975 976test_expect_success '%S in git log --format works with other placeholders (part 2)' ' 977 git log --format="%h source-b" source-b >expect && 978 git log --format="%h %S" source-b >actual && 979 test_cmp expect actual 980' 981 982test_expect_success 'setup more commits for %S with --bisect' ' 983 test_commit four && 984 test_commit five && 985 986 head1=$(git rev-parse --verify HEAD~0) && 987 head2=$(git rev-parse --verify HEAD~1) && 988 head3=$(git rev-parse --verify HEAD~2) && 989 head4=$(git rev-parse --verify HEAD~3) 990' 991 992test_expect_success '%S with --bisect labels commits with refs/bisect/bad ref' ' 993 git update-ref refs/bisect/bad-$head1 $head1 && 994 git update-ref refs/bisect/go $head1 && 995 git update-ref refs/bisect/bad-$head2 $head2 && 996 git update-ref refs/bisect/b $head3 && 997 git update-ref refs/bisect/bad-$head4 $head4 && 998 git update-ref refs/bisect/good-$head4 $head4 && 999 1000 # We expect to see the range of commits betwee refs/bisect/good-$head4 1001 # and refs/bisect/bad-$head1. The "source" ref is the nearest bisect ref 1002 # from which the commit is reachable. 1003 cat >expect <<-EOF && 1004 $head1 refs/bisect/bad-$head1 1005 $head2 refs/bisect/bad-$head2 1006 $head3 refs/bisect/bad-$head2 1007 EOF 1008 git log --bisect --format="%H %S" >actual && 1009 test_cmp expect actual 1010' 1011 1012test_expect_success 'log --pretty=reference' ' 1013 git log --pretty="tformat:%h (%s, %as)" >expect && 1014 git log --pretty=reference >actual && 1015 test_cmp expect actual 1016' 1017 1018test_expect_success 'log --pretty=reference with log.date is overridden by short date' ' 1019 git log --pretty="tformat:%h (%s, %as)" >expect && 1020 test_config log.date rfc && 1021 git log --pretty=reference >actual && 1022 test_cmp expect actual 1023' 1024 1025test_expect_success 'log --pretty=reference with explicit date overrides short date' ' 1026 git log --date=rfc --pretty="tformat:%h (%s, %ad)" >expect && 1027 git log --date=rfc --pretty=reference >actual && 1028 test_cmp expect actual 1029' 1030 1031test_expect_success 'log --pretty=reference is never unabbreviated' ' 1032 git log --pretty="tformat:%h (%s, %as)" >expect && 1033 git log --no-abbrev-commit --pretty=reference >actual && 1034 test_cmp expect actual 1035' 1036 1037test_expect_success 'log --pretty=reference is never decorated' ' 1038 git log --pretty="tformat:%h (%s, %as)" >expect && 1039 git log --decorate=short --pretty=reference >actual && 1040 test_cmp expect actual 1041' 1042 1043test_expect_success 'log --pretty=reference does not output reflog info' ' 1044 git log --walk-reflogs --pretty="tformat:%h (%s, %as)" >expect && 1045 git log --walk-reflogs --pretty=reference >actual && 1046 test_cmp expect actual 1047' 1048 1049test_expect_success 'log --pretty=reference is colored appropriately' ' 1050 git log --color=always --pretty="tformat:%C(auto)%h (%s, %as)" >expect && 1051 git log --color=always --pretty=reference >actual && 1052 test_cmp expect actual 1053' 1054 1055test_expect_success '%(describe) vs git describe' ' 1056 git log --format="%H" | while read hash 1057 do 1058 if desc=$(git describe $hash) 1059 then 1060 : >expect-contains-good 1061 else 1062 : >expect-contains-bad 1063 fi && 1064 echo "$hash $desc" || return 1 1065 done >expect && 1066 test_path_exists expect-contains-good && 1067 test_path_exists expect-contains-bad && 1068 1069 git log --format="%H %(describe)" >actual 2>err && 1070 test_cmp expect actual && 1071 test_must_be_empty err 1072' 1073 1074test_expect_success '%(describe:match=...) vs git describe --match ...' ' 1075 test_when_finished "git tag -d tag-match" && 1076 git tag -a -m tagged tag-match && 1077 git describe --match "*-match" >expect && 1078 git log -1 --format="%(describe:match=*-match)" >actual && 1079 test_cmp expect actual 1080' 1081 1082test_expect_success '%(describe:exclude=...) vs git describe --exclude ...' ' 1083 test_when_finished "git tag -d tag-exclude" && 1084 git tag -a -m tagged tag-exclude && 1085 git describe --exclude "*-exclude" >expect && 1086 git log -1 --format="%(describe:exclude=*-exclude)" >actual && 1087 test_cmp expect actual 1088' 1089 1090test_expect_success '%(describe:tags) vs git describe --tags' ' 1091 test_when_finished "git tag -d tagname" && 1092 git tag tagname && 1093 git describe --tags >expect && 1094 git log -1 --format="%(describe:tags)" >actual && 1095 test_cmp expect actual 1096' 1097 1098test_expect_success '%(describe:abbrev=...) vs git describe --abbrev=...' ' 1099 test_when_finished "git tag -d tagname" && 1100 1101 # Case 1: We have commits between HEAD and the most recent tag 1102 # reachable from it 1103 test_commit --no-tag file && 1104 git describe --abbrev=15 >expect && 1105 git log -1 --format="%(describe:abbrev=15)" >actual && 1106 test_cmp expect actual && 1107 1108 # Make sure the hash used is at least 15 digits long 1109 sed -e "s/^.*-g\([0-9a-f]*\)$/\1/" <actual >hexpart && 1110 test 16 -le $(wc -c <hexpart) && 1111 1112 # Case 2: We have a tag at HEAD, describe directly gives the 1113 # name of the tag 1114 git tag -a -m tagged tagname && 1115 git describe --abbrev=15 >expect && 1116 git log -1 --format="%(describe:abbrev=15)" >actual && 1117 test_cmp expect actual && 1118 test tagname = $(cat actual) 1119' 1120 1121test_expect_success 'log --pretty with space stealing' ' 1122 printf mm0 >expect && 1123 git log -1 --pretty="format:mm%>>|(1)%x30" >actual && 1124 test_cmp expect actual 1125' 1126 1127test_expect_success 'log --pretty with invalid padding format' ' 1128 printf "%s%%<(20" "$(git rev-parse HEAD)" >expect && 1129 git log -1 --pretty="format:%H%<(20" >actual && 1130 test_cmp expect actual 1131' 1132 1133test_expect_success 'log --pretty with magical wrapping directives' ' 1134 commit_id=$(git commit-tree HEAD^{tree} -m "describe me") && 1135 git tag describe-me $commit_id && 1136 printf "\n(tag:\ndescribe-me)%%+w(2)" >expect && 1137 git log -1 --pretty="format:%w(1)%+d%+w(2)" $commit_id >actual && 1138 test_cmp expect actual 1139' 1140 1141test_expect_success SIZE_T_IS_64BIT 'log --pretty with overflowing wrapping directive' ' 1142 printf "%%w(2147483649,1,1)0" >expect && 1143 git log -1 --pretty="format:%w(2147483649,1,1)%x30" >actual && 1144 test_cmp expect actual && 1145 printf "%%w(1,2147483649,1)0" >expect && 1146 git log -1 --pretty="format:%w(1,2147483649,1)%x30" >actual && 1147 test_cmp expect actual && 1148 printf "%%w(1,1,2147483649)0" >expect && 1149 git log -1 --pretty="format:%w(1,1,2147483649)%x30" >actual && 1150 test_cmp expect actual 1151' 1152 1153test_expect_success SIZE_T_IS_64BIT 'log --pretty with overflowing padding directive' ' 1154 printf "%%<(2147483649)0" >expect && 1155 git log -1 --pretty="format:%<(2147483649)%x30" >actual && 1156 test_cmp expect actual 1157' 1158 1159test_expect_success 'log --pretty with padding and preceding control chars' ' 1160 printf "\20\20 0" >expect && 1161 git log -1 --pretty="format:%x10%x10%>|(4)%x30" >actual && 1162 test_cmp expect actual 1163' 1164 1165test_expect_success 'log --pretty truncation with control chars' ' 1166 test_commit "$(printf "\20\20\20\20xxxx")" file contents commit-with-control-chars && 1167 printf "\20\20\20\20x.." >expect && 1168 git log -1 --pretty="format:%<(3,trunc)%s" commit-with-control-chars >actual && 1169 test_cmp expect actual 1170' 1171 1172test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'log --pretty with huge commit message' ' 1173 # We only assert that this command does not crash. This needs to be 1174 # executed with the address sanitizer to demonstrate failure. 1175 git log -1 --pretty="format:%>(2147483646)%x41%41%>(2147483646)%x41" >/dev/null 1176' 1177 1178test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'set up huge commit' ' 1179 test-tool genzeros 2147483649 | tr "\000" "1" >expect && 1180 huge_commit=$(git commit-tree -F expect HEAD^{tree}) 1181' 1182 1183test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'log --pretty with huge commit message' ' 1184 git log -1 --format="%B%<(1)%x30" $huge_commit >actual && 1185 echo 0 >>expect && 1186 test_cmp expect actual 1187' 1188 1189test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'log --pretty with huge commit message does not cause allocation failure' ' 1190 test_must_fail git log -1 --format="%<(1)%B" $huge_commit 2>error && 1191 cat >expect <<-EOF && 1192 fatal: number too large to represent as int on this platform: 2147483649 1193 EOF 1194 test_cmp expect error 1195' 1196 1197# pretty-formats note wide char limitations, and add tests 1198test_expect_failure 'wide and decomposed characters column counting' ' 1199 1200# from t/lib-unicode-nfc-nfd.sh hex values converted to octal 1201 utf8_nfc=$(printf "\303\251") && # e acute combined. 1202 utf8_nfd=$(printf "\145\314\201") && # e with a combining acute (i.e. decomposed) 1203 utf8_emoji=$(printf "\360\237\221\250") && 1204 1205# replacement character when requesting a wide char fits in a single display colum. 1206# "half wide" alternative could be a plain ASCII dot `.` 1207 utf8_vert_ell=$(printf "\342\213\256") && 1208 1209# use ${xxx} here! 1210 nfc10="${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}" && 1211 nfd10="${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}" && 1212 emoji5="${utf8_emoji}${utf8_emoji}${utf8_emoji}${utf8_emoji}${utf8_emoji}" && 1213# emoji5 uses 10 display columns 1214 1215 test_commit "abcdefghij" && 1216 test_commit --no-tag "${nfc10}" && 1217 test_commit --no-tag "${nfd10}" && 1218 test_commit --no-tag "${emoji5}" && 1219 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 && 1220 git log --format="%<(5,mtrunc)%s" -4 >actual && 1221 test_cmp expected actual 1222' 1223 1224test_done