Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t6006-rev-list-format.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t6006-rev-list-format.sh` 642 lines · 16081 bytes Raw Blame History 1 #!/bin/sh 2 3 # Copyright (c) 2009 Jens Lehmann 4 # Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests) 5 6 test_description='git rev-list --pretty=format test' 7 8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 10 11 . ./test-lib.sh 12 . "$TEST_DIRECTORY"/lib-terminal.sh 13 14 test_tick 15 16 if test_have_prereq ICONV 17 then 18 # Tested non-UTF-8 encoding 19 test_encoding="ISO8859-1" 20 21 # String "added" in German 22 # (translated with Google Translate), 23 # encoded in UTF-8, used as a commit log message below. 24 added_utf8_part=$(printf "\303\274") 25 added_utf8_part_iso88591=$(echo "$added_utf8_part" | iconv -f utf-8 -t $test_encoding) 26 added=$(printf "added (hinzugef${added_utf8_part}gt) foo") 27 added_iso88591=$(echo "$added" | iconv -f utf-8 -t $test_encoding) 28 # same but "changed" 29 changed_utf8_part=$(printf "\303\244") 30 changed_utf8_part_iso88591=$(echo "$changed_utf8_part" | iconv -f utf-8 -t $test_encoding) 31 changed=$(printf "changed (ge${changed_utf8_part}ndert) foo") 32 changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t $test_encoding) 33 else 34 # Tested non-UTF-8 encoding 35 test_encoding="UTF-8" 36 37 # String "added" in German 38 # (translated with Google Translate), 39 # encoded in UTF-8, used as a commit log message below. 40 added_utf8_part="u" 41 added_utf8_part_iso88591="u" 42 added=$(printf "added (hinzugef${added_utf8_part}gt) foo") 43 added_iso88591="$added" 44 # same but "changed" 45 changed_utf8_part="a" 46 changed_utf8_part_iso88591="a" 47 changed=$(printf "changed (ge${changed_utf8_part}ndert) foo") 48 changed_iso88591="$changed" 49 fi 50 51 # Count of char to truncate 52 # Number is chosen so, that non-ACSII characters 53 # (see $added_utf8_part and $changed_utf8_part) 54 # fall into truncated parts of appropriate words both from left and right 55 truncate_count=20 56 57 test_expect_success 'setup' ' 58 : >foo && 59 git add foo && 60 git config i18n.commitEncoding $test_encoding && 61 echo "$added_iso88591" | git commit -F - && 62 head1=$(git rev-parse --verify HEAD) && 63 head1_short=$(git rev-parse --verify --short $head1) && 64 head1_short4=$(git rev-parse --verify --short=4 $head1) && 65 tree1=$(git rev-parse --verify HEAD:) && 66 tree1_short=$(git rev-parse --verify --short $tree1) && 67 echo "$changed" > foo && 68 echo "$changed_iso88591" | git commit -a -F - && 69 head2=$(git rev-parse --verify HEAD) && 70 head2_short=$(git rev-parse --verify --short $head2) && 71 head2_short4=$(git rev-parse --verify --short=4 $head2) && 72 tree2=$(git rev-parse --verify HEAD:) && 73 tree2_short=$(git rev-parse --verify --short $tree2) && 74 git config --unset i18n.commitEncoding 75 ' 76 77 # usage: test_format [argument...] name format_string [success|failure] [prereq] expect.$1 91 test_expect_${3:-success} $4 "format $1" " 92 git rev-list $args --pretty=format:'$2' main >output.$1 && 93 test_cmp expect.$1 output.$1 94 " 95 } 96 97 # usage: test_pretty [argument...] name format_name [failure] expect.$1 111 test_expect_${3:-success} "pretty $1 (without --no-commit-header)" " 112 git rev-list $args --pretty='$2' main >output.$1 && 113 test_cmp expect.$1 output.$1 114 " 115 test_expect_${3:-success} "pretty $1 (with --no-commit-header)" " 116 git rev-list $args --no-commit-header --pretty='$2' main >output.$1 && 117 test_cmp expect.$1 output.$1 118 " 119 } 120 121 # Feed to --format to provide predictable colored sequences. 122 BASIC_COLOR='%Credfoo%Creset' 123 COLOR='%C(red)foo%C(reset)' 124 AUTO_COLOR='%C(auto,red)foo%C(auto,reset)' 125 ALWAYS_COLOR='%C(always,red)foo%C(always,reset)' 126 has_color () { 127 test_decode_color <"$1" >decoded && 128 echo "foo" >expect && 129 test_cmp expect decoded 130 } 131 132 has_no_color () { 133 echo foo >expect && 134 test_cmp expect "$1" 135 } 136 137 test_format percent %%h < 270 271 $changed 272 273 commit $head1 274 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 275 276 $added 277 278 EOF 279 280 test_expect_success 'basic colors' ' 281 cat >expect <<-EOF && 282 commit $head2 283 foobarbazxyzzy 284 EOF 285 format="%Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy" && 286 git rev-list --color --format="$format" -1 main >actual.raw && 287 test_decode_color actual && 288 test_cmp expect actual 289 ' 290 291 test_expect_success '%S is not a placeholder for rev-list yet' ' 292 git rev-list --format="%S" -1 main | grep "%S" 293 ' 294 295 test_expect_success 'advanced colors' ' 296 cat >expect <<-EOF && 297 commit $head2 298 foo 299 EOF 300 format="%C(red yellow bold)foo%C(reset)" && 301 git rev-list --color --format="$format" -1 main >actual.raw && 302 test_decode_color actual && 303 test_cmp expect actual 304 ' 305 306 for spec in \ 307 "%Cred:$BASIC_COLOR" \ 308 "%C(...):$COLOR" \ 309 "%C(auto,...):$AUTO_COLOR" 310 do 311 desc=${spec%%:*} 312 color=${spec#*:} 313 test_expect_success "$desc does not enable color by default" ' 314 git log --format=$color -1 >actual && 315 has_no_color actual 316 ' 317 318 test_expect_success "$desc enables colors for color.diff" ' 319 git -c color.diff=always log --format=$color -1 >actual && 320 has_color actual 321 ' 322 323 test_expect_success "$desc enables colors for color.ui" ' 324 git -c color.ui=always log --format=$color -1 >actual && 325 has_color actual 326 ' 327 328 test_expect_success "$desc respects --color" ' 329 git log --format=$color -1 --color >actual && 330 has_color actual 331 ' 332 333 test_expect_success "$desc respects --no-color" ' 334 git -c color.ui=always log --format=$color -1 --no-color >actual && 335 has_no_color actual 336 ' 337 338 test_expect_success TTY "$desc respects --color=auto (stdout is tty)" ' 339 test_terminal git log --format=$color -1 --color=auto >actual && 340 has_color actual 341 ' 342 343 test_expect_success "$desc respects --color=auto (stdout not tty)" ' 344 ( 345 TERM=vt100 && export TERM && 346 git log --format=$color -1 --color=auto >actual && 347 has_no_color actual 348 ) 349 ' 350 done 351 352 test_expect_success '%C(always,...) enables color even without tty' ' 353 git log --format=$ALWAYS_COLOR -1 >actual && 354 has_color actual 355 ' 356 357 test_expect_success '%C(auto) respects --color' ' 358 git log --color --format="%C(auto)%H" -1 >actual.raw && 359 test_decode_color actual && 360 echo "$(git rev-parse HEAD)" >expect && 361 test_cmp expect actual 362 ' 363 364 test_expect_success '%C(auto) respects --no-color' ' 365 git log --no-color --format="%C(auto)%H" -1 >actual && 366 git rev-parse HEAD >expect && 367 test_cmp expect actual 368 ' 369 370 test_expect_success 'rev-list %C(auto,...) respects --color' ' 371 git rev-list --color --format="%C(auto,green)foo%C(auto,reset)" \ 372 -1 HEAD >actual.raw && 373 test_decode_color actual && 374 cat >expect <<-EOF && 375 commit $(git rev-parse HEAD) 376 foo 377 EOF 378 test_cmp expect actual 379 ' 380 381 test_expect_success 'setup complex body' ' 382 message=$(cat <<-EOF 383 Test printing of complex bodies 384 385 This commit message is much longer than the others, 386 and it will be encoded in $test_encoding. We should therefore 387 include an ISO8859 character: ¡bueno! 388 EOF 389 ) && 390 391 if test_have_prereq ICONV 392 then 393 echo "$message" | iconv -f utf-8 -t $test_encoding >commit-msg 394 else 395 echo "$message" >commit-msg 396 fi && 397 398 git config i18n.commitencoding $test_encoding && 399 echo change2 >foo && git commit -a -F commit-msg && 400 head3=$(git rev-parse --verify HEAD) && 401 head3_short=$(git rev-parse --short $head3) 402 ' 403 404 test_format complex-encoding %e success ICONV <expected.utf-8 && 451 commit $head3 452 This commit message is much longer than the others, 453 and it will be encoded in $test_encoding. We should therefore 454 include an ISO8859 character: ¡bueno! 455 456 commit $head2 457 commit $head1 458 EOF 459 if test_have_prereq ICONV 460 then 461 iconv -f utf-8 -t $test_encoding expected.utf-8 >expected.ISO8859-1 462 else 463 cp expected.utf-8 expected.ISO8859-1 464 fi 465 ' 466 467 test_format complex-body %b expect commit $head3 && 513 echo >>expect fooQbar && 514 git rev-list -1 --format=foo%x00bar HEAD >actual.nul && 515 nul_to_q actual && 516 test_cmp expect actual 517 ' 518 519 test_expect_success '%ad respects --date=' ' 520 echo 2005-04-07 >expect.ad-short && 521 git log -1 --date=short --pretty=tformat:%ad >output.ad-short main && 522 test_cmp expect.ad-short output.ad-short 523 ' 524 525 test_expect_success 'empty email' ' 526 test_tick && 527 C=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} actual && 534 test_line_count = 2 actual 535 ' 536 537 test_expect_success 'del LF before empty (2)' ' 538 git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD >actual && 539 test_line_count = 6 actual && 540 test_grep "^$" actual 541 ' 542 543 test_expect_success 'add LF before non-empty (1)' ' 544 git show -s --pretty=format:"%s%+b%nThanks%n" HEAD^^ >actual && 545 test_line_count = 2 actual 546 ' 547 548 test_expect_success 'add LF before non-empty (2)' ' 549 git show -s --pretty=format:"%s%+b%nThanks%n" HEAD >actual && 550 test_line_count = 6 actual && 551 test_grep "^$" actual 552 ' 553 554 test_expect_success 'add SP before non-empty (1)' ' 555 git show -s --pretty=format:"%s% bThanks" HEAD^^ >actual && 556 test $(wc -w actual && 561 test $(wc -w expect2 && 566 echo LONG LONG LONG >expect3 && 567 git log -1 --format="%h %h %h" HEAD >actual1 && 568 git log -1 --abbrev=5 --format="%h %h %h" HEAD >actual2 && 569 git log -1 --abbrev=5 --format="%H %H %H" HEAD >actual3 && 570 sed -e "s/$OID_REGEX/LONG/g" -e "s/$_x05/SHORT/g" fuzzy2 && 571 sed -e "s/$OID_REGEX/LONG/g" -e "s/$_x05/SHORT/g" fuzzy3 && 572 test_cmp expect2 fuzzy2 && 573 test_cmp expect3 fuzzy3 && 574 ! test_cmp actual1 actual2 575 ' 576 577 test_expect_success '%H is not affected by --abbrev-commit' ' 578 expected=$(($(test_oid hexsz) + 1)) && 579 git log -1 --format=%H --abbrev-commit --abbrev=20 HEAD >actual && 580 len=$(wc -c actual && 586 len=$(wc -c expect && 592 git log -g --format="%h %gD: %gs" >actual && 593 test_cmp expect actual 594 ' 595 596 test_expect_success '"%h %gD: %gs" is same as git-reflog (with date)' ' 597 git reflog --date=raw >expect && 598 git log -g --format="%h %gD: %gs" --date=raw >actual && 599 test_cmp expect actual 600 ' 601 602 test_expect_success '"%h %gD: %gs" is same as git-reflog (with --abbrev)' ' 603 git reflog --abbrev=13 --date=raw >expect && 604 git log -g --abbrev=13 --format="%h %gD: %gs" --date=raw >actual && 605 test_cmp expect actual 606 ' 607 608 test_expect_success '%gd shortens ref name' ' 609 echo "main@{0}" >expect.gd-short && 610 git log -g -1 --format=%gd refs/heads/main >actual.gd-short && 611 test_cmp expect.gd-short actual.gd-short 612 ' 613 614 test_expect_success 'reflog identity' ' 615 echo "$GIT_COMMITTER_NAME:$GIT_COMMITTER_EMAIL" >expect && 616 git log -g -1 --format="%gn:%ge" >actual && 617 test_cmp expect actual 618 ' 619 620 test_expect_success 'oneline with empty message' ' 621 git commit --allow-empty --cleanup=verbatim -m "$LF" && 622 git commit --allow-empty --allow-empty-message && 623 git rev-list --oneline HEAD >test.txt && 624 test_line_count = 5 test.txt && 625 git rev-list --oneline --graph HEAD >testg.txt && 626 test_line_count = 5 testg.txt 627 ' 628 629 test_expect_success 'single-character name is parsed correctly' ' 630 git commit --author="a " --allow-empty -m foo && 631 echo "a " >expect && 632 git log -1 --format="%an <%ae>" >actual && 633 test_cmp expect actual 634 ' 635 636 test_expect_success 'unused %G placeholders are passed through' ' 637 echo "%GX %G" >expect && 638 git log -1 --format="%GX %G" >actual && 639 test_cmp expect actual 640 ' 641 642 test_done