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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
|
LF='
'
test_argv="${LF}--root=trash"
while test $# != 0
do
case "$1" in
--va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind)
cgit_valgrind=t
test_argv="$test_argv${LF}--verbose"
;;
*)
test_argv="$test_argv$LF$1"
;;
esac
shift
done
OLDIFS=$IFS
IFS=$LF
set -- $test_argv
IFS=$OLDIFS
TEST_DIRECTORY=$(pwd)/../vendor/git/t
TEST_OUTPUT_DIRECTORY=$(pwd)
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_NO_CREATE_REPO=YesPlease
. "$TEST_DIRECTORY"/test-lib.sh
for cgit_variable in SCRIPT_NAME PATH_INFO QUERY_STRING HTTP_HOST HTTPS NO_HTTP \
REQUEST_METHOD SERVER_NAME SERVER_PORT HTTP_COOKIE HTTP_REFERER CONTENT_LENGTH \
CONTENT_TYPE REMOTE_ADDR REMOTE_USER CGIT_CONFIG CGIT_SCINTILLUA_PATH \
LUA_INIT LUA_INIT_5_2 LUA_INIT_5_3 LUA_INIT_5_4 LUA_INIT_5_5
do
unset $cgit_variable
done
unset cgit_variable
umask 022
if test -n "$cgit_valgrind"
then
GIT_VALGRIND="$TEST_DIRECTORY/valgrind"
CGIT_VALGRIND=$(cd "$TEST_OUTPUT_DIRECTORY/valgrind" && pwd)
PATH="$CGIT_VALGRIND/bin:$PATH"
export GIT_VALGRIND CGIT_VALGRIND
else
PATH="$TEST_OUTPUT_DIRECTORY/../build:$PATH"
fi
FILTER_DIRECTORY=$(cd "$TEST_OUTPUT_DIRECTORY/filters" && pwd)
cgit_version=$(cgit --version) ||
BAIL_OUT "cgit --version failed, so the binary under test is broken"
case "$cgit_version" in
*"[+] Lua scripting"*)
CGIT_HAS_LUA=1
test_set_prereq CGIT_LUA
;;
*)
CGIT_HAS_LUA=0
;;
esac
cgit_flags="$TEST_OUTPUT_DIRECTORY/../build/CGIT-CFLAGS"
if test -z "$cgit_valgrind" && test -f "$cgit_flags"
then
if grep -e "-DNO_LUA" "$cgit_flags" >/dev/null
then
test "$CGIT_HAS_LUA" = 0 ||
BAIL_OUT "cgit reports Lua but was built with NO_LUA"
else
test "$CGIT_HAS_LUA" = 1 ||
BAIL_OUT "cgit was built with Lua but its version does not say so"
fi
fi
unset cgit_version cgit_flags
mkrepo() {
mkrepo_commits=$2
mkrepo_variant=$3
test_create_repo "$1" &&
(
cd "$1" &&
n=1 &&
while test $n -le $mkrepo_commits
do
echo $n >file-$n &&
git add file-$n &&
git commit -m "commit $n" &&
n=$((n + 1)) || exit 1
done &&
case "$mkrepo_variant" in
testplus)
echo "hello" >a+b &&
git add a+b &&
git commit -m "add a+b" &&
git branch "1+2"
;;
commit-graph)
git commit-graph write
;;
esac
)
}
setup_repos() {
mkdir cache &&
mkrepo repos/foo 5 >/dev/null &&
mkrepo repos/bar 50 commit-graph >/dev/null &&
mkrepo repos/foo+bar 10 testplus >/dev/null &&
mkrepo "repos/with space" 2 >/dev/null &&
mkrepo repos/filter 5 testplus >/dev/null &&
cat >cgitrc <<EOF &&
virtual-root=/
cache-root=$PWD/cache
cache-size=1021
enable-cache-list=1
snapshots=tar tar.gz tar.bz2 tar.lz tar.xz tar.zst zip
enable-log-filecount=1
enable-log-linecount=1
summary-log=5
summary-branches=5
summary-tags=5
clone-url=git://example.org/\$CGIT_REPO_URL.git
repo.url=foo
repo.path=$PWD/repos/foo/.git
# No repo.desc here, and the description file holds git's placeholder, so
# the [no description] default gets exercised.
repo.url=bar
repo.path=$PWD/repos/bar/.git
repo.desc=the bar repo
repo.url=foo+bar
repo.path=$PWD/repos/foo+bar/.git
repo.desc=the foo+bar repo
repo.url=with space
repo.path=$PWD/repos/with space/.git
repo.desc=spaced repo
repo.url=filter-exec
repo.path=$PWD/repos/filter/.git
repo.desc=filtered repo
repo.about-filter=exec:$FILTER_DIRECTORY/dump.sh
repo.commit-filter=exec:$FILTER_DIRECTORY/dump.sh
repo.email-filter=exec:$FILTER_DIRECTORY/dump.sh
repo.source-filter=exec:$FILTER_DIRECTORY/dump.sh
repo.readme=master:a+b
EOF
if test "$CGIT_HAS_LUA" -eq 1
then
cat >>cgitrc <<EOF
repo.url=filter-lua
repo.path=$PWD/repos/filter/.git
repo.desc=filtered repo
repo.about-filter=lua:$FILTER_DIRECTORY/dump.lua
repo.commit-filter=lua:$FILTER_DIRECTORY/dump.lua
repo.email-filter=lua:$FILTER_DIRECTORY/dump.lua
repo.source-filter=lua:$FILTER_DIRECTORY/dump.lua
repo.readme=master:a+b
EOF
fi
}
cgitrc_repo() {
cgitrc_file=$1
cgitrc_url=$2
shift 2
cgitrc_path="repo.path=$PWD/repos/$cgitrc_url/.git"
cgitrc_before=
cgitrc_after=
for cgitrc_setting
do
case "$cgitrc_setting" in
repo.path=*)
cgitrc_path=$cgitrc_setting
;;
repo.*)
cgitrc_after="$cgitrc_after$cgitrc_setting$LF"
;;
*)
cgitrc_before="$cgitrc_before$cgitrc_setting$LF"
;;
esac
done
printf '%s' "virtual-root=/$LF" "cache-size=0$LF" "$cgitrc_before" \
"repo.url=$cgitrc_url$LF" "$cgitrc_path$LF" "$cgitrc_after" >"$cgitrc_file"
}
cgitrc_copy() {
cgitrc_file=$1
shift
{
test $# = 0 || printf '%s\n' "$@"
sed "s/^cache-size=.*/cache-size=0/" cgitrc
} >"$cgitrc_file"
}
cgit_rc() {
CGIT_CONFIG="$PWD/$1" QUERY_STRING="$2" cgit
}
cgit_query() {
cgit_rc cgitrc "$1"
}
cgit_url() {
cgit_rc cgitrc "url=$1"
}
cgit_ok() {
cgit_ok_flags=$-
set +x
cgit_rc "$@" >cgit-ok.out 2>cgit-ok.err
cgit_ok_status=$?
case $cgit_ok_flags in
*x*)
set -x
;;
esac
cat cgit-ok.out
cat cgit-ok.err >&2
if test "$cgit_ok_status" != 0
then
echo "cgit exited with status $cgit_ok_status" >&2
return 1
elif test -s cgit-ok.err
then
echo "cgit logged an error" >&2
return 1
elif ! sed -n 1p cgit-ok.out | grep "^Status: 200" >/dev/null
then
echo "cgit answered $(sed -n 1p cgit-ok.out)" >&2
return 1
elif sed "/^$/q" cgit-ok.out | grep -i "^Content-Type: text/html" >/dev/null &&
! grep "</html>" cgit-ok.out >/dev/null
then
echo "the page stops short of </html>" >&2
return 1
fi
}
cgit_ok_url() {
sed "s/^cache-size=.*/cache-size=0/" cgitrc >cgitrc-ok &&
cgit_ok cgitrc-ok "url=$1"
}
strip_headers() {
while read -r line
do
test -z "$line" && break
done
cat
}
if test -z "$CGIT_TEST_NO_CREATE_REPOS"
then
setup_repos || BAIL_OUT "the shared repositories could not be built"
fi
|