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 perl
-MEncode -e 'decode_utf8("", Encode::FB_CROAK)' >/dev
/null
2>&1 ||
{
69 say
'skipping gitweb tests, perl version is too old'
76 # ----------------------------------------------------------------------
77 # no commits (empty, just initialized repository)
80 'no commits: projects_list (implicit)' \
82 test_debug
'cat gitweb.log'
85 'no commits: projects_index' \
86 'gitweb_run "a=project_index"'
87 test_debug
'cat gitweb.log'
90 'no commits: .git summary (implicit)' \
92 test_debug
'cat gitweb.log'
95 'no commits: .git commit (implicit HEAD)' \
96 'gitweb_run "p=.git;a=commit"'
97 test_debug
'cat gitweb.log'
100 'no commits: .git commitdiff (implicit HEAD)' \
101 'gitweb_run "p=.git;a=commitdiff"'
102 test_debug
'cat gitweb.log'
104 test_expect_success \
105 'no commits: .git tree (implicit HEAD)' \
106 'gitweb_run "p=.git;a=tree"'
107 test_debug
'cat gitweb.log'
109 test_expect_success \
110 'no commits: .git heads' \
111 'gitweb_run "p=.git;a=heads"'
112 test_debug
'cat gitweb.log'
114 test_expect_success \
115 'no commits: .git tags' \
116 'gitweb_run "p=.git;a=tags"'
117 test_debug
'cat gitweb.log'
120 # ----------------------------------------------------------------------
123 test_expect_success \
124 'Make initial commit' \
125 'echo "Not an empty file." > file &&
127 git commit -a -m "Initial commit." &&
130 test_expect_success \
131 'projects_list (implicit)' \
133 test_debug
'cat gitweb.log'
135 test_expect_success \
137 'gitweb_run "a=project_index"'
138 test_debug
'cat gitweb.log'
140 test_expect_success \
141 '.git summary (implicit)' \
142 'gitweb_run "p=.git"'
143 test_debug
'cat gitweb.log'
145 test_expect_success \
146 '.git commit (implicit HEAD)' \
147 'gitweb_run "p=.git;a=commit"'
148 test_debug
'cat gitweb.log'
150 test_expect_success \
151 '.git commitdiff (implicit HEAD, root commit)' \
152 'gitweb_run "p=.git;a=commitdiff"'
153 test_debug
'cat gitweb.log'
155 test_expect_success \
156 '.git commitdiff_plain (implicit HEAD, root commit)' \
157 'gitweb_run "p=.git;a=commitdiff_plain"'
158 test_debug
'cat gitweb.log'
160 test_expect_success \
161 '.git commit (HEAD)' \
162 'gitweb_run "p=.git;a=commit;h=HEAD"'
163 test_debug
'cat gitweb.log'
165 test_expect_success \
166 '.git tree (implicit HEAD)' \
167 'gitweb_run "p=.git;a=tree"'
168 test_debug
'cat gitweb.log'
170 test_expect_success \
172 'gitweb_run "p=.git;a=blob;f=file"'
173 test_debug
'cat gitweb.log'
175 test_expect_success \
176 '.git blob_plain (file)' \
177 'gitweb_run "p=.git;a=blob_plain;f=file"'
178 test_debug
'cat gitweb.log'
180 # ----------------------------------------------------------------------
181 # nonexistent objects
183 test_expect_success \
184 '.git commit (non-existent)' \
185 'gitweb_run "p=.git;a=commit;h=non-existent"'
186 test_debug
'cat gitweb.log'
188 test_expect_success \
189 '.git commitdiff (non-existent)' \
190 'gitweb_run "p=.git;a=commitdiff;h=non-existent"'
191 test_debug
'cat gitweb.log'
193 test_expect_success \
194 '.git commitdiff (non-existent vs HEAD)' \
195 'gitweb_run "p=.git;a=commitdiff;hp=non-existent;h=HEAD"'
196 test_debug
'cat gitweb.log'
198 test_expect_success \
199 '.git tree (0000000000000000000000000000000000000000)' \
200 'gitweb_run "p=.git;a=tree;h=0000000000000000000000000000000000000000"'
201 test_debug
'cat gitweb.log'
203 test_expect_success \
204 '.git tag (0000000000000000000000000000000000000000)' \
205 'gitweb_run "p=.git;a=tag;h=0000000000000000000000000000000000000000"'
206 test_debug
'cat gitweb.log'
208 test_expect_success \
209 '.git blob (non-existent)' \
210 'gitweb_run "p=.git;a=blob;f=non-existent"'
211 test_debug
'cat gitweb.log'
213 test_expect_success \
214 '.git blob_plain (non-existent)' \
215 'gitweb_run "p=.git;a=blob_plain;f=non-existent"'
216 test_debug
'cat gitweb.log'
219 # ----------------------------------------------------------------------
220 # commitdiff testing (implicit, one implicit tree-ish)
222 test_expect_success \
223 'commitdiff(0): root' \
224 'gitweb_run "p=.git;a=commitdiff"'
225 test_debug
'cat gitweb.log'
227 test_expect_success \
228 'commitdiff(0): file added' \
229 'echo "New file" > new_file &&
231 git commit -a -m "File added." &&
232 gitweb_run "p=.git;a=commitdiff"'
233 test_debug
'cat gitweb.log'
235 test_expect_success \
236 'commitdiff(0): mode change' \
237 'test_chmod +x new_file &&
238 git commit -a -m "Mode changed." &&
239 gitweb_run "p=.git;a=commitdiff"'
240 test_debug
'cat gitweb.log'
242 test_expect_success \
243 'commitdiff(0): file renamed' \
244 'git mv new_file renamed_file &&
245 git commit -a -m "File renamed." &&
246 gitweb_run "p=.git;a=commitdiff"'
247 test_debug
'cat gitweb.log'
249 test_expect_success \
250 'commitdiff(0): file to symlink' \
252 ln -s file renamed_file &&
253 git commit -a -m "File to symlink." &&
254 gitweb_run "p=.git;a=commitdiff"'
255 test_debug
'cat gitweb.log'
257 test_expect_success \
258 'commitdiff(0): file deleted' \
259 'git rm renamed_file &&
260 rm -f renamed_file &&
261 git commit -a -m "File removed." &&
262 gitweb_run "p=.git;a=commitdiff"'
263 test_debug
'cat gitweb.log'
265 test_expect_success \
266 'commitdiff(0): file copied / new file' \
269 git commit -a -m "File copied." &&
270 gitweb_run "p=.git;a=commitdiff"'
271 test_debug
'cat gitweb.log'
273 test_expect_success \
274 'commitdiff(0): mode change and modified' \
275 'echo "New line" >> file2 &&
276 test_chmod +x file2 &&
277 git commit -a -m "Mode change and modification." &&
278 gitweb_run "p=.git;a=commitdiff"'
279 test_debug
'cat gitweb.log'
281 test_expect_success \
282 'commitdiff(0): renamed and modified' \
285 et nihil mihi deerit.
286 In loco pascuae ibi me collocavit,
287 super aquam refectionis educavit me;
288 animam meam convertit,
289 deduxit me super semitas jusitiae,
292 git commit -a -m "File added." &&
293 git mv file2 file3 &&
294 echo "Propter nomen suum." >> file3 &&
295 git commit -a -m "File rename and modification." &&
296 gitweb_run "p=.git;a=commitdiff"'
297 test_debug
'cat gitweb.log'
299 test_expect_success \
300 'commitdiff(0): renamed, mode change and modified' \
301 'git mv file3 file2 &&
302 echo "Propter nomen suum." >> file2 &&
303 test_chmod +x file2 &&
304 git commit -a -m "File rename, mode change and modification." &&
305 gitweb_run "p=.git;a=commitdiff"'
306 test_debug
'cat gitweb.log'
308 # ----------------------------------------------------------------------
309 # commitdiff testing (taken from t4114-apply-typechange.sh)
311 test_expect_success
'setup typechange commits' '
312 echo "hello world" > foo &&
313 echo "hi planet" > bar &&
314 git update-index --add foo bar &&
315 git commit -m initial &&
316 git branch initial &&
319 git update-index foo &&
320 git commit -m "foo symlinked to bar" &&
321 git branch foo-symlinked-to-bar &&
323 echo "how far is the sun?" > foo &&
324 git update-index foo &&
325 git commit -m "foo back to file" &&
326 git branch foo-back-to-file &&
328 git update-index --remove foo &&
330 echo "if only I knew" > foo/baz &&
331 git update-index --add foo/baz &&
332 git commit -m "foo becomes a directory" &&
333 git branch "foo-becomes-a-directory" &&
334 echo "hello world" > foo/baz &&
335 git update-index foo/baz &&
336 git commit -m "foo/baz is the original foo" &&
337 git branch foo-baz-renamed-from-foo
340 test_expect_success \
341 'commitdiff(2): file renamed from foo to foo/baz' \
342 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-baz-renamed-from-foo"'
343 test_debug
'cat gitweb.log'
345 test_expect_success \
346 'commitdiff(2): file renamed from foo/baz to foo' \
347 'gitweb_run "p=.git;a=commitdiff;hp=foo-baz-renamed-from-foo;h=initial"'
348 test_debug
'cat gitweb.log'
350 test_expect_success \
351 'commitdiff(2): directory becomes file' \
352 'gitweb_run "p=.git;a=commitdiff;hp=foo-becomes-a-directory;h=initial"'
353 test_debug
'cat gitweb.log'
355 test_expect_success \
356 'commitdiff(2): file becomes directory' \
357 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-becomes-a-directory"'
358 test_debug
'cat gitweb.log'
360 test_expect_success \
361 'commitdiff(2): file becomes symlink' \
362 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-symlinked-to-bar"'
363 test_debug
'cat gitweb.log'
365 test_expect_success \
366 'commitdiff(2): symlink becomes file' \
367 'gitweb_run "p=.git;a=commitdiff;hp=foo-symlinked-to-bar;h=foo-back-to-file"'
368 test_debug
'cat gitweb.log'
370 test_expect_success \
371 'commitdiff(2): symlink becomes directory' \
372 'gitweb_run "p=.git;a=commitdiff;hp=foo-symlinked-to-bar;h=foo-becomes-a-directory"'
373 test_debug
'cat gitweb.log'
375 test_expect_success \
376 'commitdiff(2): directory becomes symlink' \
377 'gitweb_run "p=.git;a=commitdiff;hp=foo-becomes-a-directory;h=foo-symlinked-to-bar"'
378 test_debug
'cat gitweb.log'
380 # ----------------------------------------------------------------------
381 # commit, commitdiff: merge, large
382 test_expect_success \
385 echo "Branch" >> b &&
387 git commit -a -m "On branch" &&
388 git checkout master &&
391 test_expect_success \
392 'commit(0): merge commit' \
393 'gitweb_run "p=.git;a=commit"'
394 test_debug
'cat gitweb.log'
396 test_expect_success \
397 'commitdiff(0): merge commit' \
398 'gitweb_run "p=.git;a=commitdiff"'
399 test_debug
'cat gitweb.log'
401 test_expect_success \
402 'Prepare large commit' \
404 echo "To be changed" > 01-change &&
405 echo "To be renamed" > 02-pure-rename-from &&
406 echo "To be deleted" > 03-delete &&
407 echo "To be renamed and changed" > 04-rename-from &&
408 echo "To have mode changed" > 05-mode-change &&
409 echo "File to symlink" > 06-file-or-symlink &&
410 echo "To be changed and have mode changed" > 07-change-mode-change &&
412 git commit -a -m "Prepare large commit" &&
413 echo "Changed" > 01-change &&
414 git mv 02-pure-rename-from 02-pure-rename-to &&
415 git rm 03-delete && rm -f 03-delete &&
416 echo "A new file" > 03-new &&
418 git mv 04-rename-from 04-rename-to &&
419 echo "Changed" >> 04-rename-to &&
420 test_chmod +x 05-mode-change &&
421 rm -f 06-file-or-symlink && ln -s 01-change 06-file-or-symlink &&
422 echo "Changed and have mode changed" > 07-change-mode-change &&
423 test_chmod +x 07-change-mode-change &&
424 git commit -a -m "Large commit" &&
427 test_expect_success \
428 'commit(1): large commit' \
429 'gitweb_run "p=.git;a=commit;h=b"'
430 test_debug
'cat gitweb.log'
432 test_expect_success \
433 'commitdiff(1): large commit' \
434 'gitweb_run "p=.git;a=commitdiff;h=b"'
435 test_debug
'cat gitweb.log'
437 # ----------------------------------------------------------------------
440 test_expect_success \
441 'tags: list of different types of tags' \
442 'git checkout master &&
443 git tag -a -m "Tag commit object" tag-commit HEAD &&
444 git tag -a -m "" tag-commit-nomessage HEAD &&
445 git tag -a -m "Tag tag object" tag-tag tag-commit &&
446 git tag -a -m "Tag tree object" tag-tree HEAD^{tree} &&
447 git tag -a -m "Tag blob object" tag-blob HEAD:file &&
448 git tag lightweight/tag-commit HEAD &&
449 git tag lightweight/tag-tag tag-commit &&
450 git tag lightweight/tag-tree HEAD^{tree} &&
451 git tag lightweight/tag-blob HEAD:file &&
452 gitweb_run "p=.git;a=tags"'
453 test_debug
'cat gitweb.log'
455 test_expect_success \
456 'tag: Tag to commit object' \
457 'gitweb_run "p=.git;a=tag;h=tag-commit"'
458 test_debug
'cat gitweb.log'
460 test_expect_success \
461 'tag: on lightweight tag (invalid)' \
462 'gitweb_run "p=.git;a=tag;h=lightweight/tag-commit"'
463 test_debug
'cat gitweb.log'
465 # ----------------------------------------------------------------------
468 test_expect_success \
469 'logs: log (implicit HEAD)' \
470 'gitweb_run "p=.git;a=log"'
471 test_debug
'cat gitweb.log'
473 test_expect_success \
474 'logs: shortlog (implicit HEAD)' \
475 'gitweb_run "p=.git;a=shortlog"'
476 test_debug
'cat gitweb.log'
478 test_expect_success \
479 'logs: history (implicit HEAD, file)' \
480 'gitweb_run "p=.git;a=history;f=file"'
481 test_debug
'cat gitweb.log'
483 test_expect_success \
484 'logs: history (implicit HEAD, non-existent file)' \
485 'gitweb_run "p=.git;a=history;f=non-existent"'
486 test_debug
'cat gitweb.log'
488 test_expect_success \
489 'logs: history (implicit HEAD, deleted file)' \
490 'git checkout master &&
491 echo "to be deleted" > deleted_file &&
492 git add deleted_file &&
493 git commit -m "Add file to be deleted" &&
494 git rm deleted_file &&
495 git commit -m "Delete file" &&
496 gitweb_run "p=.git;a=history;f=deleted_file"'
497 test_debug
'cat gitweb.log'
499 # ----------------------------------------------------------------------
501 test_expect_success \
502 'path_info: project' \
503 'gitweb_run "" "/.git"'
504 test_debug
'cat gitweb.log'
506 test_expect_success \
507 'path_info: project/branch' \
508 'gitweb_run "" "/.git/b"'
509 test_debug
'cat gitweb.log'
511 test_expect_success \
512 'path_info: project/branch:file' \
513 'gitweb_run "" "/.git/master:file"'
514 test_debug
'cat gitweb.log'
516 test_expect_success \
517 'path_info: project/branch:dir/' \
518 'gitweb_run "" "/.git/master:foo/"'
519 test_debug
'cat gitweb.log'
521 test_expect_success \
522 'path_info: project/branch:file (non-existent)' \
523 'gitweb_run "" "/.git/master:non-existent"'
524 test_debug
'cat gitweb.log'
526 test_expect_success \
527 'path_info: project/branch:dir/ (non-existent)' \
528 'gitweb_run "" "/.git/master:non-existent/"'
529 test_debug
'cat gitweb.log'
532 test_expect_success \
533 'path_info: project/branch:/file' \
534 'gitweb_run "" "/.git/master:/file"'
535 test_debug
'cat gitweb.log'
537 test_expect_success \
538 'path_info: project/:/file (implicit HEAD)' \
539 'gitweb_run "" "/.git/:/file"'
540 test_debug
'cat gitweb.log'
542 test_expect_success \
543 'path_info: project/:/ (implicit HEAD, top tree)' \
544 'gitweb_run "" "/.git/:/"'
545 test_debug
'cat gitweb.log'
548 # ----------------------------------------------------------------------
551 test_expect_success \
553 'gitweb_run "a=opml"'
554 test_debug
'cat gitweb.log'
556 test_expect_success \
558 'gitweb_run "p=.git;a=rss"'
559 test_debug
'cat gitweb.log'
561 test_expect_success \
563 'gitweb_run "p=.git;a=atom"'
564 test_debug
'cat gitweb.log'
566 # ----------------------------------------------------------------------
569 test_expect_success \
570 'encode(commit): utf8' \
571 '. "$TEST_DIRECTORY"/t3901-utf8.txt &&
572 echo "UTF-8" >> file &&
574 git commit -F "$TEST_DIRECTORY"/t3900/1-UTF-8.txt &&
575 gitweb_run "p=.git;a=commit"'
576 test_debug
'cat gitweb.log'
578 test_expect_success \
579 'encode(commit): iso-8859-1' \
580 '. "$TEST_DIRECTORY"/t3901-8859-1.txt &&
581 echo "ISO-8859-1" >> file &&
583 git config i18n.commitencoding ISO-8859-1 &&
584 git commit -F "$TEST_DIRECTORY"/t3900/ISO-8859-1.txt &&
585 git config --unset i18n.commitencoding &&
586 gitweb_run "p=.git;a=commit"'
587 test_debug
'cat gitweb.log'
589 test_expect_success \
590 'encode(log): utf-8 and iso-8859-1' \
591 'gitweb_run "p=.git;a=log"'
592 test_debug
'cat gitweb.log'
594 # ----------------------------------------------------------------------
597 test_expect_success \
598 'opt: log --no-merges' \
599 'gitweb_run "p=.git;a=log;opt=--no-merges"'
600 test_debug
'cat gitweb.log'
602 test_expect_success \
603 'opt: atom --no-merges' \
604 'gitweb_run "p=.git;a=log;opt=--no-merges"'
605 test_debug
'cat gitweb.log'
607 test_expect_success \
608 'opt: "file" history --no-merges' \
609 'gitweb_run "p=.git;a=history;f=file;opt=--no-merges"'
610 test_debug
'cat gitweb.log'
612 test_expect_success \
613 'opt: log --no-such-option (invalid option)' \
614 'gitweb_run "p=.git;a=log;opt=--no-such-option"'
615 test_debug
'cat gitweb.log'
617 test_expect_success \
618 'opt: tree --no-merges (invalid option for action)' \
619 'gitweb_run "p=.git;a=tree;opt=--no-merges"'
620 test_debug
'cat gitweb.log'
622 # ----------------------------------------------------------------------
623 # testing config_to_multi / cloneurl
625 test_expect_success \
626 'URL: no project URLs, no base URL' \
627 'gitweb_run "p=.git;a=summary"'
628 test_debug
'cat gitweb.log'
630 test_expect_success \
631 'URL: project URLs via gitweb.url' \
632 'git config --add gitweb.url git://example.com/git/trash.git &&
633 git config --add gitweb.url http://example.com/git/trash.git &&
634 gitweb_run "p=.git;a=summary"'
635 test_debug
'cat gitweb.log'
637 cat >.git
/cloneurl
<<\EOF
638 git
://example.com
/git
/trash.git
639 http
://example.com
/git
/trash.git
642 test_expect_success \
643 'URL: project URLs via cloneurl file' \
644 'gitweb_run "p=.git;a=summary"'
645 test_debug
'cat gitweb.log'
647 # ----------------------------------------------------------------------
648 # gitweb config and repo config
650 cat >>gitweb_config.perl
<<EOF
652 \$feature{'blame'}{'override'} = 1;
653 \$feature{'snapshot'}{'override'} = 1;
656 test_expect_success \
657 'config override: tree view, features not overridden in repo config' \
658 'gitweb_run "p=.git;a=tree"'
659 test_debug
'cat gitweb.log'
661 test_expect_success \
662 'config override: tree view, features disabled in repo config' \
663 'git config gitweb.blame no &&
664 git config gitweb.snapshot none &&
665 gitweb_run "p=.git;a=tree"'
666 test_debug
'cat gitweb.log'
668 test_expect_success \
669 'config override: tree view, features enabled in repo config (1)' \
670 'git config gitweb.blame yes &&
671 git config gitweb.snapshot "zip,tgz, tbz2" &&
672 gitweb_run "p=.git;a=tree"'
673 test_debug
'cat gitweb.log'
675 cat >.git
/config
<<\EOF
676 # testing noval and alternate separator
681 test_expect_success \
682 'config override: tree view, features enabled in repo config (2)' \
683 'gitweb_run "p=.git;a=tree"'
684 test_debug
'cat gitweb.log'
686 # ----------------------------------------------------------------------
687 # non-ASCII in README.html
689 test_expect_success \
690 'README.html with non-ASCII characters (utf-8)' \
691 'echo "<b>UTF-8 example:</b><br />" > .git/README.html &&
692 cat "$TEST_DIRECTORY"/t3900/1-UTF-8.txt >> .git/README.html &&
693 gitweb_run "p=.git;a=summary"'
694 test_debug
'cat gitweb.log'