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
|
test_description='Check the repository scan'
CGIT_TEST_NO_CREATE_REPOS=YesPlease
. ./setup.sh
scan_index() {
cgitrc_file=$1
shift
{
echo "virtual-root=/" &&
echo "cache-size=0" &&
printf '%s\n' "$@"
} >"$cgitrc_file" &&
cgit_ok "$cgitrc_file" "url="
}
test_expect_success 'a scan from the command line prints its list sorted by url' '
mkrepo cmdscan/x 1 &&
mkrepo cmdscan/x.git 1 &&
mv cmdscan/x/.git cmdscan/x/a.git &&
echo "snapshots=zip" >cmdscan/x.git/.git/cgitrc &&
cgit --scan-path="$PWD/cmdscan" >scan.out &&
sed -n "s/^repo.url=//p" scan.out >urls &&
test_write_lines x.git x/a.git >expect &&
test_cmp expect urls &&
test_grep "^repo.snapshots=\\.zip$" scan.out &&
cgit --scan-tree="$PWD/cmdscan" >tree.out &&
test_cmp scan.out tree.out
'
test_expect_success 'the command line can stand in for the web server' '
mkrepo repos/foo 1 &&
cgitrc_repo cmdrc foo &&
CGIT_CONFIG="$PWD/cmdrc" cgit --nohttp --query="url=foo/log/" >nohttp.out &&
test_grep ! "^Status:" nohttp.out &&
test_grep "data-page=.log. data-repo=.foo." nohttp.out &&
sed "s/^cache-size=0$/cache-size=64/" cmdrc >cmdcacherc &&
mkdir cmdcache &&
CGIT_CONFIG="$PWD/cmdcacherc" cgit --cache="$PWD/cmdcache" --query="url=foo/log/" >cache.out &&
test_grep "^Status: 200" cache.out &&
ls cmdcache >slots &&
test_line_count = 1 slots
'
test_expect_success 'a repository holding noweb is left out' '
mkrepo noweb/shown 1 &&
mkrepo noweb/hidden 1 &&
touch noweb/hidden/.git/noweb &&
scan_index nowebrc "scan-path=$PWD/noweb" >tmp &&
test_grep ">shown</a>" tmp &&
test_grep ! ">hidden</a>" tmp
'
test_expect_success 'a dot directory is scanned only with scan-hidden-path' '
mkrepo dotted/shown 1 &&
mkrepo dotted/.secret 1 &&
scan_index dottedrc "scan-path=$PWD/dotted" >tmp &&
test_grep ">shown</a>" tmp &&
test_grep ! ">.secret</a>" tmp &&
scan_index dottedrc "scan-hidden-path=1" "scan-path=$PWD/dotted" >tmp &&
test_grep ">.secret</a>" tmp
'
test_expect_success 'section-from-path files a repository under its path' '
mkrepo sectioned/top/mid/repo 1 &&
mkrepo sectioned/solo 1 &&
scan_index sectionrc "section-from-path=1" "scan-path=$PWD/sectioned" >tmp &&
test_grep "<td colspan=.[0-9]*. class=.reposection.>top</td>" tmp &&
test_grep "href=./top/mid/repo/.>mid/repo</a>" tmp &&
scan_index sectionrc "section-from-path=-1" "scan-path=$PWD/sectioned" >tmp &&
test_grep "<td colspan=.[0-9]*. class=.reposection.>top/mid</td>" tmp &&
test_grep "href=./top/mid/repo/.>repo</a>" tmp &&
test_grep "href=./solo/.>solo</a>" tmp &&
scan_index sectionrc "scan-path=$PWD/sectioned" >tmp &&
test_grep ! "class=.reposection." tmp &&
test_grep "href=./top/mid/repo/.>top/mid/repo</a>" tmp
'
test_expect_success 'a project list scans only what it names, in its order' '
mkrepo listed/one 1 &&
mkrepo listed/two 1 &&
mkrepo listed/unlisted 1 &&
test_write_lines two one >projects &&
mkdir listcache &&
{
echo "virtual-root=/" &&
echo "cache-root=$PWD/listcache" &&
echo "cache-size=64" &&
echo "cache-index-ttl=0" &&
echo "project-list=$PWD/projects" &&
echo "scan-path=$PWD/listed"
} >listrc &&
cgit_ok listrc "url=" >tmp &&
test_grep ">one</a>" tmp &&
test_grep ">two</a>" tmp &&
test_grep ! ">unlisted</a>" tmp &&
sed -n "s/^repo.url=//p" listcache/rc-* >urls &&
test_write_lines two one >expect &&
test_cmp expect urls
'
test_expect_success 'a scan reads the gitweb settings of a repository' '
mkrepo gitweb/repo 1 &&
git -C gitweb/repo config gitweb.owner "Some Owner" &&
git -C gitweb/repo config gitweb.description "Described by gitweb" &&
git -C gitweb/repo config gitweb.category "Category" &&
scan_index gitwebrc "enable-git-config=1" "scan-path=$PWD/gitweb" >tmp &&
test_grep "<td colspan=.[0-9]*. class=.reposection.>Category</td>" tmp &&
test_grep ">Described by gitweb</a>" tmp &&
test_grep "Some Owner" tmp &&
scan_index gitwebrc "scan-path=$PWD/gitweb" >tmp &&
test_grep ! "Described by gitweb" tmp &&
test_grep ! "Some Owner" tmp
'
test_expect_success 'a nested repository url goes to the deepest match' '
mkrepo nest/outer 1 &&
mkrepo nest/inner 2 &&
{
echo "virtual-root=/" &&
echo "cache-size=0" &&
echo "repo.url=a" &&
echo "repo.path=$PWD/nest/outer/.git" &&
echo "repo.url=a/b" &&
echo "repo.path=$PWD/nest/inner/.git"
} >nestrc &&
cgit_ok nestrc "url=a/b/log/" >tmp &&
test_grep "data-page=.log. data-repo=.a/b." tmp &&
test_grep "commit 2" tmp &&
cgit_ok nestrc "url=a/log/" >tmp &&
test_grep "data-page=.log. data-repo=.a." tmp &&
test_grep ! "commit 2" tmp &&
cgit_ok nestrc "url=a/b/tree/file-1" >tmp &&
test_grep "data-page=.tree. data-repo=.a/b." tmp
'
test_done
|