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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
test_description='Check content on summary page'
. ./setup.sh
test_expect_success 'generate foo summary' '
cgit_ok_url "foo" >tmp &&
sed -n "/<tbody class=.log.>/,/<\/tbody>/p" tmp >log
'
test_expect_success 'find commit 1' 'test_grep ">commit 1<" log'
test_expect_success 'find commit 5' 'test_grep ">commit 5<" log'
test_expect_success 'find branch master' 'grep "<tr class=.branch.><td><a[^>]*>master</a>" tmp'
test_expect_success 'a repository without tags draws no tag table' '
cgit_ok_url "foo" >tmp &&
test_grep "<tbody class=.branches.>" tmp &&
test_grep ! "Tag</th>" tmp
'
test_expect_success 'clone-url expanded correctly' '
grep "git://example.org/foo.git" tmp
'
test_expect_success 'generate bar summary' '
cgit_ok_url "bar" >tmp &&
sed -n "/<tbody class=.log.>/,/<\/tbody>/p" tmp >log
'
test_expect_success 'repo description reaches the meta tag' '
grep "<meta name=.description. content=.the bar repo.>" tmp
'
test_expect_success 'the summary log stops at summary-log commits' '
test_grep ">commit 46<" log &&
test_grep ! ">commit 45<" log
'
test_expect_success 'find commit 50' 'test_grep ">commit 50<" log'
test_expect_success 'a git clone url row falls back to the page url' '
grep "clone-url.><a rel=.vcs-git. title=.bar Git repository. href=./bar/.>git://example.org/bar.git</a>" tmp
'
test_expect_success 'an scp clone url row links to the http url' '
cgitrc_repo clonerc foo "repo.clone-url=git@example.org:foo https://example.org/foo" &&
cgit_ok clonerc "url=foo" >tmp &&
grep "title=.foo Git repository. href=.https://example.org/foo.>git@example.org:foo</a>" tmp
'
test_expect_success 'the head links only the clone urls with a scheme' '
cgit_ok clonerc "url=foo" >tmp &&
test_grep "<link rel=.vcs-git. href=.https://example.org/foo. title=.foo Git repository.>" tmp &&
test_grep ! "<link rel=.vcs-git. href=.git@" tmp
'
test_expect_success 'clone-prefix gives a clone url per prefix' '
cgitrc_repo prefixrc foo "clone-prefix=https://a git://b" &&
cgit_ok prefixrc "url=foo" >tmp &&
test_grep "clone-url.><a rel=.vcs-git. title=.foo Git repository. href=.https://a/foo.>https://a/foo</a>" tmp &&
test_grep "clone-url.><a rel=.vcs-git. title=.foo Git repository. href=.https://a/foo.>git://b/foo</a>" tmp
'
test_expect_success 'a space in the repository url stays inside one clone url' '
cgit_ok_url "with+space" >tmp &&
test_grep "clone-url.><a rel=.vcs-git. title=.with space Git repository. href=./with%20space/.>git://example.org/with space.git</a>" tmp &&
test $(grep -c "class=.clone-url." tmp) = 1 &&
test_grep "<link rel=.vcs-git. href=.git://example.org/with%20space\.git. title=.with space Git repository.>" tmp &&
test $(grep -c "<link rel=.vcs-git." tmp) = 1 &&
cgitrc_repo spacerc "with space" "clone-prefix=https://a git://b" &&
cgit_ok spacerc "url=with+space" >tmp &&
test_grep ">https://a/with space</a>" tmp &&
test_grep ">git://b/with space</a>" tmp &&
test $(grep -c "class=.clone-url." tmp) = 2
'
test_expect_success 'a clone url is linked percent-encoded' '
url=$(printf "d\303\251p\303\264t") &&
encoded=d%C3%A9p%C3%B4t &&
cgitrc_repo encrc "$url" "repo.path=$PWD/repos/foo/.git" \
"repo.clone-url=git+ssh://example.org/my%20repos/\$CGIT_REPO_URL.git https://example.org/\$CGIT_REPO_URL" &&
cgit_ok encrc "url=$encoded" >tmp &&
test_grep "<link rel=.vcs-git. href=.git+ssh://example.org/my%20repos/$encoded\.git. title=.$url Git repository.>" tmp &&
test_grep "<link rel=.vcs-git. href=.https://example.org/$encoded. title=.$url Git repository.>" tmp &&
test_grep "title=.$url Git repository. href=.https://example.org/$encoded.>git+ssh://example.org/my%20repos/$url\.git</a>" tmp &&
test_grep "title=.$url Git repository. href=.https://example.org/$encoded.>https://example.org/$url</a>" tmp &&
test_grep ! "href=.[^ >]*$url" tmp &&
cgit_ok spacerc "url=with+space" >tmp &&
test_grep "<link rel=.vcs-git. href=.https://a/with%20space. title=.with space Git repository.>" tmp &&
test_grep "<link rel=.vcs-git. href=.git://b/with%20space. title=.with space Git repository.>" tmp &&
test_grep "href=.https://a/with%20space.>git://b/with space</a>" tmp
'
test_expect_success 'a clone url from the request stays inside its attribute' '
cgitrc_repo hostrc foo "repo.clone-url=https://\$HTTP_HOST/\$CGIT_REPO_URL" &&
(
HTTP_HOST="h'\''\"<x>" &&
export HTTP_HOST &&
cgit_ok hostrc "url=foo" >tmp
) &&
test_grep "<link rel=.vcs-git. href=.https://h'%22%3Cx%3E/foo. title=.foo Git repository.>" tmp &&
test_grep "href=.https://h'%22%3Cx%3E/foo.>https://h..<x>/foo</a>" tmp &&
test_grep ! "<x>" tmp
'
test_expect_success 'an empty clone url draws no clone heading' '
git init -q --bare repos/empty.git &&
{
echo "virtual-root=/" &&
echo "cache-size=0" &&
echo "clone-url=https://example.org/\$CGIT_REPO_URL" &&
echo "repo.url=foo" &&
echo "repo.path=$PWD/repos/foo/.git" &&
echo "repo.clone-url=" &&
echo "repo.url=empty" &&
echo "repo.path=$PWD/repos/empty.git" &&
echo "repo.clone-url=" &&
echo "repo.url=cloned" &&
echo "repo.path=$PWD/repos/empty.git"
} >emptyrc &&
cgit_ok emptyrc "url=foo" >tmp &&
test_grep ">commit 1<" tmp &&
test_grep ! "Clone</th>" tmp &&
cgit_ok emptyrc "url=empty" >tmp &&
test_grep "Repository seems to be empty" tmp &&
test_grep ! "Clone</th>" tmp &&
cgit_ok emptyrc "url=cloned" >tmp &&
grep "Clone</th>" tmp &&
grep "https://example.org/cloned</a>" tmp
'
test_expect_success 'set up a repository with a remote-tracking branch' '
mkrepo repos/remotes 2 &&
git -C repos/remotes update-ref refs/remotes/origin/topic HEAD~1 &&
cgitrc_repo remotesrc remotes repo.enable-remote-branches=1 &&
cgitrc_repo noremotesrc remotes
'
test_expect_success 'remote branches are shown when enabled' '
topic=$(git -C repos/remotes rev-parse origin/topic) &&
cgit_ok remotesrc "url=remotes/refs/" >tmp &&
test_grep "<tr class=.branch.><td><a href=./remotes/log/?h=origin/topic.>origin/topic</a>" tmp &&
test_grep "<option value=.origin/topic.>origin/topic</option>" tmp &&
cgit_ok remotesrc "url=remotes/log/" >tmp &&
test_grep "<a class=.remote-deco. href=./remotes/log/?id=$topic.>origin/topic</a>" tmp
'
test_expect_success 'remote branches stay hidden by default' '
cgit_ok noremotesrc "url=remotes/refs/" >tmp &&
test_grep "<tr class=.branch.><td><a href=./remotes/log/.>master</a>" tmp &&
test_grep ! "origin/topic" tmp &&
cgit_ok noremotesrc "url=remotes/log/" >tmp &&
test_grep ">commit 1<" tmp &&
test_grep ! "origin/topic" tmp
'
row_widths() {
sed -n "/<table class='list/,/<\/table>/p" "$1" | awk '
/^<tr[ >]/ {
width = 0
row = $0
while (match(row, /<t[dh][ >]/)) {
row = substr(row, RSTART + 3)
cell = substr(row, 1, index(row, ">"))
if (match(cell, /colspan=.[0-9]+/))
width += substr(cell, RSTART + 9, RLENGTH - 9)
else
width++
}
print width
}
'
}
test_widths() {
cgit_ok "${3:-colsrc}" "url=$1" >tmp &&
row_widths tmp | sort -u >actual &&
echo "$2" >expect &&
test_cmp expect actual
}
test_expect_success 'set up a repo cut short in every section' '
mkrepo repos/cols 3 &&
git -C repos/cols branch other HEAD~1 &&
git -C repos/cols tag one HEAD~1 &&
git -C repos/cols tag -a -m two two &&
{
echo "virtual-root=/" &&
echo "cache-size=0" &&
echo "summary-branches=1" &&
echo "summary-tags=1" &&
echo "summary-log=2" &&
echo "max-ref-count=1" &&
echo "clone-url=https://example.org/\$CGIT_REPO_URL" &&
echo "repo.url=none" &&
echo "repo.path=$PWD/repos/cols/.git" &&
echo "repo.url=lines" &&
echo "repo.path=$PWD/repos/cols/.git" &&
echo "repo.enable-log-linecount=1" &&
echo "repo.url=both" &&
echo "repo.path=$PWD/repos/cols/.git" &&
echo "repo.enable-log-filecount=1" &&
echo "repo.enable-log-linecount=1"
} >colsrc &&
cgit_ok colsrc "url=none" >tmp &&
grep "<tbody class=.tags.>" tmp &&
grep "<tbody class=.clone.>" tmp &&
test $(grep -c ">\[\.\.\.\]</a>" tmp) = 3
'
test_expect_success 'a summary without counts fills four columns' 'test_widths none 4'
test_expect_success 'a summary with one count fills four columns' 'test_widths lines 4'
test_expect_success 'a summary with both counts fills five columns' 'test_widths both 5'
test_expect_success 'a summary without a log fills four columns' '
sed "s/^summary-log=2$/summary-log=0/" colsrc >nologrc &&
test_widths both 4 nologrc
'
test_expect_success 'the refs page fills four columns' 'test_widths both/refs/ 4'
test_expect_success 'a page of branches fills four columns' 'test_widths both/refs/heads 4'
test_expect_success 'a page of tags fills four columns' 'test_widths both/refs/tags 4'
test_expect_success 'the tag table heads its second column for what it holds' '
cgit_ok colsrc "url=none/refs/" >tmp &&
grep "<th class=.left. scope=.col.>Tag</th><th class=.left. scope=.col.>Commit</th>" tmp &&
test_grep "<tr class=.tag.><td><a href=./none/tag/?h=[a-z]*.>[a-z]*</a></td><td><a href=./none/commit/?id=[0-9a-f]*.>commit " tmp &&
{
echo "snapshots=tar" &&
cat colsrc
} >snaprc &&
cgit_ok snaprc "url=none/refs/" >tmp &&
grep "<th class=.left. scope=.col.>Tag</th><th class=.left. scope=.col.>Download</th>" tmp &&
test_grep "<tr class=.tag.><td><a href=./none/tag/?h=[a-z]*.>[a-z]*</a></td><td><span class=.snapshot.><a href=./none/snapshot/none-[a-z]*\.tar.>" tmp
'
test_expect_success 'a lightweight tag row shows its commit author and age' '
mkrepo repos/light 1 &&
git -C repos/light tag light &&
cgitrc_repo lightrc light &&
cgit_ok lightrc "url=light/refs/tags" >tmp &&
test_grep "<tr class=.tag.><td><a href=./light/tag/?h=light.>light</a></td><td><a href=[^>]*>commit [0-9a-f]*\.\.\.</a></td><td class=.col-author.>A U Thor</td><td><time class=.age-years. datetime=.2005-04-01T11:14:15Z." tmp
'
test_done
|