From 89b10a4159a7bf1fb8799445c50bc949e360bd32 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 13:49:37 -1000 Subject: Check the trailer values each path takes The ident said to follow the mailmap had no entry in it, and the commit filter that takes a value when no trailer filter is set had no test, nor did brackets without an address, a message of nothing but a block and the repository flag turning the table on. One test appended to the shared config, and seven read a page an earlier test fetched. --- tests/t0206-trailers.sh | 90 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 28 deletions(-) (limited to 'tests') diff --git a/tests/t0206-trailers.sh b/tests/t0206-trailers.sh index 70f10bd..5a8fe97 100755 --- a/tests/t0206-trailers.sh +++ b/tests/t0206-trailers.sh @@ -3,9 +3,10 @@ # The trailer table on the commit page. A commit whose message ends in a # trailer block is rendered with enable-commit-trailers on, through the exec # dump filter as both trailer filter and email filter so the arguments each -# one receives show in the page, then with the flag off globally and off for -# the one repository. The repository carries a mailmap, so the sign-off idents -# are checked to follow it. A commit with no block is checked to get no table. +# one receives show in the page, then through the commit filter alone, then +# with the flag off globally and off for the one repository. The repository +# carries a mailmap, so the idents are checked to follow it. Commits with no +# block, or nothing but one, are checked as well. test_description='Check the commit trailers table' CGIT_TEST_NO_CREATE_REPOS=YesPlease @@ -16,9 +17,17 @@ test_expect_success 'create a repository with a trailer-shaped message' ' ( cd repos/trailers && echo content >file && - echo "Mapped Name " >.mailmap && + { + echo "Mapped Name " && + echo "Some Body " + } >.mailmap && git add file .mailmap && git commit -m "plain commit" && + git commit --allow-empty -F - <<-\EOF && + Only trailers + + Signed-off-by: A U Thor + EOF echo more >>file && git add file && git commit -F - <<-\EOF @@ -33,80 +42,105 @@ test_expect_success 'create a repository with a trailer-shaped message' ' Reported-by: (cherry picked from commit deadbeefcafe1234) Link: https://example.com/?a=1&b=2 + Cc: list EOF - ) -' - -test_expect_success 'point cgit at it with trailers on and the dump filters' ' - cat >cgitrc <<-EOF && - virtual-root=/ - cache-size=0 - enable-commit-trailers=1 - repo.url=trailers - repo.path=$PWD/repos/trailers/.git - repo.trailer-filter=exec:$FILTER_DIRECTORY/dump.sh - repo.email-filter=exec:$FILTER_DIRECTORY/dump.sh - EOF - cgit_url "trailers/commit/" >tmp + ) && + cgitrc_repo trailersrc trailers enable-commit-trailers=1 \ + "repo.trailer-filter=exec:$FILTER_DIRECTORY/dump.sh" \ + "repo.email-filter=exec:$FILTER_DIRECTORY/dump.sh" ' test_expect_success 'the body ends where the block begins' ' + cgit_ok trailersrc "url=trailers/commit/" >tmp && grep "
The body keeps its colon: it is not a trailer.
" tmp ' test_expect_success 'a value reaches the trailer filter with its key and page' ' - grep "FixesFixes commit 1234567 (.PLAIN COMMIT.)" tmp + cgit_ok trailersrc "url=trailers/commit/" >tmp && + grep "FixesFixes commit 1234567 (\"PLAIN COMMIT\")" tmp ' test_expect_success 'a run of one key, whatever its case, collapses into one row' ' + cgit_ok trailersrc "url=trailers/commit/" >tmp && grep "Signed-off-by commit MAPPED NAME <MAPPED@EXAMPLE.COM>
commit C O MITTER <COMMITTER@EXAMPLE.COM>" tmp ' test_expect_success 'an ident follows the mailmap and keeps what trails the address' ' - grep "Acked-by commit SOME ONE <SOME@EXAMPLE.COM> (maintainer)" tmp + cgit_ok trailersrc "url=trailers/commit/" >tmp && + grep "Acked-by commit SOME BODY <BODY@EXAMPLE.COM> (maintainer)" tmp +' + +# Brackets with no address in them make no ident, so the value goes to the +# trailer filter like any other text. +test_expect_success 'a value with brackets but no address is no ident' ' + cgit_ok trailersrc "url=trailers/commit/" >tmp && + grep "CcCc commit LIST <NOT-AN-ADDRESS>" tmp ' test_expect_success 'a key with no value is printed as written' ' + cgit_ok trailersrc "url=trailers/commit/" >tmp && grep "Reported-by:" tmp ' test_expect_success 'a line git could not split gets a row of its own' ' + cgit_ok trailersrc "url=trailers/commit/" >tmp && grep "(cherry picked from commit deadbeefcafe1234)" tmp ' test_expect_success 'the escaped value is what the filter sees' ' + cgit_ok trailersrc "url=trailers/commit/" >tmp && grep "LinkLink commit HTTPS://EXAMPLE.COM/?A=1&B=2" tmp ' +# With no trailer filter, a value goes through the commit filter, which is +# handed no key and no page, while an ident still takes the email path. +test_expect_success 'without a trailer filter the commit filter takes the values' ' + cgitrc_repo commitfilterrc trailers enable-commit-trailers=1 \ + "repo.commit-filter=exec:$FILTER_DIRECTORY/dump.sh" && + cgit_ok commitfilterrc "url=trailers/commit/" >tmp && + grep "Fixes1234567 (\"PLAIN COMMIT\")" tmp && + grep "Acked-bySome Body <body@example.com> (maintainer)" tmp +' + # The dump filter is handed the address whatever the setting, so the page is # drawn without it here. test_expect_success 'enable-plain-email=0 leaves the addresses off the idents' ' cgitrc_repo plainrc trailers enable-commit-trailers=1 enable-plain-email=0 && cgit_ok plainrc "url=trailers/commit/" >tmp && grep "Signed-off-byMapped Name
C O Mitter" tmp && - grep "Acked-bySome One (maintainer)" tmp && + grep "Acked-bySome Body (maintainer)" tmp && ! grep "@example.com" tmp ' test_expect_success 'a message with no block gets no table' ' - plain=$(git -C repos/trailers rev-parse HEAD~1) && - cgit_url "trailers/commit/&id=$plain" >tmp && + plain=$(git -C repos/trailers rev-parse HEAD~2) && + cgit_ok trailersrc "url=trailers/commit/&id=$plain" >tmp && grep "
" tmp && ! grep "commit-trailers" tmp ' +test_expect_success 'a message of nothing but a block is all table' ' + only=$(git -C repos/trailers rev-parse HEAD~1) && + cgit_ok trailersrc "url=trailers/commit/&id=$only" >tmp && + grep "
" tmp && + grep "Signed-off-by commit MAPPED NAME <MAPPED@EXAMPLE.COM>" tmp +' + test_expect_success 'with the flag off the message stays whole' ' - sed "s/^enable-commit-trailers=1/enable-commit-trailers=0/" cgitrc >cgitrc-off && - cgit_rc cgitrc-off "url=trailers/commit/" >tmp && + cgitrc_repo offrc trailers && + cgit_ok offrc "url=trailers/commit/" >tmp && ! grep "commit-trailers" tmp && grep "Signed-off-by: A U Thor" tmp ' test_expect_success 'the repository flag overrides the global one' ' - echo "repo.enable-commit-trailers=0" >>cgitrc && - cgit_url "trailers/commit/" >tmp && + cgitrc_repo repooffrc trailers enable-commit-trailers=1 repo.enable-commit-trailers=0 && + cgit_ok repooffrc "url=trailers/commit/" >tmp && ! grep "commit-trailers" tmp && - grep "Signed-off-by: A U Thor" tmp + grep "Signed-off-by: A U Thor" tmp && + cgitrc_repo repoonrc trailers enable-commit-trailers=0 repo.enable-commit-trailers=1 && + cgit_ok repoonrc "url=trailers/commit/" >tmp && + grep "" tmp ' test_done -- cgit 2.12.1