Code

3dc261d80bc8f83c26355c9125d1b98923d885ff
[git.git] / t / t9500-gitweb-standalone-no-errors.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Jakub Narebski
4 #
6 test_description='gitweb as standalone script (basic tests).
8 This test runs gitweb (git web interface) as CGI script from
9 commandline, and checks that it would not write any errors
10 or warnings to log.'
12 gitweb_init () {
13         cat >gitweb_config.perl <<EOF
14 #!/usr/bin/perl
16 # gitweb configuration for tests
18 our \$version = "current";
19 our \$GIT = "git";
20 our \$projectroot = "$(pwd)";
21 our \$project_maxdepth = 8;
22 our \$home_link_str = "projects";
23 our \$site_name = "[localhost]";
24 our \$site_header = "";
25 our \$site_footer = "";
26 our \$home_text = "indextext.html";
27 our @stylesheets = ("file:///$(pwd)/../../gitweb/gitweb.css");
28 our \$logo = "file:///$(pwd)/../../gitweb/git-logo.png";
29 our \$favicon = "file:///$(pwd)/../../gitweb/git-favicon.png";
30 our \$projects_list = "";
31 our \$export_ok = "";
32 our \$strict_export = "";
34 EOF
36         cat >.git/description <<EOF
37 $0 test repository
38 EOF
39 }
41 gitweb_run () {
42         GATEWAY_INTERFACE="CGI/1.1"
43         HTTP_ACCEPT="*/*"
44         REQUEST_METHOD="GET"
45         QUERY_STRING=""$1""
46         PATH_INFO=""$2""
47         export GATEWAY_INTERFACE HTTP_ACCEPT REQUEST_METHOD QUERY_STRING PATH_INFO
49         GITWEB_CONFIG=$(pwd)/gitweb_config.perl
50         export GITWEB_CONFIG
52         # some of git commands write to STDERR on error, but this is not
53         # written to web server logs, so we are not interested in that:
54         # we are interested only in properly formatted errors/warnings
55         rm -f gitweb.log &&
56         perl -- $(pwd)/../../gitweb/gitweb.perl \
57                 >/dev/null 2>gitweb.log &&
58         if grep -q -s "^[[]" gitweb.log >/dev/null; then false; else true; fi
60         # gitweb.log is left for debugging
61 }
63 safe_chmod () {
64         chmod "$1" "$2" &&
65         if [ "$(git config --get core.filemode)" = false ]
66         then
67                 git update-index --chmod="$1" "$2"
68         fi
69 }
71 . ./test-lib.sh
73 perl -MEncode -e 'decode_utf8("", Encode::FB_CROAK)' >/dev/null 2>&1 || {
74     test_expect_success 'skipping gitweb tests, perl version is too old' :
75     test_done
76     exit
77 }
79 gitweb_init
81 # ----------------------------------------------------------------------
82 # no commits (empty, just initialized repository)
84 test_expect_success \
85         'no commits: projects_list (implicit)' \
86         'gitweb_run'
87 test_debug 'cat gitweb.log'
89 test_expect_success \
90         'no commits: projects_index' \
91         'gitweb_run "a=project_index"'
92 test_debug 'cat gitweb.log'
94 test_expect_success \
95         'no commits: .git summary (implicit)' \
96         'gitweb_run "p=.git"'
97 test_debug 'cat gitweb.log'
99 test_expect_success \
100         'no commits: .git commit (implicit HEAD)' \
101         'gitweb_run "p=.git;a=commit"'
102 test_debug 'cat gitweb.log'
104 test_expect_success \
105         'no commits: .git commitdiff (implicit HEAD)' \
106         'gitweb_run "p=.git;a=commitdiff"'
107 test_debug 'cat gitweb.log'
109 test_expect_success \
110         'no commits: .git tree (implicit HEAD)' \
111         'gitweb_run "p=.git;a=tree"'
112 test_debug 'cat gitweb.log'
114 test_expect_success \
115         'no commits: .git heads' \
116         'gitweb_run "p=.git;a=heads"'
117 test_debug 'cat gitweb.log'
119 test_expect_success \
120         'no commits: .git tags' \
121         'gitweb_run "p=.git;a=tags"'
122 test_debug 'cat gitweb.log'
125 # ----------------------------------------------------------------------
126 # initial commit
128 test_expect_success \
129         'Make initial commit' \
130         'echo "Not an empty file." > file &&
131          git add file &&
132          git commit -a -m "Initial commit." &&
133          git branch b'
135 test_expect_success \
136         'projects_list (implicit)' \
137         'gitweb_run'
138 test_debug 'cat gitweb.log'
140 test_expect_success \
141         'projects_index' \
142         'gitweb_run "a=project_index"'
143 test_debug 'cat gitweb.log'
145 test_expect_success \
146         '.git summary (implicit)' \
147         'gitweb_run "p=.git"'
148 test_debug 'cat gitweb.log'
150 test_expect_success \
151         '.git commit (implicit HEAD)' \
152         'gitweb_run "p=.git;a=commit"'
153 test_debug 'cat gitweb.log'
155 test_expect_success \
156         '.git commitdiff (implicit HEAD, root commit)' \
157         'gitweb_run "p=.git;a=commitdiff"'
158 test_debug 'cat gitweb.log'
160 test_expect_success \
161         '.git commitdiff_plain (implicit HEAD, root commit)' \
162         'gitweb_run "p=.git;a=commitdiff_plain"'
163 test_debug 'cat gitweb.log'
165 test_expect_success \
166         '.git commit (HEAD)' \
167         'gitweb_run "p=.git;a=commit;h=HEAD"'
168 test_debug 'cat gitweb.log'
170 test_expect_success \
171         '.git tree (implicit HEAD)' \
172         'gitweb_run "p=.git;a=tree"'
173 test_debug 'cat gitweb.log'
175 test_expect_success \
176         '.git blob (file)' \
177         'gitweb_run "p=.git;a=blob;f=file"'
178 test_debug 'cat gitweb.log'
180 test_expect_success \
181         '.git blob_plain (file)' \
182         'gitweb_run "p=.git;a=blob_plain;f=file"'
183 test_debug 'cat gitweb.log'
185 # ----------------------------------------------------------------------
186 # nonexistent objects
188 test_expect_success \
189         '.git commit (non-existent)' \
190         'gitweb_run "p=.git;a=commit;h=non-existent"'
191 test_debug 'cat gitweb.log'
193 test_expect_success \
194         '.git commitdiff (non-existent)' \
195         'gitweb_run "p=.git;a=commitdiff;h=non-existent"'
196 test_debug 'cat gitweb.log'
198 test_expect_success \
199         '.git commitdiff (non-existent vs HEAD)' \
200         'gitweb_run "p=.git;a=commitdiff;hp=non-existent;h=HEAD"'
201 test_debug 'cat gitweb.log'
203 test_expect_success \
204         '.git tree (0000000000000000000000000000000000000000)' \
205         'gitweb_run "p=.git;a=tree;h=0000000000000000000000000000000000000000"'
206 test_debug 'cat gitweb.log'
208 test_expect_success \
209         '.git tag (0000000000000000000000000000000000000000)' \
210         'gitweb_run "p=.git;a=tag;h=0000000000000000000000000000000000000000"'
211 test_debug 'cat gitweb.log'
213 test_expect_success \
214         '.git blob (non-existent)' \
215         'gitweb_run "p=.git;a=blob;f=non-existent"'
216 test_debug 'cat gitweb.log'
218 test_expect_success \
219         '.git blob_plain (non-existent)' \
220         'gitweb_run "p=.git;a=blob_plain;f=non-existent"'
221 test_debug 'cat gitweb.log'
224 # ----------------------------------------------------------------------
225 # commitdiff testing (implicit, one implicit tree-ish)
227 test_expect_success \
228         'commitdiff(0): root' \
229         'gitweb_run "p=.git;a=commitdiff"'
230 test_debug 'cat gitweb.log'
232 test_expect_success \
233         'commitdiff(0): file added' \
234         'echo "New file" > new_file &&
235          git add new_file &&
236          git commit -a -m "File added." &&
237          gitweb_run "p=.git;a=commitdiff"'
238 test_debug 'cat gitweb.log'
240 test_expect_success \
241         'commitdiff(0): mode change' \
242         'safe_chmod +x new_file &&
243          git commit -a -m "Mode changed." &&
244          gitweb_run "p=.git;a=commitdiff"'
245 test_debug 'cat gitweb.log'
247 test_expect_success \
248         'commitdiff(0): file renamed' \
249         'git mv new_file renamed_file &&
250          git commit -a -m "File renamed." &&
251          gitweb_run "p=.git;a=commitdiff"'
252 test_debug 'cat gitweb.log'
254 test_expect_success \
255         'commitdiff(0): file to symlink' \
256         'rm renamed_file &&
257          ln -s file renamed_file &&
258          git commit -a -m "File to symlink." &&
259          gitweb_run "p=.git;a=commitdiff"'
260 test_debug 'cat gitweb.log'
262 test_expect_success \
263         'commitdiff(0): file deleted' \
264         'git rm renamed_file &&
265          rm -f renamed_file &&
266          git commit -a -m "File removed." &&
267          gitweb_run "p=.git;a=commitdiff"'
268 test_debug 'cat gitweb.log'
270 test_expect_success \
271         'commitdiff(0): file copied / new file' \
272         'cp file file2 &&
273          git add file2 &&
274          git commit -a -m "File copied." &&
275          gitweb_run "p=.git;a=commitdiff"'
276 test_debug 'cat gitweb.log'
278 test_expect_success \
279         'commitdiff(0): mode change and modified' \
280         'echo "New line" >> file2 &&
281          safe_chmod +x file2 &&
282          git commit -a -m "Mode change and modification." &&
283          gitweb_run "p=.git;a=commitdiff"'
284 test_debug 'cat gitweb.log'
286 test_expect_success \
287         'commitdiff(0): renamed and modified' \
288         'cat >file2<<EOF &&
289 Dominus regit me,
290 et nihil mihi deerit.
291 In loco pascuae ibi me collocavit,
292 super aquam refectionis educavit me;
293 animam meam convertit,
294 deduxit me super semitas jusitiae,
295 propter nomen suum.
296 EOF
297          git commit -a -m "File added." &&
298          git mv file2 file3 &&
299          echo "Propter nomen suum." >> file3 &&
300          git commit -a -m "File rename and modification." &&
301          gitweb_run "p=.git;a=commitdiff"'
302 test_debug 'cat gitweb.log'
304 test_expect_success \
305         'commitdiff(0): renamed, mode change and modified' \
306         'git mv file3 file2 &&
307          echo "Propter nomen suum." >> file2 &&
308          safe_chmod +x file2 &&
309          git commit -a -m "File rename, mode change and modification." &&
310          gitweb_run "p=.git;a=commitdiff"'
311 test_debug 'cat gitweb.log'
313 # ----------------------------------------------------------------------
314 # commitdiff testing (taken from t4114-apply-typechange.sh)
316 test_expect_success 'setup typechange commits' '
317         echo "hello world" > foo &&
318         echo "hi planet" > bar &&
319         git update-index --add foo bar &&
320         git commit -m initial &&
321         git branch initial &&
322         rm -f foo &&
323         ln -s bar foo &&
324         git update-index foo &&
325         git commit -m "foo symlinked to bar" &&
326         git branch foo-symlinked-to-bar &&
327         rm -f foo &&
328         echo "how far is the sun?" > foo &&
329         git update-index foo &&
330         git commit -m "foo back to file" &&
331         git branch foo-back-to-file &&
332         rm -f foo &&
333         git update-index --remove foo &&
334         mkdir foo &&
335         echo "if only I knew" > foo/baz &&
336         git update-index --add foo/baz &&
337         git commit -m "foo becomes a directory" &&
338         git branch "foo-becomes-a-directory" &&
339         echo "hello world" > foo/baz &&
340         git update-index foo/baz &&
341         git commit -m "foo/baz is the original foo" &&
342         git branch foo-baz-renamed-from-foo
343         '
345 test_expect_success \
346         'commitdiff(2): file renamed from foo to foo/baz' \
347         'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-baz-renamed-from-foo"'
348 test_debug 'cat gitweb.log'
350 test_expect_success \
351         'commitdiff(2): file renamed from foo/baz to foo' \
352         'gitweb_run "p=.git;a=commitdiff;hp=foo-baz-renamed-from-foo;h=initial"'
353 test_debug 'cat gitweb.log'
355 test_expect_success \
356         'commitdiff(2): directory becomes file' \
357         'gitweb_run "p=.git;a=commitdiff;hp=foo-becomes-a-directory;h=initial"'
358 test_debug 'cat gitweb.log'
360 test_expect_success \
361         'commitdiff(2): file becomes directory' \
362         'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-becomes-a-directory"'
363 test_debug 'cat gitweb.log'
365 test_expect_success \
366         'commitdiff(2): file becomes symlink' \
367         'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-symlinked-to-bar"'
368 test_debug 'cat gitweb.log'
370 test_expect_success \
371         'commitdiff(2): symlink becomes file' \
372         'gitweb_run "p=.git;a=commitdiff;hp=foo-symlinked-to-bar;h=foo-back-to-file"'
373 test_debug 'cat gitweb.log'
375 test_expect_success \
376         'commitdiff(2): symlink becomes directory' \
377         'gitweb_run "p=.git;a=commitdiff;hp=foo-symlinked-to-bar;h=foo-becomes-a-directory"'
378 test_debug 'cat gitweb.log'
380 test_expect_success \
381         'commitdiff(2): directory becomes symlink' \
382         'gitweb_run "p=.git;a=commitdiff;hp=foo-becomes-a-directory;h=foo-symlinked-to-bar"'
383 test_debug 'cat gitweb.log'
385 # ----------------------------------------------------------------------
386 # commit, commitdiff: merge, large
387 test_expect_success \
388         'Create a merge' \
389         'git checkout b &&
390          echo "Branch" >> b &&
391          git add b &&
392          git commit -a -m "On branch" &&
393          git checkout master &&
394          git pull . b'
396 test_expect_success \
397         'commit(0): merge commit' \
398         'gitweb_run "p=.git;a=commit"'
399 test_debug 'cat gitweb.log'
401 test_expect_success \
402         'commitdiff(0): merge commit' \
403         'gitweb_run "p=.git;a=commitdiff"'
404 test_debug 'cat gitweb.log'
406 test_expect_success \
407         'Prepare large commit' \
408         'git checkout b &&
409          echo "To be changed" > 01-change &&
410          echo "To be renamed" > 02-pure-rename-from &&
411          echo "To be deleted" > 03-delete &&
412          echo "To be renamed and changed" > 04-rename-from &&
413          echo "To have mode changed" > 05-mode-change &&
414          echo "File to symlink" > 06-file-or-symlink &&
415          echo "To be changed and have mode changed" > 07-change-mode-change     &&
416          git add 0* &&
417          git commit -a -m "Prepare large commit" &&
418          echo "Changed" > 01-change &&
419          git mv 02-pure-rename-from 02-pure-rename-to &&
420          git rm 03-delete && rm -f 03-delete &&
421          echo "A new file" > 03-new &&
422          git add 03-new &&
423          git mv 04-rename-from 04-rename-to &&
424          echo "Changed" >> 04-rename-to &&
425          safe_chmod +x 05-mode-change &&
426          rm -f 06-file-or-symlink && ln -s 01-change 06-file-or-symlink &&
427          echo "Changed and have mode changed" > 07-change-mode-change   &&
428          safe_chmod +x 07-change-mode-change &&
429          git commit -a -m "Large commit" &&
430          git checkout master'
432 test_expect_success \
433         'commit(1): large commit' \
434         'gitweb_run "p=.git;a=commit;h=b"'
435 test_debug 'cat gitweb.log'
437 test_expect_success \
438         'commitdiff(1): large commit' \
439         'gitweb_run "p=.git;a=commitdiff;h=b"'
440 test_debug 'cat gitweb.log'
442 # ----------------------------------------------------------------------
443 # tags testing
445 test_expect_success \
446         'tags: list of different types of tags' \
447         'git checkout master &&
448          git tag -a -m "Tag commit object" tag-commit HEAD &&
449          git tag -a -m "" tag-commit-nomessage HEAD &&
450          git tag -a -m "Tag tag object" tag-tag tag-commit &&
451          git tag -a -m "Tag tree object" tag-tree HEAD^{tree} &&
452          git tag -a -m "Tag blob object" tag-blob HEAD:file &&
453          git tag lightweight/tag-commit HEAD &&
454          git tag lightweight/tag-tag tag-commit &&
455          git tag lightweight/tag-tree HEAD^{tree} &&
456          git tag lightweight/tag-blob HEAD:file &&
457          gitweb_run "p=.git;a=tags"'
458 test_debug 'cat gitweb.log'
460 test_expect_success \
461         'tag: Tag to commit object' \
462         'gitweb_run "p=.git;a=tag;h=tag-commit"'
463 test_debug 'cat gitweb.log'
465 test_expect_success \
466         'tag: on lightweight tag (invalid)' \
467         'gitweb_run "p=.git;a=tag;h=lightweight/tag-commit"'
468 test_debug 'cat gitweb.log'
470 # ----------------------------------------------------------------------
471 # logs
473 test_expect_success \
474         'logs: log (implicit HEAD)' \
475         'gitweb_run "p=.git;a=log"'
476 test_debug 'cat gitweb.log'
478 test_expect_success \
479         'logs: shortlog (implicit HEAD)' \
480         'gitweb_run "p=.git;a=shortlog"'
481 test_debug 'cat gitweb.log'
483 test_expect_success \
484         'logs: history (implicit HEAD, file)' \
485         'gitweb_run "p=.git;a=history;f=file"'
486 test_debug 'cat gitweb.log'
488 test_expect_success \
489         'logs: history (implicit HEAD, non-existent file)' \
490         'gitweb_run "p=.git;a=history;f=non-existent"'
491 test_debug 'cat gitweb.log'
493 test_expect_success \
494         'logs: history (implicit HEAD, deleted file)' \
495         'git checkout master &&
496          echo "to be deleted" > deleted_file &&
497          git add deleted_file &&
498          git commit -m "Add file to be deleted" &&
499          git rm deleted_file &&
500          git commit -m "Delete file" &&
501          gitweb_run "p=.git;a=history;f=deleted_file"'
502 test_debug 'cat gitweb.log'
504 # ----------------------------------------------------------------------
505 # feed generation
507 test_expect_success \
508         'feeds: OPML' \
509         'gitweb_run "a=opml"'
510 test_debug 'cat gitweb.log'
512 test_expect_success \
513         'feed: RSS' \
514         'gitweb_run "p=.git;a=rss"'
515 test_debug 'cat gitweb.log'
517 test_expect_success \
518         'feed: Atom' \
519         'gitweb_run "p=.git;a=atom"'
520 test_debug 'cat gitweb.log'
522 # ----------------------------------------------------------------------
523 # encoding/decoding
525 test_expect_success \
526         'encode(commit): utf8' \
527         '. ../t3901-utf8.txt &&
528          echo "UTF-8" >> file &&
529          git add file &&
530          git commit -F ../t3900/1-UTF-8.txt &&
531          gitweb_run "p=.git;a=commit"'
532 test_debug 'cat gitweb.log'
534 test_expect_success \
535         'encode(commit): iso-8859-1' \
536         '. ../t3901-8859-1.txt &&
537          echo "ISO-8859-1" >> file &&
538          git add file &&
539          git config i18n.commitencoding ISO-8859-1 &&
540          git commit -F ../t3900/ISO-8859-1.txt &&
541          git config --unset i18n.commitencoding &&
542          gitweb_run "p=.git;a=commit"'
543 test_debug 'cat gitweb.log'
545 test_expect_success \
546         'encode(log): utf-8 and iso-8859-1' \
547         'gitweb_run "p=.git;a=log"'
548 test_debug 'cat gitweb.log'
550 # ----------------------------------------------------------------------
551 # extra options
553 test_expect_success \
554         'opt: log --no-merges' \
555         'gitweb_run "p=.git;a=log;opt=--no-merges"'
556 test_debug 'cat gitweb.log'
558 test_expect_success \
559         'opt: atom --no-merges' \
560         'gitweb_run "p=.git;a=log;opt=--no-merges"'
561 test_debug 'cat gitweb.log'
563 test_expect_success \
564         'opt: "file" history --no-merges' \
565         'gitweb_run "p=.git;a=history;f=file;opt=--no-merges"'
566 test_debug 'cat gitweb.log'
568 test_expect_success \
569         'opt: log --no-such-option (invalid option)' \
570         'gitweb_run "p=.git;a=log;opt=--no-such-option"'
571 test_debug 'cat gitweb.log'
573 test_expect_success \
574         'opt: tree --no-merges (invalid option for action)' \
575         'gitweb_run "p=.git;a=tree;opt=--no-merges"'
576 test_debug 'cat gitweb.log'
578 # ----------------------------------------------------------------------
579 # testing config_to_multi / cloneurl
581 test_expect_success \
582        'URL: no project URLs, no base URL' \
583        'gitweb_run "p=.git;a=summary"'
584 test_debug 'cat gitweb.log'
586 test_expect_success \
587        'URL: project URLs via gitweb.url' \
588        'git config --add gitweb.url git://example.com/git/trash.git &&
589         git config --add gitweb.url http://example.com/git/trash.git &&
590         gitweb_run "p=.git;a=summary"'
591 test_debug 'cat gitweb.log'
593 cat >.git/cloneurl <<\EOF
594 git://example.com/git/trash.git
595 http://example.com/git/trash.git
596 EOF
598 test_expect_success \
599        'URL: project URLs via cloneurl file' \
600        'gitweb_run "p=.git;a=summary"'
601 test_debug 'cat gitweb.log'
603 # ----------------------------------------------------------------------
604 # gitweb config and repo config
606 cat >>gitweb_config.perl <<EOF
608 \$feature{'blame'}{'override'} = 1;
609 \$feature{'snapshot'}{'override'} = 1;
610 EOF
612 test_expect_success \
613         'config override: tree view, features disabled in repo config' \
614         'git config gitweb.blame no &&
615          git config gitweb.snapshot none &&
616          gitweb_run "p=.git;a=tree"'
617 test_debug 'cat gitweb.log'
619 test_expect_success \
620         'config override: tree view, features enabled in repo config' \
621         'git config gitweb.blame yes &&
622          git config gitweb.snapshot "zip,tgz, tbz2" &&
623          gitweb_run "p=.git;a=tree"'
624 test_debug 'cat gitweb.log'
626 test_done