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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
test_description='Check content on index page'
. ./setup.sh
test_expect_success 'generate index page' 'cgit_ok_url "" >tmp'
test_expect_success 'find foo repo' 'grep ">foo</a>" tmp'
test_expect_success 'find foo description' 'grep "href=./foo/.>\[no description\]</a>" tmp'
test_expect_success 'find bar repo' 'grep ">bar</a>" tmp'
test_expect_success 'find bar description' 'grep "the bar repo" tmp'
test_expect_success 'find foo+bar repo' 'grep ">foo+bar<" tmp'
test_expect_success 'verify foo+bar links' 'test $(grep -o "href=./foo%2Bbar/." tmp | wc -l) = 2'
test_expect_success 'verify "with%20space" links' 'test $(grep -o "href=./with%20space/." tmp | wc -l) = 2'
test_expect_success 'the index links no tree or log by default' '
cgit_ok_url "" >tmp &&
test_grep ">foo</a>" tmp &&
test_grep ! "foo/tree" tmp &&
test_grep ! "foo/log" tmp
'
test_expect_success 'index links lead to the summary, log and tree' '
cgitrc_copy linksrc enable-index-links=1 &&
cgit_ok linksrc "url=" >tmp &&
grep "<a class=.button. href=./foo/.>summary</a><a class=.button. href=./foo/log/.>log</a>" tmp &&
grep "href=./foo/log/.>log</a><a class=.button. href=./foo/tree/.>tree<" tmp
'
test_expect_success 'each css and js entry gets a link of its own' '
cgitrc_copy headrc css=/a.css css=/b.css js=/a.js js= js=/b.js &&
cgit_ok headrc "url=" >tmp &&
grep "<link rel=.stylesheet. href=./a.css.>" tmp &&
grep "<link rel=.stylesheet. href=./b.css.>" tmp &&
grep "<script src=" tmp >scripts &&
test_line_count = 2 scripts &&
grep "/a.js" scripts &&
grep "/b.js" scripts
'
test_expect_success 'root-readme without a filter is its own page, as written' '
echo "<b>site</b>" >root.html &&
cgitrc_copy rootrc "root-readme=$PWD/root.html" &&
cgit_ok rootrc "url=" >tmp &&
test_grep "<li><a title=.About this site. href=./?p=about.>about</a>" tmp &&
test_grep ! "<b>site</b>" tmp &&
cgit_ok rootrc "p=about" >tmp &&
test_grep "^<b>site</b>$" tmp
'
test_expect_success 'a cut description keeps whole characters' '
cgitrc_copy descrc max-repodesc-length=10 &&
{
echo "repo.url=mb" &&
echo "repo.path=$PWD/repos/foo/.git" &&
echo "repo.desc=日本語の説明文です"
} >>descrc &&
cgit_ok descrc "url=" >tmp &&
grep ">日本語\.\.\.</a>" tmp
'
test_expect_success 'a description limit of 0 or less leaves the ellipsis alone' '
for limit in 0 -1
do
cgitrc_copy limitrc max-repodesc-length=$limit &&
cgit_ok limitrc "url=" >tmp &&
test_grep "href=./bar/.>\.\.\.</a>" tmp || return 1
done
'
test_expect_success 'a url matching no repository says so' '
cgit_url "nonexistent/tree/" >tmp &&
grep "^Status: 404" tmp &&
grep "<div class=.error.>Nothing matches this url</div>" tmp &&
cgit_query "q=nonexistent" >tmp &&
grep "^Status: 404" tmp &&
grep "<div class=.error.>No repositories found</div>" tmp
'
test_expect_success 'a search finding nothing under a url prefix says so' '
cgitrc_repos prefixrc \
repo.url=a/x "repo.path=$PWD/repos/foo/.git" \
repo.url=a/y "repo.path=$PWD/repos/foo/.git" &&
cgit_ok prefixrc "url=a/" >tmp &&
test_grep ">a/x</a>" tmp &&
test_grep ">a/y</a>" tmp &&
cgit_rc prefixrc "url=a/&q=zzz" >tmp &&
test_grep "^Status: 404" tmp &&
test_grep "<div class=.error.>No repositories found</div>" tmp
'
test_index_order() {
cgit_ok orderrc "$1" >tmp &&
sed -n "s/.*class=.col-name toplevel-repo.><a href=.\/.\/.>\(.\)<\/a>.*/\1/p" tmp >order &&
shift &&
printf "%s\n" "$@" >expect &&
test_cmp expect order
}
test_expect_success 'set up repositories each column sorts apart' '
for name in b a c
do
git init -q --bare "orders/$name.git" &&
mkdir "orders/$name.git/info/web" || return 1
done &&
echo "2005-04-03 10:00:00 +0000" >orders/a.git/info/web/last-modified &&
echo "2005-04-05 10:00:00 +0000" >orders/b.git/info/web/last-modified &&
echo "2005-04-01 10:00:00 +0000" >orders/c.git/info/web/last-modified &&
cgitrc_repos orderrc \
repo.url=c "repo.path=$PWD/orders/c.git" \
"repo.desc=first by description" "repo.owner=second owner" \
repo.url=a "repo.path=$PWD/orders/a.git" \
"repo.desc=third by description" "repo.owner=first owner" \
repo.url=b "repo.path=$PWD/orders/b.git" \
"repo.desc=second by description" "repo.owner=third owner" &&
test_index_order "url=" c a b
'
test_expect_success 'the index sorts by each column on request' '
test_index_order "s=name" a b c &&
test_index_order "s=desc" c b a &&
test_index_order "s=owner" a c b &&
test_index_order "s=idle" b a c
'
test_expect_success 'the idle column shows the date the age file holds' '
cgit_ok orderrc "url=" >tmp &&
test_grep "<td class=.col-idle.><time class=.age-years. datetime=.2005-04-05T10:00:00Z." tmp
'
test_expect_success 'a negative offset shows the first page of the index' '
{
echo "max-repo-count=2" &&
cat orderrc
} >pagedrc &&
printf "%s\n" c a >expect &&
for ofs in 0 -1 -100
do
cgit_ok pagedrc "ofs=$ofs" >tmp &&
sed -n "s/.*class=.col-name toplevel-repo.><a href=.\/.\/.>\(.\)<\/a>.*/\1/p" tmp >order &&
test_cmp expect order &&
test_grep "<a title=.Page 1. class=.current. aria-current=.page. href=./.>\[1\]</a>" tmp || return 1
done
'
test_section_order() {
cgit_ok "$1" "$2" >tmp &&
sed -n -e "s/.*<td colspan=.5. class=.reposection.>\(.*\)<\/td>.*/[\1]/p" \
-e "s/.*class=.col-name sublevel-repo.><a href=[^>]*>\([^<]*\)<\/a>.*/\1/p" tmp >order &&
shift 2 &&
printf "%s\n" "$@" >expect &&
test_cmp expect order
}
test_expect_success 'set up repositories in two sections' '
for name in z1 a2 a3 a1
do
git init -q --bare "sections/$name.git" &&
mkdir "sections/$name.git/info/web" || return 1
done &&
echo "2005-04-01 10:00:00 +0000" >sections/a2.git/info/web/last-modified &&
echo "2005-04-05 10:00:00 +0000" >sections/a3.git/info/web/last-modified &&
echo "2005-04-03 10:00:00 +0000" >sections/a1.git/info/web/last-modified &&
cgitrc_repos sectionrc enable-index-links=1 \
section=zeta \
repo.url=z1 "repo.path=$PWD/sections/z1.git" \
section=alpha \
repo.url=a2 "repo.path=$PWD/sections/a2.git" \
repo.url=a3 "repo.path=$PWD/sections/a3.git" \
repo.url=a1 "repo.path=$PWD/sections/a1.git" &&
{
echo "section-sort=1" &&
cat sectionrc
} >sectionsortrc &&
{
echo "repository-sort=age" &&
cat sectionsortrc
} >sectionagerc
'
test_expect_success 'the index keeps the cgitrc order of sections' '
test_section_order sectionrc "url=" "[zeta]" z1 "[alpha]" a2 a3 a1
'
test_expect_success 'section-sort orders the sections and their repositories' '
test_section_order sectionsortrc "url=" "[alpha]" a1 a2 a3 "[zeta]" z1 &&
test_section_order sectionagerc "url=" "[alpha]" a3 a1 a2 "[zeta]" z1
'
test_expect_success 'an index sorted by a column drops the sections' '
cgit_ok sectionrc "s=name" >tmp &&
test_grep "class=.col-name toplevel-repo.><a href=./a1/.>a1</a>" tmp &&
test_grep ! "reposection" tmp &&
test_grep ! "sublevel-repo" tmp
'
test_expect_success 'the sorted column heading says which way it runs' '
for s in name desc owner idle
do
cgit_ok_url "&s=$s" >tmp &&
grep "<th class=.left col-$s. scope=.col. aria-sort=.ascending.>" tmp &&
test $(grep -o "aria-sort" tmp | wc -l) = 1 || return 1
done &&
cgit_ok_url "" >tmp &&
test_grep "<th class=.left col-name. scope=.col.><a href=./?s=name.>Name</a></th>" tmp &&
test_grep ! "aria-sort" tmp
'
test_expect_success 'a scan lists repositories in path order' '
for name in proj9 Proj3 proj7 proj1 Proj5 proj8 proj2 proj6 proj4
do
git init -q --bare "sorted/$name.git" || return 1
done &&
{
echo "virtual-root=/" &&
echo "cache-size=0" &&
echo "scan-path=$PWD/sorted"
} >sortrc &&
{
echo "case-sensitive-sort=0" &&
cat sortrc
} >foldrc &&
cgit_ok sortrc "url=" >tmp &&
sed -n "s/.*>\([Pp]roj[0-9]\)\.git<\/a>.*/\1/p" tmp >order &&
printf "%s\n" Proj3 Proj5 proj1 proj2 proj4 proj6 proj7 proj8 proj9 >expect &&
test_cmp expect order &&
cgit_ok foldrc "url=" >tmp &&
sed -n "s/.*>\([Pp]roj[0-9]\)\.git<\/a>.*/\1/p" tmp >order &&
printf "%s\n" proj1 proj2 Proj3 proj4 Proj5 proj6 proj7 proj8 proj9 >expect &&
test_cmp expect order
'
test_expect_success 'a repository without repo.desc reads its description file' '
mkrepo repos/described 1 &&
printf "told by the file\nsecond line\n" >repos/described/.git/description &&
cgitrc_repos describedrc \
repo.url=described "repo.path=$PWD/repos/described/.git" \
repo.url=overridden "repo.path=$PWD/repos/described/.git" \
"repo.desc=from cgitrc" \
repo.url=placeholder "repo.path=$PWD/repos/foo/.git" &&
cgit_ok describedrc "url=" >tmp &&
grep "href=./described/.>told by the file</a>" tmp &&
grep "href=./overridden/.>from cgitrc</a>" tmp &&
grep "href=./placeholder/.>\[no description\]</a>" tmp &&
test_grep ! "second line" tmp &&
cgit_ok describedrc "url=described/" >tmp &&
grep "<meta name=.description. content=.told by the file.>" tmp
'
test_expect_success 'the search and the sort see a description file' '
cgit_ok describedrc "q=told" >tmp &&
test_grep "href=./described/.>told by the file</a>" tmp &&
test_grep ! ">overridden</a>" tmp &&
cgit_ok describedrc "s=desc" >tmp &&
sed -n "s/.*class=.col-name toplevel-repo.><a href=.\/[a-z]*\/.>\([a-z]*\)<\/a>.*/\1/p" tmp >order &&
printf "%s\n" placeholder overridden described >expect &&
test_cmp expect order
'
test_done
|