blob: 61fba94a3f8671e3966f19768bbeb37bac59cbab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/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 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.

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 <mapped@example.com> <author@example.com>" >.mailmap &&
		git add file .mailmap &&
		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>
		Acked-by: Some One <some@example.com> (maintainer)
		Reported-by:
		(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-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
'

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 scope=.row.>Fixes</th><td>Fixes commit 1234567 (.PLAIN COMMIT.)</td></tr>" tmp
'

test_expect_success 'a run of one key, whatever its case, collapses into one row' '
	grep "<tr><th scope=.row.>Signed-off-by</th><td><mapped@example.com> commit MAPPED NAME &LT;MAPPED@EXAMPLE.COM&GT;<br><committer@example.com> commit C O MITTER &LT;COMMITTER@EXAMPLE.COM&GT;</td></tr>" tmp
'

test_expect_success 'an ident follows the mailmap and keeps what trails the address' '
	grep "<tr><th scope=.row.>Acked-by</th><td><some@example.com> commit SOME ONE &LT;SOME@EXAMPLE.COM&GT; (maintainer)</td></tr>" tmp
'

test_expect_success 'a key with no value is printed as written' '
	grep "<tr><td colspan=.2.>Reported-by:</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 scope=.row.>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-commit-trailers=1/enable-commit-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-commit-trailers=0" >>cgitrc &&
	cgit_url "trailers/commit/" >tmp &&
	! grep "commit-trailers" tmp &&
	grep "Signed-off-by: A U Thor" tmp
'

test_done