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 say
'gitweb not supported, skipping tests.'
71 if ! test_have_prereq PERL
; then
72 say
'skipping gitweb tests, perl not available'
76 perl
-MEncode -e 'decode_utf8("", Encode::FB_CROAK)' >/dev
/null
2>&1 ||
{
77 say
'skipping gitweb tests, perl version is too old'
83 # ----------------------------------------------------------------------
84 # no commits (empty, just initialized repository)
87 'no commits: projects_list (implicit)' \
89 test_debug
'cat gitweb.log'
92 'no commits: projects_index' \
93 'gitweb_run "a=project_index"'
94 test_debug
'cat gitweb.log'
97 'no commits: .git summary (implicit)' \
99 test_debug
'cat gitweb.log'
101 test_expect_success \
102 'no commits: .git commit (implicit HEAD)' \
103 'gitweb_run "p=.git;a=commit"'
104 test_debug
'cat gitweb.log'
106 test_expect_success \
107 'no commits: .git commitdiff (implicit HEAD)' \
108 'gitweb_run "p=.git;a=commitdiff"'
109 test_debug
'cat gitweb.log'
111 test_expect_success \
112 'no commits: .git tree (implicit HEAD)' \
113 'gitweb_run "p=.git;a=tree"'
114 test_debug
'cat gitweb.log'
116 test_expect_success \
117 'no commits: .git heads' \
118 'gitweb_run "p=.git;a=heads"'
119 test_debug
'cat gitweb.log'
121 test_expect_success \
122 'no commits: .git tags' \
123 'gitweb_run "p=.git;a=tags"'
124 test_debug
'cat gitweb.log'
127 # ----------------------------------------------------------------------
130 test_expect_success \
131 'Make initial commit' \
132 'echo "Not an empty file." > file &&
134 git commit -a -m "Initial commit." &&
137 test_expect_success \
138 'projects_list (implicit)' \
140 test_debug
'cat gitweb.log'
142 test_expect_success \
144 'gitweb_run "a=project_index"'
145 test_debug
'cat gitweb.log'
147 test_expect_success \
148 '.git summary (implicit)' \
149 'gitweb_run "p=.git"'
150 test_debug
'cat gitweb.log'
152 test_expect_success \
153 '.git commit (implicit HEAD)' \
154 'gitweb_run "p=.git;a=commit"'
155 test_debug
'cat gitweb.log'
157 test_expect_success \
158 '.git commitdiff (implicit HEAD, root commit)' \
159 'gitweb_run "p=.git;a=commitdiff"'
160 test_debug
'cat gitweb.log'
162 test_expect_success \
163 '.git commitdiff_plain (implicit HEAD, root commit)' \
164 'gitweb_run "p=.git;a=commitdiff_plain"'
165 test_debug
'cat gitweb.log'
167 test_expect_success \
168 '.git commit (HEAD)' \
169 'gitweb_run "p=.git;a=commit;h=HEAD"'
170 test_debug
'cat gitweb.log'
172 test_expect_success \
173 '.git tree (implicit HEAD)' \
174 'gitweb_run "p=.git;a=tree"'
175 test_debug
'cat gitweb.log'
177 test_expect_success \
179 'gitweb_run "p=.git;a=blob;f=file"'
180 test_debug
'cat gitweb.log'
182 test_expect_success \
183 '.git blob_plain (file)' \
184 'gitweb_run "p=.git;a=blob_plain;f=file"'
185 test_debug
'cat gitweb.log'
187 # ----------------------------------------------------------------------
188 # nonexistent objects
190 test_expect_success \
191 '.git commit (non-existent)' \
192 'gitweb_run "p=.git;a=commit;h=non-existent"'
193 test_debug
'cat gitweb.log'
195 test_expect_success \
196 '.git commitdiff (non-existent)' \
197 'gitweb_run "p=.git;a=commitdiff;h=non-existent"'
198 test_debug
'cat gitweb.log'
200 test_expect_success \
201 '.git commitdiff (non-existent vs HEAD)' \
202 'gitweb_run "p=.git;a=commitdiff;hp=non-existent;h=HEAD"'
203 test_debug
'cat gitweb.log'
205 test_expect_success \
206 '.git tree (0000000000000000000000000000000000000000)' \
207 'gitweb_run "p=.git;a=tree;h=0000000000000000000000000000000000000000"'
208 test_debug
'cat gitweb.log'
210 test_expect_success \
211 '.git tag (0000000000000000000000000000000000000000)' \
212 'gitweb_run "p=.git;a=tag;h=0000000000000000000000000000000000000000"'
213 test_debug
'cat gitweb.log'
215 test_expect_success \
216 '.git blob (non-existent)' \
217 'gitweb_run "p=.git;a=blob;f=non-existent"'
218 test_debug
'cat gitweb.log'
220 test_expect_success \
221 '.git blob_plain (non-existent)' \
222 'gitweb_run "p=.git;a=blob_plain;f=non-existent"'
223 test_debug
'cat gitweb.log'
226 # ----------------------------------------------------------------------
227 # commitdiff testing (implicit, one implicit tree-ish)
229 test_expect_success \
230 'commitdiff(0): root' \
231 'gitweb_run "p=.git;a=commitdiff"'
232 test_debug
'cat gitweb.log'
234 test_expect_success \
235 'commitdiff(0): file added' \
236 'echo "New file" > new_file &&
238 git commit -a -m "File added." &&
239 gitweb_run "p=.git;a=commitdiff"'
240 test_debug
'cat gitweb.log'
242 test_expect_success \
243 'commitdiff(0): mode change' \
244 'test_chmod +x new_file &&
245 git commit -a -m "Mode changed." &&
246 gitweb_run "p=.git;a=commitdiff"'
247 test_debug
'cat gitweb.log'
249 test_expect_success \
250 'commitdiff(0): file renamed' \
251 'git mv new_file renamed_file &&
252 git commit -a -m "File renamed." &&
253 gitweb_run "p=.git;a=commitdiff"'
254 test_debug
'cat gitweb.log'
256 test_expect_success SYMLINKS \
257 'commitdiff(0): file to symlink' \
259 ln -s file renamed_file &&
260 git commit -a -m "File to symlink." &&
261 gitweb_run "p=.git;a=commitdiff"'
262 test_debug
'cat gitweb.log'
264 test_expect_success \
265 'commitdiff(0): file deleted' \
266 'git rm renamed_file &&
267 rm -f renamed_file &&
268 git commit -a -m "File removed." &&
269 gitweb_run "p=.git;a=commitdiff"'
270 test_debug
'cat gitweb.log'
272 test_expect_success \
273 'commitdiff(0): file copied / new file' \
276 git commit -a -m "File copied." &&
277 gitweb_run "p=.git;a=commitdiff"'
278 test_debug
'cat gitweb.log'
280 test_expect_success \
281 'commitdiff(0): mode change and modified' \
282 'echo "New line" >> file2 &&
283 test_chmod +x file2 &&
284 git commit -a -m "Mode change and modification." &&
285 gitweb_run "p=.git;a=commitdiff"'
286 test_debug
'cat gitweb.log'
288 test_expect_success \
289 'commitdiff(0): renamed and modified' \
292 et nihil mihi deerit.
293 In loco pascuae ibi me collocavit,
294 super aquam refectionis educavit me;
295 animam meam convertit,
296 deduxit me super semitas jusitiae,
299 git commit -a -m "File added." &&
300 git mv file2 file3 &&
301 echo "Propter nomen suum." >> file3 &&
302 git commit -a -m "File rename and modification." &&
303 gitweb_run "p=.git;a=commitdiff"'
304 test_debug
'cat gitweb.log'
306 test_expect_success \
307 'commitdiff(0): renamed, mode change and modified' \
308 'git mv file3 file2 &&
309 echo "Propter nomen suum." >> file2 &&
310 test_chmod +x file2 &&
311 git commit -a -m "File rename, mode change and modification." &&
312 gitweb_run "p=.git;a=commitdiff"'
313 test_debug
'cat gitweb.log'
315 # ----------------------------------------------------------------------
316 # commitdiff testing (taken from t4114-apply-typechange.sh)
318 test_expect_success SYMLINKS
'setup typechange commits' '
319 echo "hello world" > foo &&
320 echo "hi planet" > bar &&
321 git update-index --add foo bar &&
322 git commit -m initial &&
323 git branch initial &&
326 git update-index foo &&
327 git commit -m "foo symlinked to bar" &&
328 git branch foo-symlinked-to-bar &&
330 echo "how far is the sun?" > foo &&
331 git update-index foo &&
332 git commit -m "foo back to file" &&
333 git branch foo-back-to-file &&
335 git update-index --remove foo &&
337 echo "if only I knew" > foo/baz &&
338 git update-index --add foo/baz &&
339 git commit -m "foo becomes a directory" &&
340 git branch "foo-becomes-a-directory" &&
341 echo "hello world" > foo/baz &&
342 git update-index foo/baz &&
343 git commit -m "foo/baz is the original foo" &&
344 git branch foo-baz-renamed-from-foo
347 test_expect_success \
348 'commitdiff(2): file renamed from foo to foo/baz' \
349 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-baz-renamed-from-foo"'
350 test_debug
'cat gitweb.log'
352 test_expect_success \
353 'commitdiff(2): file renamed from foo/baz to foo' \
354 'gitweb_run "p=.git;a=commitdiff;hp=foo-baz-renamed-from-foo;h=initial"'
355 test_debug
'cat gitweb.log'
357 test_expect_success \
358 'commitdiff(2): directory becomes file' \
359 'gitweb_run "p=.git;a=commitdiff;hp=foo-becomes-a-directory;h=initial"'
360 test_debug
'cat gitweb.log'
362 test_expect_success \
363 'commitdiff(2): file becomes directory' \
364 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-becomes-a-directory"'
365 test_debug
'cat gitweb.log'
367 test_expect_success \
368 'commitdiff(2): file becomes symlink' \
369 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-symlinked-to-bar"'
370 test_debug
'cat gitweb.log'
372 test_expect_success \
373 'commitdiff(2): symlink becomes file' \
374 'gitweb_run "p=.git;a=commitdiff;hp=foo-symlinked-to-bar;h=foo-back-to-file"'
375 test_debug
'cat gitweb.log'
377 test_expect_success \
378 'commitdiff(2): symlink becomes directory' \
379 'gitweb_run "p=.git;a=commitdiff;hp=foo-symlinked-to-bar;h=foo-becomes-a-directory"'
380 test_debug
'cat gitweb.log'
382 test_expect_success \
383 'commitdiff(2): directory becomes symlink' \
384 'gitweb_run "p=.git;a=commitdiff;hp=foo-becomes-a-directory;h=foo-symlinked-to-bar"'
385 test_debug
'cat gitweb.log'
387 # ----------------------------------------------------------------------
388 # commit, commitdiff: merge, large
389 test_expect_success \
392 echo "Branch" >> b &&
394 git commit -a -m "On branch" &&
395 git checkout master &&
398 test_expect_success \
399 'commit(0): merge commit' \
400 'gitweb_run "p=.git;a=commit"'
401 test_debug
'cat gitweb.log'
403 test_expect_success \
404 'commitdiff(0): merge commit' \
405 'gitweb_run "p=.git;a=commitdiff"'
406 test_debug
'cat gitweb.log'
408 test_expect_success \
409 'Prepare large commit' \
411 echo "To be changed" > 01-change &&
412 echo "To be renamed" > 02-pure-rename-from &&
413 echo "To be deleted" > 03-delete &&
414 echo "To be renamed and changed" > 04-rename-from &&
415 echo "To have mode changed" > 05-mode-change &&
416 echo "File to symlink" > 06-file-or-symlink &&
417 echo "To be changed and have mode changed" > 07-change-mode-change &&
419 git commit -a -m "Prepare large commit" &&
420 echo "Changed" > 01-change &&
421 git mv 02-pure-rename-from 02-pure-rename-to &&
422 git rm 03-delete && rm -f 03-delete &&
423 echo "A new file" > 03-new &&
425 git mv 04-rename-from 04-rename-to &&
426 echo "Changed" >> 04-rename-to &&
427 test_chmod +x 05-mode-change &&
428 rm -f 06-file-or-symlink &&
429 if test_have_prereq SYMLINKS; then
430 ln -s 01-change 06-file-or-symlink
432 printf %s 01-change > 06-file-or-symlink
434 echo "Changed and have mode changed" > 07-change-mode-change &&
435 test_chmod +x 07-change-mode-change &&
436 git commit -a -m "Large commit" &&
439 test_expect_success \
440 'commit(1): large commit' \
441 'gitweb_run "p=.git;a=commit;h=b"'
442 test_debug
'cat gitweb.log'
444 test_expect_success \
445 'commitdiff(1): large commit' \
446 'gitweb_run "p=.git;a=commitdiff;h=b"'
447 test_debug
'cat gitweb.log'
449 # ----------------------------------------------------------------------
452 test_expect_success \
453 'tags: list of different types of tags' \
454 'git checkout master &&
455 git tag -a -m "Tag commit object" tag-commit HEAD &&
456 git tag -a -m "" tag-commit-nomessage HEAD &&
457 git tag -a -m "Tag tag object" tag-tag tag-commit &&
458 git tag -a -m "Tag tree object" tag-tree HEAD^{tree} &&
459 git tag -a -m "Tag blob object" tag-blob HEAD:file &&
460 git tag lightweight/tag-commit HEAD &&
461 git tag lightweight/tag-tag tag-commit &&
462 git tag lightweight/tag-tree HEAD^{tree} &&
463 git tag lightweight/tag-blob HEAD:file &&
464 gitweb_run "p=.git;a=tags"'
465 test_debug
'cat gitweb.log'
467 test_expect_success \
468 'tag: Tag to commit object' \
469 'gitweb_run "p=.git;a=tag;h=tag-commit"'
470 test_debug
'cat gitweb.log'
472 test_expect_success \
473 'tag: on lightweight tag (invalid)' \
474 'gitweb_run "p=.git;a=tag;h=lightweight/tag-commit"'
475 test_debug
'cat gitweb.log'
477 # ----------------------------------------------------------------------
480 test_expect_success \
481 'logs: log (implicit HEAD)' \
482 'gitweb_run "p=.git;a=log"'
483 test_debug
'cat gitweb.log'
485 test_expect_success \
486 'logs: shortlog (implicit HEAD)' \
487 'gitweb_run "p=.git;a=shortlog"'
488 test_debug
'cat gitweb.log'
490 test_expect_success \
491 'logs: history (implicit HEAD, file)' \
492 'gitweb_run "p=.git;a=history;f=file"'
493 test_debug
'cat gitweb.log'
495 test_expect_success \
496 'logs: history (implicit HEAD, non-existent file)' \
497 'gitweb_run "p=.git;a=history;f=non-existent"'
498 test_debug
'cat gitweb.log'
500 test_expect_success \
501 'logs: history (implicit HEAD, deleted file)' \
502 'git checkout master &&
503 echo "to be deleted" > deleted_file &&
504 git add deleted_file &&
505 git commit -m "Add file to be deleted" &&
506 git rm deleted_file &&
507 git commit -m "Delete file" &&
508 gitweb_run "p=.git;a=history;f=deleted_file"'
509 test_debug
'cat gitweb.log'
511 # ----------------------------------------------------------------------
513 test_expect_success \
514 'path_info: project' \
515 'gitweb_run "" "/.git"'
516 test_debug
'cat gitweb.log'
518 test_expect_success \
519 'path_info: project/branch' \
520 'gitweb_run "" "/.git/b"'
521 test_debug
'cat gitweb.log'
523 test_expect_success \
524 'path_info: project/branch:file' \
525 'gitweb_run "" "/.git/master:file"'
526 test_debug
'cat gitweb.log'
528 test_expect_success \
529 'path_info: project/branch:dir/' \
530 'gitweb_run "" "/.git/master:foo/"'
531 test_debug
'cat gitweb.log'
533 test_expect_success \
534 'path_info: project/branch:file (non-existent)' \
535 'gitweb_run "" "/.git/master:non-existent"'
536 test_debug
'cat gitweb.log'
538 test_expect_success \
539 'path_info: project/branch:dir/ (non-existent)' \
540 'gitweb_run "" "/.git/master:non-existent/"'
541 test_debug
'cat gitweb.log'
544 test_expect_success \
545 'path_info: project/branch:/file' \
546 'gitweb_run "" "/.git/master:/file"'
547 test_debug
'cat gitweb.log'
549 test_expect_success \
550 'path_info: project/:/file (implicit HEAD)' \
551 'gitweb_run "" "/.git/:/file"'
552 test_debug
'cat gitweb.log'
554 test_expect_success \
555 'path_info: project/:/ (implicit HEAD, top tree)' \
556 'gitweb_run "" "/.git/:/"'
557 test_debug
'cat gitweb.log'
560 # ----------------------------------------------------------------------
563 test_expect_success \
565 'gitweb_run "a=opml"'
566 test_debug
'cat gitweb.log'
568 test_expect_success \
570 'gitweb_run "p=.git;a=rss"'
571 test_debug
'cat gitweb.log'
573 test_expect_success \
575 'gitweb_run "p=.git;a=atom"'
576 test_debug
'cat gitweb.log'
578 # ----------------------------------------------------------------------
581 test_expect_success \
582 'encode(commit): utf8' \
583 '. "$TEST_DIRECTORY"/t3901-utf8.txt &&
584 echo "UTF-8" >> file &&
586 git commit -F "$TEST_DIRECTORY"/t3900/1-UTF-8.txt &&
587 gitweb_run "p=.git;a=commit"'
588 test_debug
'cat gitweb.log'
590 test_expect_success \
591 'encode(commit): iso-8859-1' \
592 '. "$TEST_DIRECTORY"/t3901-8859-1.txt &&
593 echo "ISO-8859-1" >> file &&
595 git config i18n.commitencoding ISO-8859-1 &&
596 git commit -F "$TEST_DIRECTORY"/t3900/ISO-8859-1.txt &&
597 git config --unset i18n.commitencoding &&
598 gitweb_run "p=.git;a=commit"'
599 test_debug
'cat gitweb.log'
601 test_expect_success \
602 'encode(log): utf-8 and iso-8859-1' \
603 'gitweb_run "p=.git;a=log"'
604 test_debug
'cat gitweb.log'
606 # ----------------------------------------------------------------------
609 test_expect_success \
610 'opt: log --no-merges' \
611 'gitweb_run "p=.git;a=log;opt=--no-merges"'
612 test_debug
'cat gitweb.log'
614 test_expect_success \
615 'opt: atom --no-merges' \
616 'gitweb_run "p=.git;a=log;opt=--no-merges"'
617 test_debug
'cat gitweb.log'
619 test_expect_success \
620 'opt: "file" history --no-merges' \
621 'gitweb_run "p=.git;a=history;f=file;opt=--no-merges"'
622 test_debug
'cat gitweb.log'
624 test_expect_success \
625 'opt: log --no-such-option (invalid option)' \
626 'gitweb_run "p=.git;a=log;opt=--no-such-option"'
627 test_debug
'cat gitweb.log'
629 test_expect_success \
630 'opt: tree --no-merges (invalid option for action)' \
631 'gitweb_run "p=.git;a=tree;opt=--no-merges"'
632 test_debug
'cat gitweb.log'
634 # ----------------------------------------------------------------------
635 # testing config_to_multi / cloneurl
637 test_expect_success \
638 'URL: no project URLs, no base URL' \
639 'gitweb_run "p=.git;a=summary"'
640 test_debug
'cat gitweb.log'
642 test_expect_success \
643 'URL: project URLs via gitweb.url' \
644 'git config --add gitweb.url git://example.com/git/trash.git &&
645 git config --add gitweb.url http://example.com/git/trash.git &&
646 gitweb_run "p=.git;a=summary"'
647 test_debug
'cat gitweb.log'
649 cat >.git
/cloneurl
<<\EOF
650 git
://example.com
/git
/trash.git
651 http
://example.com
/git
/trash.git
654 test_expect_success \
655 'URL: project URLs via cloneurl file' \
656 'gitweb_run "p=.git;a=summary"'
657 test_debug
'cat gitweb.log'
659 # ----------------------------------------------------------------------
660 # gitweb config and repo config
662 cat >>gitweb_config.perl
<<EOF
664 \$feature{'blame'}{'override'} = 1;
665 \$feature{'snapshot'}{'override'} = 1;
668 test_expect_success \
669 'config override: tree view, features not overridden in repo config' \
670 'gitweb_run "p=.git;a=tree"'
671 test_debug
'cat gitweb.log'
673 test_expect_success \
674 'config override: tree view, features disabled in repo config' \
675 'git config gitweb.blame no &&
676 git config gitweb.snapshot none &&
677 gitweb_run "p=.git;a=tree"'
678 test_debug
'cat gitweb.log'
680 test_expect_success \
681 'config override: tree view, features enabled in repo config (1)' \
682 'git config gitweb.blame yes &&
683 git config gitweb.snapshot "zip,tgz, tbz2" &&
684 gitweb_run "p=.git;a=tree"'
685 test_debug
'cat gitweb.log'
687 cat >.git
/config
<<\EOF
688 # testing noval and alternate separator
693 test_expect_success \
694 'config override: tree view, features enabled in repo config (2)' \
695 'gitweb_run "p=.git;a=tree"'
696 test_debug
'cat gitweb.log'
698 # ----------------------------------------------------------------------
699 # non-ASCII in README.html
701 test_expect_success \
702 'README.html with non-ASCII characters (utf-8)' \
703 'echo "<b>UTF-8 example:</b><br />" > .git/README.html &&
704 cat "$TEST_DIRECTORY"/t3900/1-UTF-8.txt >> .git/README.html &&
705 gitweb_run "p=.git;a=summary"'
706 test_debug
'cat gitweb.log'