diff options
context:
space:
mode:
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Split trailers out of the commit message
Diffstat (limited to 'tests')
-rwxr-xr-xtests/t0206-trailers.sh91
1 file changed, 91 insertions, 0 deletions
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 <author@example.com>
+ Signed-off-by: C O Mitter <committer@example.com>
+ (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 "<div class=.commit-msg.>The body keeps its colon: it is not a trailer.</div>" tmp
+'
+
+test_expect_success 'a value reaches the trailer filter with its key and page' '
+ grep "<tr><th>Fixes</th><td>Fixes commit 1234567 (.PLAIN COMMIT.)</td></tr>" tmp
+'
+
+test_expect_success 'a run of one key collapses into one row through the email filter' '
+ grep "<tr><th>Signed-off-by</th><td><author@example.com> commit A U THOR &LT;AUTHOR@EXAMPLE.COM&GT;<br><committer@example.com> commit C O MITTER &LT;COMMITTER@EXAMPLE.COM&GT;</td></tr>" tmp
+'
+
+test_expect_success 'a line git could not split gets a row of its own' '
+ grep "<tr><td colspan=.2.>(cherry picked from commit deadbeefcafe1234)</td></tr>" tmp
+'
+
+test_expect_success 'the escaped value is what the filter sees' '
+ grep "<tr><th>Link</th><td>Link commit HTTPS://EXAMPLE.COM/?A=1&AMP;B=2</td></tr>" 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 "<div class=.commit-msg.></div>" 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