#!/bin/sh # 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 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 . ./setup.sh test_expect_success 'create a repository with a trailer-shaped message' ' test_create_repo repos/trailers && ( cd repos/trailers && echo content >file && { 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 Fix the frobnicator The body keeps its colon: it is not a trailer. Fixes: 1234567 ("plain commit") Signed-off-by: A U Thor signed-off-by: C O Mitter Acked-by: Some One (maintainer) Reported-by: (cherry picked from commit deadbeefcafe1234) Link: https://example.com/?a=1&b=2 Cc: list EOF ) && 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' ' 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' ' 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 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~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' ' 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' ' 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 && cgitrc_repo repoonrc trailers enable-commit-trailers=0 repo.enable-commit-trailers=1 && cgit_ok repoonrc "url=trailers/commit/" >tmp && grep "" tmp ' # git leaves an old style Conflicts section out of the block it finds, so a # message holding one after its trailers is shown whole rather than lose the # section to the split. git knows the section by the tab before each path, # which a here-document with a dash would strip. test_expect_success 'the commit page shows a message whole when text follows its trailers' ' test_create_repo repos/conflicts && echo content >repos/conflicts/file && git -C repos/conflicts add file && printf "Subject\n\nBody text.\n\nSigned-off-by: A U Thor \n\nConflicts:\n\tfile\n" >msg && git -C repos/conflicts commit -q -F "$PWD/msg" && cgitrc_repo conflictsrc conflicts enable-commit-trailers=1 && cgit_ok conflictsrc "url=conflicts/commit/" >tmp && ! grep "commit-trailers" tmp && grep "^Signed-off-by: A U Thor" tmp && printf "Conflicts:\n\tfile\n" >expect && sed -n "/^Conflicts:/,/^\tfile/p" tmp >actual && test_cmp expect actual ' test_done