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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
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>" &&
echo "Some Body <body@example.com> <some@example.com>"
} >.mailmap &&
git add file .mailmap &&
git commit -m "plain commit" &&
git commit --allow-empty -F - <<-\EOF &&
Only trailers
Signed-off-by: A U Thor <author@example.com>
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 <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
Cc: list <not-an-address>
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 "<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' '
cgit_ok trailersrc "url=trailers/commit/" >tmp &&
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' '
cgit_ok trailersrc "url=trailers/commit/" >tmp &&
grep "<tr><th scope=.row.>Signed-off-by</th><td><mapped@example.com> commit MAPPED NAME <MAPPED@EXAMPLE.COM><br><committer@example.com> commit C O MITTER <COMMITTER@EXAMPLE.COM></td></tr>" tmp
'
test_expect_success 'an ident follows the mailmap and keeps what trails the address' '
cgit_ok trailersrc "url=trailers/commit/" >tmp &&
grep "<tr><th scope=.row.>Acked-by</th><td><body@example.com> commit SOME BODY <BODY@EXAMPLE.COM> (maintainer)</td></tr>" tmp
'
test_expect_success 'a value with brackets but no address is no ident' '
cgit_ok trailersrc "url=trailers/commit/" >tmp &&
grep "<tr><th scope=.row.>Cc</th><td>Cc commit LIST <NOT-AN-ADDRESS></td></tr>" tmp
'
test_expect_success 'a key with no value is printed as written' '
cgit_ok trailersrc "url=trailers/commit/" >tmp &&
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' '
cgit_ok trailersrc "url=trailers/commit/" >tmp &&
grep "<tr><td colspan=.2.>(cherry picked from commit deadbeefcafe1234)</td></tr>" tmp
'
test_expect_success 'the escaped value is what the filter sees' '
cgit_ok trailersrc "url=trailers/commit/" >tmp &&
grep "<tr><th scope=.row.>Link</th><td>Link commit HTTPS://EXAMPLE.COM/?A=1&B=2</td></tr>" tmp
'
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 "<tr><th scope=.row.>Fixes</th><td>1234567 (\"PLAIN COMMIT\")</td></tr>" tmp &&
grep "<tr><th scope=.row.>Acked-by</th><td>Some Body <body@example.com> (maintainer)</td></tr>" tmp
'
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 "<tr><th scope=.row.>Signed-off-by</th><td>Mapped Name<br>C O Mitter</td></tr>" tmp &&
grep "<tr><th scope=.row.>Acked-by</th><td>Some Body (maintainer)</td></tr>" 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 "<div class=.commit-msg.></div>" 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 "<div class=.commit-msg.></div>" tmp &&
grep "<tr><th scope=.row.>Signed-off-by</th><td><mapped@example.com> commit MAPPED NAME <MAPPED@EXAMPLE.COM></td></tr>" 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 "<table class=.commit-trailers.>" tmp
'
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 <author@example.com>\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
|