1#!/bin/sh
2#
3# Copyright (c) 2007 Jakub Narebski
4#
5
6test_description='gitweb as standalone script (basic tests).
7
8This test runs gitweb (git web interface) as CGI script from
9commandline, and checks that it would not write any errors
10or warnings to log.'
11
12gitweb_init () {
13 cat >gitweb_config.perl <<EOF
14#!/usr/bin/perl
15
16# gitweb configuration for tests
17
18our \$version = "current";
19our \$GIT = "git";
20our \$projectroot = "$(pwd)";
21our \$home_link_str = "projects";
22our \$site_name = "[localhost]";
23our \$site_header = "";
24our \$site_footer = "";
25our \$home_text = "indextext.html";
26our @stylesheets = ("file:///$(pwd)/../../gitweb/gitweb.css");
27our \$logo = "file:///$(pwd)/../../gitweb/git-logo.png";
28our \$favicon = "file:///$(pwd)/../../gitweb/git-favicon.png";
29our \$projects_list = "";
30our \$export_ok = "";
31our \$strict_export = "";
32
33CGI::Carp::set_programname("gitweb/gitweb.cgi");
34EOF
35
36 cat >.git/description <<EOF
37$0 test repository
38EOF
39}
40
41gitweb_run () {
42 export GATEWAY_INTERFACE="CGI/1.1"
43 export HTTP_ACCEPT="*/*"
44 export REQUEST_METHOD="GET"
45 export QUERY_STRING=""$1""
46 export PATH_INFO=""$2""
47
48 export GITWEB_CONFIG=$(pwd)/gitweb_config.perl
49
50 # some of git commands write to STDERR on error, but this is not
51 # written to web server logs, so we are not interested in that:
52 # we are interested only in properly formatted errors/warnings
53 rm -f gitweb.log &&
54 perl -- $(pwd)/../../gitweb/gitweb.perl \
55 >/dev/null 2>gitweb.log &&
56 if grep -q -s "^[[]" gitweb.log >/dev/null; then false; else true; fi
57
58 # gitweb.log is left for debugging
59}
60
61. ./test-lib.sh
62
63perl -MEncode -e 'decode_utf8("", Encode::FB_CROAK)' >/dev/null 2>&1 || {
64 test_expect_success 'skipping gitweb tests, perl version is too old' :
65 test_done
66 exit
67}
68
69gitweb_init
70
71# ----------------------------------------------------------------------
72# no commits (empty, just initialized repository)
73
74test_expect_success \
75 'no commits: projects_list (implicit)' \
76 'gitweb_run'
77test_debug 'cat gitweb.log'
78
79test_expect_success \
80 'no commits: projects_index' \
81 'gitweb_run "a=project_index"'
82test_debug 'cat gitweb.log'
83
84test_expect_success \
85 'no commits: .git summary (implicit)' \
86 'gitweb_run "p=.git"'
87test_debug 'cat gitweb.log'
88
89test_expect_success \
90 'no commits: .git commit (implicit HEAD)' \
91 'gitweb_run "p=.git;a=commit"'
92test_debug 'cat gitweb.log'
93
94test_expect_success \
95 'no commits: .git commitdiff (implicit HEAD)' \
96 'gitweb_run "p=.git;a=commitdiff"'
97test_debug 'cat gitweb.log'
98
99test_expect_success \
100 'no commits: .git tree (implicit HEAD)' \
101 'gitweb_run "p=.git;a=tree"'
102test_debug 'cat gitweb.log'
103
104test_expect_success \
105 'no commits: .git heads' \
106 'gitweb_run "p=.git;a=heads"'
107test_debug 'cat gitweb.log'
108
109test_expect_success \
110 'no commits: .git tags' \
111 'gitweb_run "p=.git;a=tags"'
112test_debug 'cat gitweb.log'
113
114
115# ----------------------------------------------------------------------
116# initial commit
117
118test_expect_success \
119 'Make initial commit' \
120 'echo "Not an empty file." > file &&
121 git add file &&
122 git commit -a -m "Initial commit." &&
123 git branch b'
124
125test_expect_success \
126 'projects_list (implicit)' \
127 'gitweb_run'
128test_debug 'cat gitweb.log'
129
130test_expect_success \
131 'projects_index' \
132 'gitweb_run "a=project_index"'
133test_debug 'cat gitweb.log'
134
135test_expect_success \
136 '.git summary (implicit)' \
137 'gitweb_run "p=.git"'
138test_debug 'cat gitweb.log'
139
140test_expect_success \
141 '.git commit (implicit HEAD)' \
142 'gitweb_run "p=.git;a=commit"'
143test_debug 'cat gitweb.log'
144
145test_expect_success \
146 '.git commitdiff (implicit HEAD, root commit)' \
147 'gitweb_run "p=.git;a=commitdiff"'
148test_debug 'cat gitweb.log'
149
150test_expect_success \
151 '.git commitdiff_plain (implicit HEAD, root commit)' \
152 'gitweb_run "p=.git;a=commitdiff_plain"'
153test_debug 'cat gitweb.log'
154
155test_expect_success \
156 '.git commit (HEAD)' \
157 'gitweb_run "p=.git;a=commit;h=HEAD"'
158test_debug 'cat gitweb.log'
159
160test_expect_success \
161 '.git tree (implicit HEAD)' \
162 'gitweb_run "p=.git;a=tree"'
163test_debug 'cat gitweb.log'
164
165test_expect_success \
166 '.git blob (file)' \
167 'gitweb_run "p=.git;a=blob;f=file"'
168test_debug 'cat gitweb.log'
169
170test_expect_success \
171 '.git blob_plain (file)' \
172 'gitweb_run "p=.git;a=blob_plain;f=file"'
173test_debug 'cat gitweb.log'
174
175# ----------------------------------------------------------------------
176# nonexistent objects
177
178test_expect_success \
179 '.git commit (non-existent)' \
180 'gitweb_run "p=.git;a=commit;h=non-existent"'
181test_debug 'cat gitweb.log'
182
183test_expect_success \
184 '.git commitdiff (non-existent)' \
185 'gitweb_run "p=.git;a=commitdiff;h=non-existent"'
186test_debug 'cat gitweb.log'
187
188test_expect_success \
189 '.git commitdiff (non-existent vs HEAD)' \
190 'gitweb_run "p=.git;a=commitdiff;hp=non-existent;h=HEAD"'
191test_debug 'cat gitweb.log'
192
193test_expect_success \
194 '.git tree (0000000000000000000000000000000000000000)' \
195 'gitweb_run "p=.git;a=tree;h=0000000000000000000000000000000000000000"'
196test_debug 'cat gitweb.log'
197
198test_expect_success \
199 '.git tag (0000000000000000000000000000000000000000)' \
200 'gitweb_run "p=.git;a=tag;h=0000000000000000000000000000000000000000"'
201test_debug 'cat gitweb.log'
202
203test_expect_success \
204 '.git blob (non-existent)' \
205 'gitweb_run "p=.git;a=blob;f=non-existent"'
206test_debug 'cat gitweb.log'
207
208test_expect_success \
209 '.git blob_plain (non-existent)' \
210 'gitweb_run "p=.git;a=blob_plain;f=non-existent"'
211test_debug 'cat gitweb.log'
212
213
214# ----------------------------------------------------------------------
215# commitdiff testing (implicit, one implicit tree-ish)
216
217test_expect_success \
218 'commitdiff(0): root' \
219 'gitweb_run "p=.git;a=commitdiff"'
220test_debug 'cat gitweb.log'
221
222test_expect_success \
223 'commitdiff(0): file added' \
224 'echo "New file" > new_file &&
225 git add new_file &&
226 git commit -a -m "File added." &&
227 gitweb_run "p=.git;a=commitdiff"'
228test_debug 'cat gitweb.log'
229
230test_expect_success \
231 'commitdiff(0): mode change' \
232 'chmod a+x new_file &&
233 git commit -a -m "Mode changed." &&
234 gitweb_run "p=.git;a=commitdiff"'
235test_debug 'cat gitweb.log'
236
237test_expect_success \
238 'commitdiff(0): file renamed' \
239 'git mv new_file renamed_file &&
240 git commit -a -m "File renamed." &&
241 gitweb_run "p=.git;a=commitdiff"'
242test_debug 'cat gitweb.log'
243
244test_expect_success \
245 'commitdiff(0): file to symlink' \
246 'rm renamed_file &&
247 ln -s file renamed_file &&
248 git commit -a -m "File to symlink." &&
249 gitweb_run "p=.git;a=commitdiff"'
250test_debug 'cat gitweb.log'
251
252test_expect_success \
253 'commitdiff(0): file deleted' \
254 'git rm renamed_file &&
255 rm -f renamed_file &&
256 git commit -a -m "File removed." &&
257 gitweb_run "p=.git;a=commitdiff"'
258test_debug 'cat gitweb.log'
259
260test_expect_success \
261 'commitdiff(0): file copied / new file' \
262 'cp file file2 &&
263 git add file2 &&
264 git commit -a -m "File copied." &&
265 gitweb_run "p=.git;a=commitdiff"'
266test_debug 'cat gitweb.log'
267
268test_expect_success \
269 'commitdiff(0): mode change and modified' \
270 'echo "New line" >> file2 &&
271 chmod a+x file2 &&
272 git commit -a -m "Mode change and modification." &&
273 gitweb_run "p=.git;a=commitdiff"'
274test_debug 'cat gitweb.log'
275
276test_expect_success \
277 'commitdiff(0): renamed and modified' \
278 'cat >file2<<EOF &&
279Dominus regit me,
280et nihil mihi deerit.
281In loco pascuae ibi me collocavit,
282super aquam refectionis educavit me;
283animam meam convertit,
284deduxit me super semitas jusitiae,
285propter nomen suum.
286EOF
287 git commit -a -m "File added." &&
288 git mv file2 file3 &&
289 echo "Propter nomen suum." >> file3 &&
290 git commit -a -m "File rename and modification." &&
291 gitweb_run "p=.git;a=commitdiff"'
292test_debug 'cat gitweb.log'
293
294test_expect_success \
295 'commitdiff(0): renamed, mode change and modified' \
296 'git mv file3 file2 &&
297 echo "Propter nomen suum." >> file2 &&
298 chmod a+x file2 &&
299 git commit -a -m "File rename, mode change and modification." &&
300 gitweb_run "p=.git;a=commitdiff"'
301test_debug 'cat gitweb.log'
302
303# ----------------------------------------------------------------------
304# commitdiff testing (taken from t4114-apply-typechange.sh)
305
306test_expect_success 'setup typechange commits' '
307 echo "hello world" > foo &&
308 echo "hi planet" > bar &&
309 git update-index --add foo bar &&
310 git commit -m initial &&
311 git branch initial &&
312 rm -f foo &&
313 ln -s bar foo &&
314 git update-index foo &&
315 git commit -m "foo symlinked to bar" &&
316 git branch foo-symlinked-to-bar &&
317 rm -f foo &&
318 echo "how far is the sun?" > foo &&
319 git update-index foo &&
320 git commit -m "foo back to file" &&
321 git branch foo-back-to-file &&
322 rm -f foo &&
323 git update-index --remove foo &&
324 mkdir foo &&
325 echo "if only I knew" > foo/baz &&
326 git update-index --add foo/baz &&
327 git commit -m "foo becomes a directory" &&
328 git branch "foo-becomes-a-directory" &&
329 echo "hello world" > foo/baz &&
330 git update-index foo/baz &&
331 git commit -m "foo/baz is the original foo" &&
332 git branch foo-baz-renamed-from-foo
333 '
334
335test_expect_success \
336 'commitdiff(2): file renamed from foo to foo/baz' \
337 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-baz-renamed-from-foo"'
338test_debug 'cat gitweb.log'
339
340test_expect_success \
341 'commitdiff(2): file renamed from foo/baz to foo' \
342 'gitweb_run "p=.git;a=commitdiff;hp=foo-baz-renamed-from-foo;h=initial"'
343test_debug 'cat gitweb.log'
344
345test_expect_success \
346 'commitdiff(2): directory becomes file' \
347 'gitweb_run "p=.git;a=commitdiff;hp=foo-becomes-a-directory;h=initial"'
348test_debug 'cat gitweb.log'
349
350test_expect_success \
351 'commitdiff(2): file becomes directory' \
352 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-becomes-a-directory"'
353test_debug 'cat gitweb.log'
354
355test_expect_success \
356 'commitdiff(2): file becomes symlink' \
357 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-symlinked-to-bar"'
358test_debug 'cat gitweb.log'
359
360test_expect_success \
361 'commitdiff(2): symlink becomes file' \
362 'gitweb_run "p=.git;a=commitdiff;hp=foo-symlinked-to-bar;h=foo-back-to-file"'
363test_debug 'cat gitweb.log'
364
365test_expect_success \
366 'commitdiff(2): symlink becomes directory' \
367 'gitweb_run "p=.git;a=commitdiff;hp=foo-symlinked-to-bar;h=foo-becomes-a-directory"'
368test_debug 'cat gitweb.log'
369
370test_expect_success \
371 'commitdiff(2): directory becomes symlink' \
372 'gitweb_run "p=.git;a=commitdiff;hp=foo-becomes-a-directory;h=foo-symlinked-to-bar"'
373test_debug 'cat gitweb.log'
374
375# ----------------------------------------------------------------------
376# commit, commitdiff: merge, large
377test_expect_success \
378 'Create a merge' \
379 'git checkout b &&
380 echo "Branch" >> b &&
381 git add b &&
382 git commit -a -m "On branch" &&
383 git checkout master &&
384 git pull . b'
385
386test_expect_success \
387 'commit(0): merge commit' \
388 'gitweb_run "p=.git;a=commit"'
389test_debug 'cat gitweb.log'
390
391test_expect_success \
392 'commitdiff(0): merge commit' \
393 'gitweb_run "p=.git;a=commitdiff"'
394test_debug 'cat gitweb.log'
395
396test_expect_success \
397 'Prepare large commit' \
398 'git checkout b &&
399 echo "To be changed" > 01-change &&
400 echo "To be renamed" > 02-pure-rename-from &&
401 echo "To be deleted" > 03-delete &&
402 echo "To be renamed and changed" > 04-rename-from &&
403 echo "To have mode changed" > 05-mode-change &&
404 echo "File to symlink" > 06-file-or-symlink &&
405 echo "To be changed and have mode changed" > 07-change-mode-change &&
406 git add 0* &&
407 git commit -a -m "Prepare large commit" &&
408 echo "Changed" > 01-change &&
409 git mv 02-pure-rename-from 02-pure-rename-to &&
410 git rm 03-delete && rm -f 03-delete &&
411 echo "A new file" > 03-new &&
412 git add 03-new &&
413 git mv 04-rename-from 04-rename-to &&
414 echo "Changed" >> 04-rename-to &&
415 chmod a+x 05-mode-change &&
416 rm -f 06-file-or-symlink && ln -s 01-change 06-file-or-symlink &&
417 echo "Changed and have mode changed" > 07-change-mode-change &&
418 chmod a+x 07-change-mode-change &&
419 git commit -a -m "Large commit" &&
420 git checkout master'
421
422test_expect_success \
423 'commit(1): large commit' \
424 'gitweb_run "p=.git;a=commit;h=b"'
425test_debug 'cat gitweb.log'
426
427test_expect_success \
428 'commitdiff(1): large commit' \
429 'gitweb_run "p=.git;a=commitdiff;h=b"'
430test_debug 'cat gitweb.log'
431
432# ----------------------------------------------------------------------
433# tags testing
434
435test_expect_success \
436 'tags: list of different types of tags' \
437 'git checkout master &&
438 git tag -a -m "Tag commit object" tag-commit HEAD &&
439 git tag -a -m "" tag-commit-nomessage HEAD &&
440 git tag -a -m "Tag tag object" tag-tag tag-commit &&
441 git tag -a -m "Tag tree object" tag-tree HEAD^{tree} &&
442 git tag -a -m "Tag blob object" tag-blob HEAD:file &&
443 git tag lightweight/tag-commit HEAD &&
444 git tag lightweight/tag-tag tag-commit &&
445 git tag lightweight/tag-tree HEAD^{tree} &&
446 git tag lightweight/tag-blob HEAD:file &&
447 gitweb_run "p=.git;a=tags"'
448test_debug 'cat gitweb.log'
449
450test_expect_success \
451 'tag: Tag to commit object' \
452 'gitweb_run "p=.git;a=tag;h=tag-commit"'
453test_debug 'cat gitweb.log'
454
455test_expect_success \
456 'tag: on lightweight tag (invalid)' \
457 'gitweb_run "p=.git;a=tag;h=lightweight/tag-commit"'
458test_debug 'cat gitweb.log'
459
460# ----------------------------------------------------------------------
461# logs
462
463test_expect_success \
464 'logs: log (implicit HEAD)' \
465 'gitweb_run "p=.git;a=log"'
466test_debug 'cat gitweb.log'
467
468test_expect_success \
469 'logs: shortlog (implicit HEAD)' \
470 'gitweb_run "p=.git;a=shortlog"'
471test_debug 'cat gitweb.log'
472
473test_expect_success \
474 'logs: history (implicit HEAD, file)' \
475 'gitweb_run "p=.git;a=history;f=file"'
476test_debug 'cat gitweb.log'
477
478# ----------------------------------------------------------------------
479# feed generation
480
481test_expect_success \
482 'feeds: OPML' \
483 'gitweb_run "a=opml"'
484test_debug 'cat gitweb.log'
485
486test_expect_success \
487 'feed: RSS' \
488 'gitweb_run "p=.git;a=rss"'
489test_debug 'cat gitweb.log'
490
491test_expect_success \
492 'feed: Atom' \
493 'gitweb_run "p=.git;a=atom"'
494test_debug 'cat gitweb.log'
495
496# ----------------------------------------------------------------------
497# encoding/decoding
498
499test_expect_success \
500 'encode(commit): utf8' \
501 '. ../t3901-utf8.txt &&
502 echo "UTF-8" >> file &&
503 git add file &&
504 git commit -F ../t3900/1-UTF-8.txt &&
505 gitweb_run "p=.git;a=commit"'
506test_debug 'cat gitweb.log'
507
508test_expect_success \
509 'encode(commit): iso-8859-1' \
510 '. ../t3901-8859-1.txt &&
511 echo "ISO-8859-1" >> file &&
512 git add file &&
513 git config i18n.commitencoding ISO-8859-1 &&
514 git commit -F ../t3900/ISO-8859-1.txt &&
515 git config --unset i18n.commitencoding &&
516 gitweb_run "p=.git;a=commit"'
517test_debug 'cat gitweb.log'
518
519test_expect_success \
520 'encode(log): utf-8 and iso-8859-1' \
521 'gitweb_run "p=.git;a=log"'
522test_debug 'cat gitweb.log'
523
524test_done