Code

Merge branch 'maint-1.5.5' into maint-1.5.6
[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         safe_pwd="$(perl -MPOSIX=getcwd -e 'print quotemeta(getcwd)')"
14         cat >gitweb_config.perl <<EOF
15 #!/usr/bin/perl
17 # gitweb configuration for tests
19 our \$version = "current";
20 our \$GIT = "git";
21 our \$projectroot = "$safe_pwd";
22 our \$project_maxdepth = 8;
23 our \$home_link_str = "projects";
24 our \$site_name = "[localhost]";
25 our \$site_header = "";
26 our \$site_footer = "";
27 our \$home_text = "indextext.html";
28 our @stylesheets = ("file:///$safe_pwd/../../gitweb/gitweb.css");
29 our \$logo = "file:///$safe_pwd/../../gitweb/git-logo.png";
30 our \$favicon = "file:///$safe_pwd/../../gitweb/git-favicon.png";
31 our \$projects_list = "";
32 our \$export_ok = "";
33 our \$strict_export = "";
35 EOF
37         cat >.git/description <<EOF
38 $0 test repository
39 EOF
40 }
42 gitweb_run () {
43         GATEWAY_INTERFACE="CGI/1.1"
44         HTTP_ACCEPT="*/*"
45         REQUEST_METHOD="GET"
46         QUERY_STRING=""$1""
47         PATH_INFO=""$2""
48         export GATEWAY_INTERFACE HTTP_ACCEPT REQUEST_METHOD QUERY_STRING PATH_INFO
50         GITWEB_CONFIG=$(pwd)/gitweb_config.perl
51         export GITWEB_CONFIG
53         # some of git commands write to STDERR on error, but this is not
54         # written to web server logs, so we are not interested in that:
55         # we are interested only in properly formatted errors/warnings
56         rm -f gitweb.log &&
57         perl -- "$(pwd)/../../gitweb/gitweb.perl" \
58                 >/dev/null 2>gitweb.log &&
59         if grep -q -s "^[[]" gitweb.log >/dev/null; then false; else true; fi
61         # gitweb.log is left for debugging
62 }
64 safe_chmod () {
65         chmod "$1" "$2" &&
66         if [ "$(git config --get core.filemode)" = false ]
67         then
68                 git update-index --chmod="$1" "$2"
69         fi
70 }
72 . ./test-lib.sh
74 perl -MEncode -e 'decode_utf8("", Encode::FB_CROAK)' >/dev/null 2>&1 || {
75     test_expect_success 'skipping gitweb tests, perl version is too old' :
76     test_done
77     exit
78 }
80 gitweb_init
82 # ----------------------------------------------------------------------
83 # no commits (empty, just initialized repository)
85 test_expect_success \
86         'no commits: projects_list (implicit)' \
87         'gitweb_run'
88 test_debug 'cat gitweb.log'
90 test_expect_success \
91         'no commits: projects_index' \
92         'gitweb_run "a=project_index"'
93 test_debug 'cat gitweb.log'
95 test_expect_success \
96         'no commits: .git summary (implicit)' \
97         'gitweb_run "p=.git"'
98 test_debug 'cat gitweb.log'
100 test_expect_success \
101         'no commits: .git commit (implicit HEAD)' \
102         'gitweb_run "p=.git;a=commit"'
103 test_debug 'cat gitweb.log'
105 test_expect_success \
106         'no commits: .git commitdiff (implicit HEAD)' \
107         'gitweb_run "p=.git;a=commitdiff"'
108 test_debug 'cat gitweb.log'
110 test_expect_success \
111         'no commits: .git tree (implicit HEAD)' \
112         'gitweb_run "p=.git;a=tree"'
113 test_debug 'cat gitweb.log'
115 test_expect_success \
116         'no commits: .git heads' \
117         'gitweb_run "p=.git;a=heads"'
118 test_debug 'cat gitweb.log'
120 test_expect_success \
121         'no commits: .git tags' \
122         'gitweb_run "p=.git;a=tags"'
123 test_debug 'cat gitweb.log'
126 # ----------------------------------------------------------------------
127 # initial commit
129 test_expect_success \
130         'Make initial commit' \
131         'echo "Not an empty file." > file &&
132          git add file &&
133          git commit -a -m "Initial commit." &&
134          git branch b'
136 test_expect_success \
137         'projects_list (implicit)' \
138         'gitweb_run'
139 test_debug 'cat gitweb.log'
141 test_expect_success \
142         'projects_index' \
143         'gitweb_run "a=project_index"'
144 test_debug 'cat gitweb.log'
146 test_expect_success \
147         '.git summary (implicit)' \
148         'gitweb_run "p=.git"'
149 test_debug 'cat gitweb.log'
151 test_expect_success \
152         '.git commit (implicit HEAD)' \
153         'gitweb_run "p=.git;a=commit"'
154 test_debug 'cat gitweb.log'
156 test_expect_success \
157         '.git commitdiff (implicit HEAD, root commit)' \
158         'gitweb_run "p=.git;a=commitdiff"'
159 test_debug 'cat gitweb.log'
161 test_expect_success \
162         '.git commitdiff_plain (implicit HEAD, root commit)' \
163         'gitweb_run "p=.git;a=commitdiff_plain"'
164 test_debug 'cat gitweb.log'
166 test_expect_success \
167         '.git commit (HEAD)' \
168         'gitweb_run "p=.git;a=commit;h=HEAD"'
169 test_debug 'cat gitweb.log'
171 test_expect_success \
172         '.git tree (implicit HEAD)' \
173         'gitweb_run "p=.git;a=tree"'
174 test_debug 'cat gitweb.log'
176 test_expect_success \
177         '.git blob (file)' \
178         'gitweb_run "p=.git;a=blob;f=file"'
179 test_debug 'cat gitweb.log'
181 test_expect_success \
182         '.git blob_plain (file)' \
183         'gitweb_run "p=.git;a=blob_plain;f=file"'
184 test_debug 'cat gitweb.log'
186 # ----------------------------------------------------------------------
187 # nonexistent objects
189 test_expect_success \
190         '.git commit (non-existent)' \
191         'gitweb_run "p=.git;a=commit;h=non-existent"'
192 test_debug 'cat gitweb.log'
194 test_expect_success \
195         '.git commitdiff (non-existent)' \
196         'gitweb_run "p=.git;a=commitdiff;h=non-existent"'
197 test_debug 'cat gitweb.log'
199 test_expect_success \
200         '.git commitdiff (non-existent vs HEAD)' \
201         'gitweb_run "p=.git;a=commitdiff;hp=non-existent;h=HEAD"'
202 test_debug 'cat gitweb.log'
204 test_expect_success \
205         '.git tree (0000000000000000000000000000000000000000)' \
206         'gitweb_run "p=.git;a=tree;h=0000000000000000000000000000000000000000"'
207 test_debug 'cat gitweb.log'
209 test_expect_success \
210         '.git tag (0000000000000000000000000000000000000000)' \
211         'gitweb_run "p=.git;a=tag;h=0000000000000000000000000000000000000000"'
212 test_debug 'cat gitweb.log'
214 test_expect_success \
215         '.git blob (non-existent)' \
216         'gitweb_run "p=.git;a=blob;f=non-existent"'
217 test_debug 'cat gitweb.log'
219 test_expect_success \
220         '.git blob_plain (non-existent)' \
221         'gitweb_run "p=.git;a=blob_plain;f=non-existent"'
222 test_debug 'cat gitweb.log'
225 # ----------------------------------------------------------------------
226 # commitdiff testing (implicit, one implicit tree-ish)
228 test_expect_success \
229         'commitdiff(0): root' \
230         'gitweb_run "p=.git;a=commitdiff"'
231 test_debug 'cat gitweb.log'
233 test_expect_success \
234         'commitdiff(0): file added' \
235         'echo "New file" > new_file &&
236          git add new_file &&
237          git commit -a -m "File added." &&
238          gitweb_run "p=.git;a=commitdiff"'
239 test_debug 'cat gitweb.log'
241 test_expect_success \
242         'commitdiff(0): mode change' \
243         'safe_chmod +x new_file &&
244          git commit -a -m "Mode changed." &&
245          gitweb_run "p=.git;a=commitdiff"'
246 test_debug 'cat gitweb.log'
248 test_expect_success \
249         'commitdiff(0): file renamed' \
250         'git mv new_file renamed_file &&
251          git commit -a -m "File renamed." &&
252          gitweb_run "p=.git;a=commitdiff"'
253 test_debug 'cat gitweb.log'
255 test_expect_success \
256         'commitdiff(0): file to symlink' \
257         'rm renamed_file &&
258          ln -s file renamed_file &&
259          git commit -a -m "File to symlink." &&
260          gitweb_run "p=.git;a=commitdiff"'
261 test_debug 'cat gitweb.log'
263 test_expect_success \
264         'commitdiff(0): file deleted' \
265         'git rm renamed_file &&
266          rm -f renamed_file &&
267          git commit -a -m "File removed." &&
268          gitweb_run "p=.git;a=commitdiff"'
269 test_debug 'cat gitweb.log'
271 test_expect_success \
272         'commitdiff(0): file copied / new file' \
273         'cp file file2 &&
274          git add file2 &&
275          git commit -a -m "File copied." &&
276          gitweb_run "p=.git;a=commitdiff"'
277 test_debug 'cat gitweb.log'
279 test_expect_success \
280         'commitdiff(0): mode change and modified' \
281         'echo "New line" >> file2 &&
282          safe_chmod +x file2 &&
283          git commit -a -m "Mode change and modification." &&
284          gitweb_run "p=.git;a=commitdiff"'
285 test_debug 'cat gitweb.log'
287 test_expect_success \
288         'commitdiff(0): renamed and modified' \
289         'cat >file2<<EOF &&
290 Dominus regit me,
291 et nihil mihi deerit.
292 In loco pascuae ibi me collocavit,
293 super aquam refectionis educavit me;
294 animam meam convertit,
295 deduxit me super semitas jusitiae,
296 propter nomen suum.
297 EOF
298          git commit -a -m "File added." &&
299          git mv file2 file3 &&
300          echo "Propter nomen suum." >> file3 &&
301          git commit -a -m "File rename and modification." &&
302          gitweb_run "p=.git;a=commitdiff"'
303 test_debug 'cat gitweb.log'
305 test_expect_success \
306         'commitdiff(0): renamed, mode change and modified' \
307         'git mv file3 file2 &&
308          echo "Propter nomen suum." >> file2 &&
309          safe_chmod +x file2 &&
310          git commit -a -m "File rename, mode change and modification." &&
311          gitweb_run "p=.git;a=commitdiff"'
312 test_debug 'cat gitweb.log'
314 # ----------------------------------------------------------------------
315 # commitdiff testing (taken from t4114-apply-typechange.sh)
317 test_expect_success 'setup typechange commits' '
318         echo "hello world" > foo &&
319         echo "hi planet" > bar &&
320         git update-index --add foo bar &&
321         git commit -m initial &&
322         git branch initial &&
323         rm -f foo &&
324         ln -s bar foo &&
325         git update-index foo &&
326         git commit -m "foo symlinked to bar" &&
327         git branch foo-symlinked-to-bar &&
328         rm -f foo &&
329         echo "how far is the sun?" > foo &&
330         git update-index foo &&
331         git commit -m "foo back to file" &&
332         git branch foo-back-to-file &&
333         rm -f foo &&
334         git update-index --remove foo &&
335         mkdir foo &&
336         echo "if only I knew" > foo/baz &&
337         git update-index --add foo/baz &&
338         git commit -m "foo becomes a directory" &&
339         git branch "foo-becomes-a-directory" &&
340         echo "hello world" > foo/baz &&
341         git update-index foo/baz &&
342         git commit -m "foo/baz is the original foo" &&
343         git branch foo-baz-renamed-from-foo
344         '
346 test_expect_success \
347         'commitdiff(2): file renamed from foo to foo/baz' \
348         'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-baz-renamed-from-foo"'
349 test_debug 'cat gitweb.log'
351 test_expect_success \
352         'commitdiff(2): file renamed from foo/baz to foo' \
353         'gitweb_run "p=.git;a=commitdiff;hp=foo-baz-renamed-from-foo;h=initial"'
354 test_debug 'cat gitweb.log'
356 test_expect_success \
357         'commitdiff(2): directory becomes file' \
358         'gitweb_run "p=.git;a=commitdiff;hp=foo-becomes-a-directory;h=initial"'
359 test_debug 'cat gitweb.log'
361 test_expect_success \
362         'commitdiff(2): file becomes directory' \
363         'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-becomes-a-directory"'
364 test_debug 'cat gitweb.log'
366 test_expect_success \
367         'commitdiff(2): file becomes symlink' \
368         'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-symlinked-to-bar"'
369 test_debug 'cat gitweb.log'
371 test_expect_success \
372         'commitdiff(2): symlink becomes file' \
373         'gitweb_run "p=.git;a=commitdiff;hp=foo-symlinked-to-bar;h=foo-back-to-file"'
374 test_debug 'cat gitweb.log'
376 test_expect_success \
377         'commitdiff(2): symlink becomes directory' \
378         'gitweb_run "p=.git;a=commitdiff;hp=foo-symlinked-to-bar;h=foo-becomes-a-directory"'
379 test_debug 'cat gitweb.log'
381 test_expect_success \
382         'commitdiff(2): directory becomes symlink' \
383         'gitweb_run "p=.git;a=commitdiff;hp=foo-becomes-a-directory;h=foo-symlinked-to-bar"'
384 test_debug 'cat gitweb.log'
386 # ----------------------------------------------------------------------
387 # commit, commitdiff: merge, large
388 test_expect_success \
389         'Create a merge' \
390         'git checkout b &&
391          echo "Branch" >> b &&
392          git add b &&
393          git commit -a -m "On branch" &&
394          git checkout master &&
395          git pull . b'
397 test_expect_success \
398         'commit(0): merge commit' \
399         'gitweb_run "p=.git;a=commit"'
400 test_debug 'cat gitweb.log'
402 test_expect_success \
403         'commitdiff(0): merge commit' \
404         'gitweb_run "p=.git;a=commitdiff"'
405 test_debug 'cat gitweb.log'
407 test_expect_success \
408         'Prepare large commit' \
409         'git checkout b &&
410          echo "To be changed" > 01-change &&
411          echo "To be renamed" > 02-pure-rename-from &&
412          echo "To be deleted" > 03-delete &&
413          echo "To be renamed and changed" > 04-rename-from &&
414          echo "To have mode changed" > 05-mode-change &&
415          echo "File to symlink" > 06-file-or-symlink &&
416          echo "To be changed and have mode changed" > 07-change-mode-change     &&
417          git add 0* &&
418          git commit -a -m "Prepare large commit" &&
419          echo "Changed" > 01-change &&
420          git mv 02-pure-rename-from 02-pure-rename-to &&
421          git rm 03-delete && rm -f 03-delete &&
422          echo "A new file" > 03-new &&
423          git add 03-new &&
424          git mv 04-rename-from 04-rename-to &&
425          echo "Changed" >> 04-rename-to &&
426          safe_chmod +x 05-mode-change &&
427          rm -f 06-file-or-symlink && ln -s 01-change 06-file-or-symlink &&
428          echo "Changed and have mode changed" > 07-change-mode-change   &&
429          safe_chmod +x 07-change-mode-change &&
430          git commit -a -m "Large commit" &&
431          git checkout master'
433 test_expect_success \
434         'commit(1): large commit' \
435         'gitweb_run "p=.git;a=commit;h=b"'
436 test_debug 'cat gitweb.log'
438 test_expect_success \
439         'commitdiff(1): large commit' \
440         'gitweb_run "p=.git;a=commitdiff;h=b"'
441 test_debug 'cat gitweb.log'
443 # ----------------------------------------------------------------------
444 # tags testing
446 test_expect_success \
447         'tags: list of different types of tags' \
448         'git checkout master &&
449          git tag -a -m "Tag commit object" tag-commit HEAD &&
450          git tag -a -m "" tag-commit-nomessage HEAD &&
451          git tag -a -m "Tag tag object" tag-tag tag-commit &&
452          git tag -a -m "Tag tree object" tag-tree HEAD^{tree} &&
453          git tag -a -m "Tag blob object" tag-blob HEAD:file &&
454          git tag lightweight/tag-commit HEAD &&
455          git tag lightweight/tag-tag tag-commit &&
456          git tag lightweight/tag-tree HEAD^{tree} &&
457          git tag lightweight/tag-blob HEAD:file &&
458          gitweb_run "p=.git;a=tags"'
459 test_debug 'cat gitweb.log'
461 test_expect_success \
462         'tag: Tag to commit object' \
463         'gitweb_run "p=.git;a=tag;h=tag-commit"'
464 test_debug 'cat gitweb.log'
466 test_expect_success \
467         'tag: on lightweight tag (invalid)' \
468         'gitweb_run "p=.git;a=tag;h=lightweight/tag-commit"'
469 test_debug 'cat gitweb.log'
471 # ----------------------------------------------------------------------
472 # logs
474 test_expect_success \
475         'logs: log (implicit HEAD)' \
476         'gitweb_run "p=.git;a=log"'
477 test_debug 'cat gitweb.log'
479 test_expect_success \
480         'logs: shortlog (implicit HEAD)' \
481         'gitweb_run "p=.git;a=shortlog"'
482 test_debug 'cat gitweb.log'
484 test_expect_success \
485         'logs: history (implicit HEAD, file)' \
486         'gitweb_run "p=.git;a=history;f=file"'
487 test_debug 'cat gitweb.log'
489 test_expect_success \
490         'logs: history (implicit HEAD, non-existent file)' \
491         'gitweb_run "p=.git;a=history;f=non-existent"'
492 test_debug 'cat gitweb.log'
494 test_expect_success \
495         'logs: history (implicit HEAD, deleted file)' \
496         'git checkout master &&
497          echo "to be deleted" > deleted_file &&
498          git add deleted_file &&
499          git commit -m "Add file to be deleted" &&
500          git rm deleted_file &&
501          git commit -m "Delete file" &&
502          gitweb_run "p=.git;a=history;f=deleted_file"'
503 test_debug 'cat gitweb.log'
505 # ----------------------------------------------------------------------
506 # feed generation
508 test_expect_success \
509         'feeds: OPML' \
510         'gitweb_run "a=opml"'
511 test_debug 'cat gitweb.log'
513 test_expect_success \
514         'feed: RSS' \
515         'gitweb_run "p=.git;a=rss"'
516 test_debug 'cat gitweb.log'
518 test_expect_success \
519         'feed: Atom' \
520         'gitweb_run "p=.git;a=atom"'
521 test_debug 'cat gitweb.log'
523 # ----------------------------------------------------------------------
524 # encoding/decoding
526 test_expect_success \
527         'encode(commit): utf8' \
528         '. ../t3901-utf8.txt &&
529          echo "UTF-8" >> file &&
530          git add file &&
531          git commit -F ../t3900/1-UTF-8.txt &&
532          gitweb_run "p=.git;a=commit"'
533 test_debug 'cat gitweb.log'
535 test_expect_success \
536         'encode(commit): iso-8859-1' \
537         '. ../t3901-8859-1.txt &&
538          echo "ISO-8859-1" >> file &&
539          git add file &&
540          git config i18n.commitencoding ISO-8859-1 &&
541          git commit -F ../t3900/ISO-8859-1.txt &&
542          git config --unset i18n.commitencoding &&
543          gitweb_run "p=.git;a=commit"'
544 test_debug 'cat gitweb.log'
546 test_expect_success \
547         'encode(log): utf-8 and iso-8859-1' \
548         'gitweb_run "p=.git;a=log"'
549 test_debug 'cat gitweb.log'
551 # ----------------------------------------------------------------------
552 # extra options
554 test_expect_success \
555         'opt: log --no-merges' \
556         'gitweb_run "p=.git;a=log;opt=--no-merges"'
557 test_debug 'cat gitweb.log'
559 test_expect_success \
560         'opt: atom --no-merges' \
561         'gitweb_run "p=.git;a=log;opt=--no-merges"'
562 test_debug 'cat gitweb.log'
564 test_expect_success \
565         'opt: "file" history --no-merges' \
566         'gitweb_run "p=.git;a=history;f=file;opt=--no-merges"'
567 test_debug 'cat gitweb.log'
569 test_expect_success \
570         'opt: log --no-such-option (invalid option)' \
571         'gitweb_run "p=.git;a=log;opt=--no-such-option"'
572 test_debug 'cat gitweb.log'
574 test_expect_success \
575         'opt: tree --no-merges (invalid option for action)' \
576         'gitweb_run "p=.git;a=tree;opt=--no-merges"'
577 test_debug 'cat gitweb.log'
579 # ----------------------------------------------------------------------
580 # testing config_to_multi / cloneurl
582 test_expect_success \
583        'URL: no project URLs, no base URL' \
584        'gitweb_run "p=.git;a=summary"'
585 test_debug 'cat gitweb.log'
587 test_expect_success \
588        'URL: project URLs via gitweb.url' \
589        'git config --add gitweb.url git://example.com/git/trash.git &&
590         git config --add gitweb.url http://example.com/git/trash.git &&
591         gitweb_run "p=.git;a=summary"'
592 test_debug 'cat gitweb.log'
594 cat >.git/cloneurl <<\EOF
595 git://example.com/git/trash.git
596 http://example.com/git/trash.git
597 EOF
599 test_expect_success \
600        'URL: project URLs via cloneurl file' \
601        'gitweb_run "p=.git;a=summary"'
602 test_debug 'cat gitweb.log'
604 # ----------------------------------------------------------------------
605 # gitweb config and repo config
607 cat >>gitweb_config.perl <<EOF
609 \$feature{'blame'}{'override'} = 1;
610 \$feature{'snapshot'}{'override'} = 1;
611 EOF
613 test_expect_success \
614         'config override: tree view, features disabled in repo config' \
615         'git config gitweb.blame no &&
616          git config gitweb.snapshot none &&
617          gitweb_run "p=.git;a=tree"'
618 test_debug 'cat gitweb.log'
620 test_expect_success \
621         'config override: tree view, features enabled in repo config' \
622         'git config gitweb.blame yes &&
623          git config gitweb.snapshot "zip,tgz, tbz2" &&
624          gitweb_run "p=.git;a=tree"'
625 test_debug 'cat gitweb.log'
627 test_done