From cd9e0e9a53fc921f53d22add7ed422da677c7d19 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Tue, 15 Sep 2026 18:20:18 -1000 Subject: Split trailers out of the commit message --- tests/t0206-trailers.sh | 91 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100755 tests/t0206-trailers.sh (limited to 'tests') diff --git a/tests/t0206-trailers.sh b/tests/t0206-trailers.sh new file mode 100755 index 0000000..fe96c5a --- /dev/null +++ b/tests/t0206-trailers.sh @@ -0,0 +1,91 @@ +#!/bin/sh + +# The trailer table on the commit page. A commit whose message ends in a +# trailer block is rendered with enable-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. A commit with no block is checked to get no table. + +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 && + git add file && + git commit -m "plain commit" && + 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 + (cherry picked from commit deadbeefcafe1234) + Link: https://example.com/?a=1&b=2 + EOF + ) +' + +test_expect_success 'point cgit at it with trailers on and the dump filters' ' + cat >cgitrc <<-EOF && + virtual-root=/ + cache-size=0 + enable-trailers=1 + enable-filter-overrides=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 +' + +test_expect_success 'the body ends where the block begins' ' + 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 +' + +test_expect_success 'a run of one key collapses into one row through the email filter' ' + grep "Signed-off-by commit A U THOR <AUTHOR@EXAMPLE.COM>
commit C O MITTER <COMMITTER@EXAMPLE.COM>" tmp +' + +test_expect_success 'a line git could not split gets a row of its own' ' + grep "(cherry picked from commit deadbeefcafe1234)" tmp +' + +test_expect_success 'the escaped value is what the filter sees' ' + grep "LinkLink commit HTTPS://EXAMPLE.COM/?A=1&B=2" 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 && + grep "
" tmp && + ! grep "commit-trailers" tmp +' + +test_expect_success 'with the flag off the message stays whole' ' + sed "s/^enable-trailers=1/enable-trailers=0/" cgitrc >cgitrc-off && + CGIT_CONFIG="$PWD/cgitrc-off" QUERY_STRING="url=trailers/commit/" cgit >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-trailers=0" >>cgitrc && + cgit_url "trailers/commit/" >tmp && + ! grep "commit-trailers" tmp && + grep "Signed-off-by: A U Thor" tmp +' + +test_done -- cgit v2.8.0