3 # Copyright (c) 2007 Jakub Narebski
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
13 safe_pwd="$(perl -MPOSIX=getcwd -e 'print quotemeta(getcwd)')"
14 cat >gitweb_config.perl <<EOF
17 # gitweb configuration for tests
19 our \$version = "current";
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:///$TEST_DIRECTORY/../gitweb/gitweb.css");
29 our \$logo = "file:///$TEST_DIRECTORY/../gitweb/git-logo.png";
30 our \$favicon = "file:///$TEST_DIRECTORY/../gitweb/git-favicon.png";
31 our \$projects_list = "";
33 our \$strict_export = "";
37 cat >.git/description <<EOF
43 GATEWAY_INTERFACE="CGI/1.1"
46 SCRIPT_NAME="$TEST_DIRECTORY/../gitweb/gitweb.perl"
49 export GATEWAY_INTERFACE HTTP_ACCEPT REQUEST_METHOD \
50 SCRIPT_NAME QUERY_STRING PATH_INFO
52 GITWEB_CONFIG=$(pwd)/gitweb_config.perl
55 # some of git commands write to STDERR on error, but this is not
56 # written to web server logs, so we are not interested in that:
57 # we are interested only in properly formatted errors/warnings
59 perl -- "$SCRIPT_NAME" \
60 >/dev/null 2>gitweb.log &&
61 if grep "^[[]" gitweb.log >/dev/null 2>&1; then false; else true; fi
63 # gitweb.log is left for debugging
68 if [ "$(git config --get core.filemode)" = false ]
70 git update-index --chmod="$1" "$2"
76 perl -MEncode -e 'decode_utf8("", Encode::FB_CROAK)' >/dev/null 2>&1 || {
77 test_expect_success 'skipping gitweb tests, perl version is too old' :
84 # ----------------------------------------------------------------------
85 # no commits (empty, just initialized repository)
88 'no commits: projects_list (implicit)' \
90 test_debug 'cat gitweb.log'
93 'no commits: projects_index' \
94 'gitweb_run "a=project_index"'
95 test_debug 'cat gitweb.log'
98 'no commits: .git summary (implicit)' \
100 test_debug 'cat gitweb.log'
102 test_expect_success \
103 'no commits: .git commit (implicit HEAD)' \
104 'gitweb_run "p=.git;a=commit"'
105 test_debug 'cat gitweb.log'
107 test_expect_success \
108 'no commits: .git commitdiff (implicit HEAD)' \
109 'gitweb_run "p=.git;a=commitdiff"'
110 test_debug 'cat gitweb.log'
112 test_expect_success \
113 'no commits: .git tree (implicit HEAD)' \
114 'gitweb_run "p=.git;a=tree"'
115 test_debug 'cat gitweb.log'
117 test_expect_success \
118 'no commits: .git heads' \
119 'gitweb_run "p=.git;a=heads"'
120 test_debug 'cat gitweb.log'
122 test_expect_success \
123 'no commits: .git tags' \
124 'gitweb_run "p=.git;a=tags"'
125 test_debug 'cat gitweb.log'
128 # ----------------------------------------------------------------------
131 test_expect_success \
132 'Make initial commit' \
133 'echo "Not an empty file." > file &&
135 git commit -a -m "Initial commit." &&
138 test_expect_success \
139 'projects_list (implicit)' \
141 test_debug 'cat gitweb.log'
143 test_expect_success \
145 'gitweb_run "a=project_index"'
146 test_debug 'cat gitweb.log'
148 test_expect_success \
149 '.git summary (implicit)' \
150 'gitweb_run "p=.git"'
151 test_debug 'cat gitweb.log'
153 test_expect_success \
154 '.git commit (implicit HEAD)' \
155 'gitweb_run "p=.git;a=commit"'
156 test_debug 'cat gitweb.log'
158 test_expect_success \
159 '.git commitdiff (implicit HEAD, root commit)' \
160 'gitweb_run "p=.git;a=commitdiff"'
161 test_debug 'cat gitweb.log'
163 test_expect_success \
164 '.git commitdiff_plain (implicit HEAD, root commit)' \
165 'gitweb_run "p=.git;a=commitdiff_plain"'
166 test_debug 'cat gitweb.log'
168 test_expect_success \
169 '.git commit (HEAD)' \
170 'gitweb_run "p=.git;a=commit;h=HEAD"'
171 test_debug 'cat gitweb.log'
173 test_expect_success \
174 '.git tree (implicit HEAD)' \
175 'gitweb_run "p=.git;a=tree"'
176 test_debug 'cat gitweb.log'
178 test_expect_success \
180 'gitweb_run "p=.git;a=blob;f=file"'
181 test_debug 'cat gitweb.log'
183 test_expect_success \
184 '.git blob_plain (file)' \
185 'gitweb_run "p=.git;a=blob_plain;f=file"'
186 test_debug 'cat gitweb.log'
188 # ----------------------------------------------------------------------
189 # nonexistent objects
191 test_expect_success \
192 '.git commit (non-existent)' \
193 'gitweb_run "p=.git;a=commit;h=non-existent"'
194 test_debug 'cat gitweb.log'
196 test_expect_success \
197 '.git commitdiff (non-existent)' \
198 'gitweb_run "p=.git;a=commitdiff;h=non-existent"'
199 test_debug 'cat gitweb.log'
201 test_expect_success \
202 '.git commitdiff (non-existent vs HEAD)' \
203 'gitweb_run "p=.git;a=commitdiff;hp=non-existent;h=HEAD"'
204 test_debug 'cat gitweb.log'
206 test_expect_success \
207 '.git tree (0000000000000000000000000000000000000000)' \
208 'gitweb_run "p=.git;a=tree;h=0000000000000000000000000000000000000000"'
209 test_debug 'cat gitweb.log'
211 test_expect_success \
212 '.git tag (0000000000000000000000000000000000000000)' \
213 'gitweb_run "p=.git;a=tag;h=0000000000000000000000000000000000000000"'
214 test_debug 'cat gitweb.log'
216 test_expect_success \
217 '.git blob (non-existent)' \
218 'gitweb_run "p=.git;a=blob;f=non-existent"'
219 test_debug 'cat gitweb.log'
221 test_expect_success \
222 '.git blob_plain (non-existent)' \
223 'gitweb_run "p=.git;a=blob_plain;f=non-existent"'
224 test_debug 'cat gitweb.log'
227 # ----------------------------------------------------------------------
228 # commitdiff testing (implicit, one implicit tree-ish)
230 test_expect_success \
231 'commitdiff(0): root' \
232 'gitweb_run "p=.git;a=commitdiff"'
233 test_debug 'cat gitweb.log'
235 test_expect_success \
236 'commitdiff(0): file added' \
237 'echo "New file" > new_file &&
239 git commit -a -m "File added." &&
240 gitweb_run "p=.git;a=commitdiff"'
241 test_debug 'cat gitweb.log'
243 test_expect_success \
244 'commitdiff(0): mode change' \
245 'safe_chmod +x new_file &&
246 git commit -a -m "Mode changed." &&
247 gitweb_run "p=.git;a=commitdiff"'
248 test_debug 'cat gitweb.log'
250 test_expect_success \
251 'commitdiff(0): file renamed' \
252 'git mv new_file renamed_file &&
253 git commit -a -m "File renamed." &&
254 gitweb_run "p=.git;a=commitdiff"'
255 test_debug 'cat gitweb.log'
257 test_expect_success \
258 'commitdiff(0): file to symlink' \
260 ln -s file renamed_file &&
261 git commit -a -m "File to symlink." &&
262 gitweb_run "p=.git;a=commitdiff"'
263 test_debug 'cat gitweb.log'
265 test_expect_success \
266 'commitdiff(0): file deleted' \
267 'git rm renamed_file &&
268 rm -f renamed_file &&
269 git commit -a -m "File removed." &&
270 gitweb_run "p=.git;a=commitdiff"'
271 test_debug 'cat gitweb.log'
273 test_expect_success \
274 'commitdiff(0): file copied / new file' \
277 git commit -a -m "File copied." &&
278 gitweb_run "p=.git;a=commitdiff"'
279 test_debug 'cat gitweb.log'
281 test_expect_success \
282 'commitdiff(0): mode change and modified' \
283 'echo "New line" >> file2 &&
284 safe_chmod +x file2 &&
285 git commit -a -m "Mode change and modification." &&
286 gitweb_run "p=.git;a=commitdiff"'
287 test_debug 'cat gitweb.log'
289 test_expect_success \
290 'commitdiff(0): renamed and modified' \
293 et nihil mihi deerit.
294 In loco pascuae ibi me collocavit,
295 super aquam refectionis educavit me;
296 animam meam convertit,
297 deduxit me super semitas jusitiae,
300 git commit -a -m "File added." &&
301 git mv file2 file3 &&
302 echo "Propter nomen suum." >> file3 &&
303 git commit -a -m "File rename and modification." &&
304 gitweb_run "p=.git;a=commitdiff"'
305 test_debug 'cat gitweb.log'
307 test_expect_success \
308 'commitdiff(0): renamed, mode change and modified' \
309 'git mv file3 file2 &&
310 echo "Propter nomen suum." >> file2 &&
311 safe_chmod +x file2 &&
312 git commit -a -m "File rename, mode change and modification." &&
313 gitweb_run "p=.git;a=commitdiff"'
314 test_debug 'cat gitweb.log'
316 # ----------------------------------------------------------------------
317 # commitdiff testing (taken from t4114-apply-typechange.sh)
319 test_expect_success 'setup typechange commits' '
320 echo "hello world" > foo &&
321 echo "hi planet" > bar &&
322 git update-index --add foo bar &&
323 git commit -m initial &&
324 git branch initial &&
327 git update-index foo &&
328 git commit -m "foo symlinked to bar" &&
329 git branch foo-symlinked-to-bar &&
331 echo "how far is the sun?" > foo &&
332 git update-index foo &&
333 git commit -m "foo back to file" &&
334 git branch foo-back-to-file &&
336 git update-index --remove foo &&
338 echo "if only I knew" > foo/baz &&
339 git update-index --add foo/baz &&
340 git commit -m "foo becomes a directory" &&
341 git branch "foo-becomes-a-directory" &&
342 echo "hello world" > foo/baz &&
343 git update-index foo/baz &&
344 git commit -m "foo/baz is the original foo" &&
345 git branch foo-baz-renamed-from-foo
348 test_expect_success \
349 'commitdiff(2): file renamed from foo to foo/baz' \
350 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-baz-renamed-from-foo"'
351 test_debug 'cat gitweb.log'
353 test_expect_success \
354 'commitdiff(2): file renamed from foo/baz to foo' \
355 'gitweb_run "p=.git;a=commitdiff;hp=foo-baz-renamed-from-foo;h=initial"'
356 test_debug 'cat gitweb.log'
358 test_expect_success \
359 'commitdiff(2): directory becomes file' \
360 'gitweb_run "p=.git;a=commitdiff;hp=foo-becomes-a-directory;h=initial"'
361 test_debug 'cat gitweb.log'
363 test_expect_success \
364 'commitdiff(2): file becomes directory' \
365 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-becomes-a-directory"'
366 test_debug 'cat gitweb.log'
368 test_expect_success \
369 'commitdiff(2): file becomes symlink' \
370 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-symlinked-to-bar"'
371 test_debug 'cat gitweb.log'
373 test_expect_success \
374 'commitdiff(2): symlink becomes file' \
375 'gitweb_run "p=.git;a=commitdiff;hp=foo-symlinked-to-bar;h=foo-back-to-file"'
376 test_debug 'cat gitweb.log'
378 test_expect_success \
379 'commitdiff(2): symlink becomes directory' \
380 'gitweb_run "p=.git;a=commitdiff;hp=foo-symlinked-to-bar;h=foo-becomes-a-directory"'
381 test_debug 'cat gitweb.log'
383 test_expect_success \
384 'commitdiff(2): directory becomes symlink' \
385 'gitweb_run "p=.git;a=commitdiff;hp=foo-becomes-a-directory;h=foo-symlinked-to-bar"'
386 test_debug 'cat gitweb.log'
388 # ----------------------------------------------------------------------
389 # commit, commitdiff: merge, large
390 test_expect_success \
393 echo "Branch" >> b &&
395 git commit -a -m "On branch" &&
396 git checkout master &&
399 test_expect_success \
400 'commit(0): merge commit' \
401 'gitweb_run "p=.git;a=commit"'
402 test_debug 'cat gitweb.log'
404 test_expect_success \
405 'commitdiff(0): merge commit' \
406 'gitweb_run "p=.git;a=commitdiff"'
407 test_debug 'cat gitweb.log'
409 test_expect_success \
410 'Prepare large commit' \
412 echo "To be changed" > 01-change &&
413 echo "To be renamed" > 02-pure-rename-from &&
414 echo "To be deleted" > 03-delete &&
415 echo "To be renamed and changed" > 04-rename-from &&
416 echo "To have mode changed" > 05-mode-change &&
417 echo "File to symlink" > 06-file-or-symlink &&
418 echo "To be changed and have mode changed" > 07-change-mode-change &&
420 git commit -a -m "Prepare large commit" &&
421 echo "Changed" > 01-change &&
422 git mv 02-pure-rename-from 02-pure-rename-to &&
423 git rm 03-delete && rm -f 03-delete &&
424 echo "A new file" > 03-new &&
426 git mv 04-rename-from 04-rename-to &&
427 echo "Changed" >> 04-rename-to &&
428 safe_chmod +x 05-mode-change &&
429 rm -f 06-file-or-symlink && ln -s 01-change 06-file-or-symlink &&
430 echo "Changed and have mode changed" > 07-change-mode-change &&
431 safe_chmod +x 07-change-mode-change &&
432 git commit -a -m "Large commit" &&
435 test_expect_success \
436 'commit(1): large commit' \
437 'gitweb_run "p=.git;a=commit;h=b"'
438 test_debug 'cat gitweb.log'
440 test_expect_success \
441 'commitdiff(1): large commit' \
442 'gitweb_run "p=.git;a=commitdiff;h=b"'
443 test_debug 'cat gitweb.log'
445 # ----------------------------------------------------------------------
448 test_expect_success \
449 'tags: list of different types of tags' \
450 'git checkout master &&
451 git tag -a -m "Tag commit object" tag-commit HEAD &&
452 git tag -a -m "" tag-commit-nomessage HEAD &&
453 git tag -a -m "Tag tag object" tag-tag tag-commit &&
454 git tag -a -m "Tag tree object" tag-tree HEAD^{tree} &&
455 git tag -a -m "Tag blob object" tag-blob HEAD:file &&
456 git tag lightweight/tag-commit HEAD &&
457 git tag lightweight/tag-tag tag-commit &&
458 git tag lightweight/tag-tree HEAD^{tree} &&
459 git tag lightweight/tag-blob HEAD:file &&
460 gitweb_run "p=.git;a=tags"'
461 test_debug 'cat gitweb.log'
463 test_expect_success \
464 'tag: Tag to commit object' \
465 'gitweb_run "p=.git;a=tag;h=tag-commit"'
466 test_debug 'cat gitweb.log'
468 test_expect_success \
469 'tag: on lightweight tag (invalid)' \
470 'gitweb_run "p=.git;a=tag;h=lightweight/tag-commit"'
471 test_debug 'cat gitweb.log'
473 # ----------------------------------------------------------------------
476 test_expect_success \
477 'logs: log (implicit HEAD)' \
478 'gitweb_run "p=.git;a=log"'
479 test_debug 'cat gitweb.log'
481 test_expect_success \
482 'logs: shortlog (implicit HEAD)' \
483 'gitweb_run "p=.git;a=shortlog"'
484 test_debug 'cat gitweb.log'
486 test_expect_success \
487 'logs: history (implicit HEAD, file)' \
488 'gitweb_run "p=.git;a=history;f=file"'
489 test_debug 'cat gitweb.log'
491 test_expect_success \
492 'logs: history (implicit HEAD, non-existent file)' \
493 'gitweb_run "p=.git;a=history;f=non-existent"'
494 test_debug 'cat gitweb.log'
496 test_expect_success \
497 'logs: history (implicit HEAD, deleted file)' \
498 'git checkout master &&
499 echo "to be deleted" > deleted_file &&
500 git add deleted_file &&
501 git commit -m "Add file to be deleted" &&
502 git rm deleted_file &&
503 git commit -m "Delete file" &&
504 gitweb_run "p=.git;a=history;f=deleted_file"'
505 test_debug 'cat gitweb.log'
507 # ----------------------------------------------------------------------
509 test_expect_success \
510 'path_info: project' \
511 'gitweb_run "" "/.git"'
512 test_debug 'cat gitweb.log'
514 test_expect_success \
515 'path_info: project/branch' \
516 'gitweb_run "" "/.git/b"'
517 test_debug 'cat gitweb.log'
519 test_expect_success \
520 'path_info: project/branch:file' \
521 'gitweb_run "" "/.git/master:file"'
522 test_debug 'cat gitweb.log'
524 test_expect_success \
525 'path_info: project/branch:dir/' \
526 'gitweb_run "" "/.git/master:foo/"'
527 test_debug 'cat gitweb.log'
529 test_expect_success \
530 'path_info: project/branch:file (non-existent)' \
531 'gitweb_run "" "/.git/master:non-existent"'
532 test_debug 'cat gitweb.log'
534 test_expect_success \
535 'path_info: project/branch:dir/ (non-existent)' \
536 'gitweb_run "" "/.git/master:non-existent/"'
537 test_debug 'cat gitweb.log'
540 test_expect_success \
541 'path_info: project/branch:/file' \
542 'gitweb_run "" "/.git/master:/file"'
543 test_debug 'cat gitweb.log'
545 test_expect_success \
546 'path_info: project/:/file (implicit HEAD)' \
547 'gitweb_run "" "/.git/:/file"'
548 test_debug 'cat gitweb.log'
550 test_expect_success \
551 'path_info: project/:/ (implicit HEAD, top tree)' \
552 'gitweb_run "" "/.git/:/"'
553 test_debug 'cat gitweb.log'
556 # ----------------------------------------------------------------------
559 test_expect_success \
561 'gitweb_run "a=opml"'
562 test_debug 'cat gitweb.log'
564 test_expect_success \
566 'gitweb_run "p=.git;a=rss"'
567 test_debug 'cat gitweb.log'
569 test_expect_success \
571 'gitweb_run "p=.git;a=atom"'
572 test_debug 'cat gitweb.log'
574 # ----------------------------------------------------------------------
577 test_expect_success \
578 'encode(commit): utf8' \
579 '. "$TEST_DIRECTORY"/t3901-utf8.txt &&
580 echo "UTF-8" >> file &&
582 git commit -F "$TEST_DIRECTORY"/t3900/1-UTF-8.txt &&
583 gitweb_run "p=.git;a=commit"'
584 test_debug 'cat gitweb.log'
586 test_expect_success \
587 'encode(commit): iso-8859-1' \
588 '. "$TEST_DIRECTORY"/t3901-8859-1.txt &&
589 echo "ISO-8859-1" >> file &&
591 git config i18n.commitencoding ISO-8859-1 &&
592 git commit -F "$TEST_DIRECTORY"/t3900/ISO-8859-1.txt &&
593 git config --unset i18n.commitencoding &&
594 gitweb_run "p=.git;a=commit"'
595 test_debug 'cat gitweb.log'
597 test_expect_success \
598 'encode(log): utf-8 and iso-8859-1' \
599 'gitweb_run "p=.git;a=log"'
600 test_debug 'cat gitweb.log'
602 # ----------------------------------------------------------------------
605 test_expect_success \
606 'opt: log --no-merges' \
607 'gitweb_run "p=.git;a=log;opt=--no-merges"'
608 test_debug 'cat gitweb.log'
610 test_expect_success \
611 'opt: atom --no-merges' \
612 'gitweb_run "p=.git;a=log;opt=--no-merges"'
613 test_debug 'cat gitweb.log'
615 test_expect_success \
616 'opt: "file" history --no-merges' \
617 'gitweb_run "p=.git;a=history;f=file;opt=--no-merges"'
618 test_debug 'cat gitweb.log'
620 test_expect_success \
621 'opt: log --no-such-option (invalid option)' \
622 'gitweb_run "p=.git;a=log;opt=--no-such-option"'
623 test_debug 'cat gitweb.log'
625 test_expect_success \
626 'opt: tree --no-merges (invalid option for action)' \
627 'gitweb_run "p=.git;a=tree;opt=--no-merges"'
628 test_debug 'cat gitweb.log'
630 # ----------------------------------------------------------------------
631 # testing config_to_multi / cloneurl
633 test_expect_success \
634 'URL: no project URLs, no base URL' \
635 'gitweb_run "p=.git;a=summary"'
636 test_debug 'cat gitweb.log'
638 test_expect_success \
639 'URL: project URLs via gitweb.url' \
640 'git config --add gitweb.url git://example.com/git/trash.git &&
641 git config --add gitweb.url http://example.com/git/trash.git &&
642 gitweb_run "p=.git;a=summary"'
643 test_debug 'cat gitweb.log'
645 cat >.git/cloneurl <<\EOF
646 git://example.com/git/trash.git
647 http://example.com/git/trash.git
650 test_expect_success \
651 'URL: project URLs via cloneurl file' \
652 'gitweb_run "p=.git;a=summary"'
653 test_debug 'cat gitweb.log'
655 # ----------------------------------------------------------------------
656 # gitweb config and repo config
658 cat >>gitweb_config.perl <<EOF
660 \$feature{'blame'}{'override'} = 1;
661 \$feature{'snapshot'}{'override'} = 1;
664 test_expect_success \
665 'config override: tree view, features not overridden in repo config' \
666 'gitweb_run "p=.git;a=tree"'
667 test_debug 'cat gitweb.log'
669 test_expect_success \
670 'config override: tree view, features disabled in repo config' \
671 'git config gitweb.blame no &&
672 git config gitweb.snapshot none &&
673 gitweb_run "p=.git;a=tree"'
674 test_debug 'cat gitweb.log'
676 test_expect_success \
677 'config override: tree view, features enabled in repo config (1)' \
678 'git config gitweb.blame yes &&
679 git config gitweb.snapshot "zip,tgz, tbz2" &&
680 gitweb_run "p=.git;a=tree"'
681 test_debug 'cat gitweb.log'
683 cat >.git/config <<\EOF
684 # testing noval and alternate separator
689 test_expect_success \
690 'config override: tree view, features enabled in repo config (2)' \
691 'gitweb_run "p=.git;a=tree"'
692 test_debug 'cat gitweb.log'
694 # ----------------------------------------------------------------------
695 # non-ASCII in README.html
697 test_expect_success \
698 'README.html with non-ASCII characters (utf-8)' \
699 'echo "<b>UTF-8 example:</b><br />" > .git/README.html &&
700 cat "$TEST_DIRECTORY"/t3900/1-UTF-8.txt >> .git/README.html &&
701 gitweb_run "p=.git;a=summary"'
702 test_debug 'cat gitweb.log'