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
|
test_description='Check content on index page'
. ./setup.sh
test_expect_success 'generate index page' 'cgit_url "" >tmp'
test_expect_success 'find foo repo' 'grep ">foo</a>" tmp'
test_expect_success 'find foo description' 'grep "\[no description\]" 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 'no tree-link' '! grep "foo/tree" tmp'
test_expect_success 'no log-link' '! grep "foo/log" tmp'
test_expect_success 'index links lead to the summary, log and tree' '
cgitrc_copy links-cgitrc enable-index-links=1 &&
cgit_rc links-cgitrc "url=" >tmp &&
grep ">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_rc 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 'a cut description keeps whole characters' '
{
echo "max-repodesc-length=10" &&
sed "s/^cache-size=.*/cache-size=0/" cgitrc &&
echo "repo.url=mb" &&
echo "repo.path=$PWD/repos/foo/.git" &&
echo "repo.desc=日本語の説明文です"
} >descrc &&
cgit_rc descrc "url=" >tmp &&
grep ">日本語\.\.\.</a>" tmp
'
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 'the index sorts by a column on request' '
cgit_query "s=name" >tmp &&
bar=$(grep -n ">bar</a>" tmp | head -1 | cut -d: -f1) &&
foo=$(grep -n ">foo</a>" tmp | head -1 | cut -d: -f1) &&
test "$bar" -lt "$foo" &&
for s in desc owner idle
do
cgit_query "s=$s" >tmp &&
grep ">foo</a>" tmp || return 1
done
'
test_expect_success 'the sorted column heading says which way it runs' '
for s in name desc owner idle
do
cgit_query "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_url "" >tmp &&
! 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_rc 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_rc 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 &&
{
echo "virtual-root=/" &&
echo "cache-size=0" &&
echo "repo.url=described" &&
echo "repo.path=$PWD/repos/described/.git" &&
echo "repo.url=overridden" &&
echo "repo.path=$PWD/repos/described/.git" &&
echo "repo.desc=from cgitrc" &&
echo "repo.url=placeholder" &&
echo "repo.path=$PWD/repos/foo/.git"
} >describedrc &&
cgit_rc 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 &&
! grep "second line" tmp &&
cgit_rc describedrc "url=described/" >tmp &&
grep "<meta name=.description. content=.told by the file.>" tmp
'
test_done
|