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
15 # ----------------------------------------------------------------------
16 # no commits (empty, just initialized repository)
19 'no commits: projects_list (implicit)' \
23 'no commits: projects_index' \
24 'gitweb_run "a=project_index"'
27 'no commits: .git summary (implicit)' \
31 'no commits: .git commit (implicit HEAD)' \
32 'gitweb_run "p=.git;a=commit"'
35 'no commits: .git commitdiff (implicit HEAD)' \
36 'gitweb_run "p=.git;a=commitdiff"'
39 'no commits: .git tree (implicit HEAD)' \
40 'gitweb_run "p=.git;a=tree"'
43 'no commits: .git heads' \
44 'gitweb_run "p=.git;a=heads"'
47 'no commits: .git tags' \
48 'gitweb_run "p=.git;a=tags"'
51 # ----------------------------------------------------------------------
55 'Make initial commit' \
56 'echo "Not an empty file." > file &&
58 git commit -a -m "Initial commit." &&
62 'projects_list (implicit)' \
67 'gitweb_run "a=project_index"'
70 '.git summary (implicit)' \
74 '.git commit (implicit HEAD)' \
75 'gitweb_run "p=.git;a=commit"'
78 '.git commitdiff (implicit HEAD, root commit)' \
79 'gitweb_run "p=.git;a=commitdiff"'
82 '.git commitdiff_plain (implicit HEAD, root commit)' \
83 'gitweb_run "p=.git;a=commitdiff_plain"'
86 '.git commit (HEAD)' \
87 'gitweb_run "p=.git;a=commit;h=HEAD"'
90 '.git tree (implicit HEAD)' \
91 'gitweb_run "p=.git;a=tree"'
95 'gitweb_run "p=.git;a=blob;f=file"'
98 '.git blob_plain (file)' \
99 'gitweb_run "p=.git;a=blob_plain;f=file"'
101 # ----------------------------------------------------------------------
102 # nonexistent objects
104 test_expect_success \
105 '.git commit (non-existent)' \
106 'gitweb_run "p=.git;a=commit;h=non-existent"'
108 test_expect_success \
109 '.git commitdiff (non-existent)' \
110 'gitweb_run "p=.git;a=commitdiff;h=non-existent"'
112 test_expect_success \
113 '.git commitdiff (non-existent vs HEAD)' \
114 'gitweb_run "p=.git;a=commitdiff;hp=non-existent;h=HEAD"'
116 test_expect_success \
117 '.git tree (0000000000000000000000000000000000000000)' \
118 'gitweb_run "p=.git;a=tree;h=0000000000000000000000000000000000000000"'
120 test_expect_success \
121 '.git tag (0000000000000000000000000000000000000000)' \
122 'gitweb_run "p=.git;a=tag;h=0000000000000000000000000000000000000000"'
124 test_expect_success \
125 '.git blob (non-existent)' \
126 'gitweb_run "p=.git;a=blob;f=non-existent"'
128 test_expect_success \
129 '.git blob_plain (non-existent)' \
130 'gitweb_run "p=.git;a=blob_plain;f=non-existent"'
133 # ----------------------------------------------------------------------
134 # commitdiff testing (implicit, one implicit tree-ish)
136 test_expect_success \
137 'commitdiff(0): root' \
138 'gitweb_run "p=.git;a=commitdiff"'
140 test_expect_success \
141 'commitdiff(0): file added' \
142 'echo "New file" > new_file &&
144 git commit -a -m "File added." &&
145 gitweb_run "p=.git;a=commitdiff"'
147 test_expect_success \
148 'commitdiff(0): mode change' \
149 'test_chmod +x new_file &&
150 git commit -a -m "Mode changed." &&
151 gitweb_run "p=.git;a=commitdiff"'
153 test_expect_success \
154 'commitdiff(0): file renamed' \
155 'git mv new_file renamed_file &&
156 git commit -a -m "File renamed." &&
157 gitweb_run "p=.git;a=commitdiff"'
159 test_expect_success SYMLINKS \
160 'commitdiff(0): file to symlink' \
162 ln -s file renamed_file &&
163 git commit -a -m "File to symlink." &&
164 gitweb_run "p=.git;a=commitdiff"'
166 test_expect_success \
167 'commitdiff(0): file deleted' \
168 'git rm renamed_file &&
169 rm -f renamed_file &&
170 git commit -a -m "File removed." &&
171 gitweb_run "p=.git;a=commitdiff"'
173 test_expect_success \
174 'commitdiff(0): file copied / new file' \
177 git commit -a -m "File copied." &&
178 gitweb_run "p=.git;a=commitdiff"'
180 test_expect_success \
181 'commitdiff(0): mode change and modified' \
182 'echo "New line" >> file2 &&
183 test_chmod +x file2 &&
184 git commit -a -m "Mode change and modification." &&
185 gitweb_run "p=.git;a=commitdiff"'
187 test_expect_success \
188 'commitdiff(0): renamed and modified' \
191 et nihil mihi deerit.
192 In loco pascuae ibi me collocavit,
193 super aquam refectionis educavit me;
194 animam meam convertit,
195 deduxit me super semitas jusitiae,
198 git commit -a -m "File added." &&
199 git mv file2 file3 &&
200 echo "Propter nomen suum." >> file3 &&
201 git commit -a -m "File rename and modification." &&
202 gitweb_run "p=.git;a=commitdiff"'
204 test_expect_success \
205 'commitdiff(0): renamed, mode change and modified' \
206 'git mv file3 file2 &&
207 echo "Propter nomen suum." >> file2 &&
208 test_chmod +x file2 &&
209 git commit -a -m "File rename, mode change and modification." &&
210 gitweb_run "p=.git;a=commitdiff"'
212 # ----------------------------------------------------------------------
213 # commitdiff testing (taken from t4114-apply-typechange.sh)
215 test_expect_success SYMLINKS 'setup typechange commits' '
216 echo "hello world" > foo &&
217 echo "hi planet" > bar &&
218 git update-index --add foo bar &&
219 git commit -m initial &&
220 git branch initial &&
223 git update-index foo &&
224 git commit -m "foo symlinked to bar" &&
225 git branch foo-symlinked-to-bar &&
227 echo "how far is the sun?" > foo &&
228 git update-index foo &&
229 git commit -m "foo back to file" &&
230 git branch foo-back-to-file &&
232 git update-index --remove foo &&
234 echo "if only I knew" > foo/baz &&
235 git update-index --add foo/baz &&
236 git commit -m "foo becomes a directory" &&
237 git branch "foo-becomes-a-directory" &&
238 echo "hello world" > foo/baz &&
239 git update-index foo/baz &&
240 git commit -m "foo/baz is the original foo" &&
241 git branch foo-baz-renamed-from-foo
244 test_expect_success \
245 'commitdiff(2): file renamed from foo to foo/baz' \
246 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-baz-renamed-from-foo"'
248 test_expect_success \
249 'commitdiff(2): file renamed from foo/baz to foo' \
250 'gitweb_run "p=.git;a=commitdiff;hp=foo-baz-renamed-from-foo;h=initial"'
252 test_expect_success \
253 'commitdiff(2): directory becomes file' \
254 'gitweb_run "p=.git;a=commitdiff;hp=foo-becomes-a-directory;h=initial"'
256 test_expect_success \
257 'commitdiff(2): file becomes directory' \
258 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-becomes-a-directory"'
260 test_expect_success \
261 'commitdiff(2): file becomes symlink' \
262 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-symlinked-to-bar"'
264 test_expect_success \
265 'commitdiff(2): symlink becomes file' \
266 'gitweb_run "p=.git;a=commitdiff;hp=foo-symlinked-to-bar;h=foo-back-to-file"'
268 test_expect_success \
269 'commitdiff(2): symlink becomes directory' \
270 'gitweb_run "p=.git;a=commitdiff;hp=foo-symlinked-to-bar;h=foo-becomes-a-directory"'
272 test_expect_success \
273 'commitdiff(2): directory becomes symlink' \
274 'gitweb_run "p=.git;a=commitdiff;hp=foo-becomes-a-directory;h=foo-symlinked-to-bar"'
276 # ----------------------------------------------------------------------
277 # commitdiff testing (incomplete lines)
279 test_expect_success 'setup incomplete lines' '
282 et nihil mihi deerit.
283 In loco pascuae ibi me collocavit,
284 super aquam refectionis educavit me;
285 animam meam convertit,
286 deduxit me super semitas jusitiae,
290 git commit -a -m "Preparing for incomplete lines" &&
291 echo "incomplete" | tr -d "\\012" >>file &&
292 git commit -a -m "Add incomplete line" &&
293 git tag incomplete_lines_add &&
294 sed -e s/CHANGE_ME/change_me/ <file >file+ &&
296 git commit -a -m "Incomplete context line" &&
297 git tag incomplete_lines_ctx &&
298 echo "Dominus regit me," >file &&
299 echo "incomplete line" | tr -d "\\012" >>file &&
300 git commit -a -m "Change incomplete line" &&
301 git tag incomplete_lines_chg
302 echo "Dominus regit me," >file &&
303 git commit -a -m "Remove incomplete line" &&
304 git tag incomplete_lines_rem
307 test_expect_success 'commitdiff(1): addition of incomplete line' '
308 gitweb_run "p=.git;a=commitdiff;h=incomplete_lines_add"
311 test_expect_success 'commitdiff(1): incomplete line as context line' '
312 gitweb_run "p=.git;a=commitdiff;h=incomplete_lines_ctx"
315 test_expect_success 'commitdiff(1): change incomplete line' '
316 gitweb_run "p=.git;a=commitdiff;h=incomplete_lines_chg"
319 test_expect_success 'commitdiff(1): removal of incomplete line' '
320 gitweb_run "p=.git;a=commitdiff;h=incomplete_lines_rem"
323 # ----------------------------------------------------------------------
324 # commit, commitdiff: merge, large
325 test_expect_success \
328 echo "Branch" >> b &&
330 git commit -a -m "On branch" &&
331 git checkout master &&
334 test_expect_success \
335 'commit(0): merge commit' \
336 'gitweb_run "p=.git;a=commit"'
338 test_expect_success \
339 'commitdiff(0): merge commit' \
340 'gitweb_run "p=.git;a=commitdiff"'
342 test_expect_success \
343 'Prepare large commit' \
345 echo "To be changed" > 01-change &&
346 echo "To be renamed" > 02-pure-rename-from &&
347 echo "To be deleted" > 03-delete &&
348 echo "To be renamed and changed" > 04-rename-from &&
349 echo "To have mode changed" > 05-mode-change &&
350 echo "File to symlink" > 06-file-or-symlink &&
351 echo "To be changed and have mode changed" > 07-change-mode-change &&
353 git commit -a -m "Prepare large commit" &&
354 echo "Changed" > 01-change &&
355 git mv 02-pure-rename-from 02-pure-rename-to &&
356 git rm 03-delete && rm -f 03-delete &&
357 echo "A new file" > 03-new &&
359 git mv 04-rename-from 04-rename-to &&
360 echo "Changed" >> 04-rename-to &&
361 test_chmod +x 05-mode-change &&
362 rm -f 06-file-or-symlink &&
363 if test_have_prereq SYMLINKS; then
364 ln -s 01-change 06-file-or-symlink
366 printf %s 01-change > 06-file-or-symlink
368 echo "Changed and have mode changed" > 07-change-mode-change &&
369 test_chmod +x 07-change-mode-change &&
370 git commit -a -m "Large commit" &&
373 test_expect_success \
374 'commit(1): large commit' \
375 'gitweb_run "p=.git;a=commit;h=b"'
377 test_expect_success \
378 'commitdiff(1): large commit' \
379 'gitweb_run "p=.git;a=commitdiff;h=b"'
381 # ----------------------------------------------------------------------
384 test_expect_success \
385 'tags: list of different types of tags' \
386 'git checkout master &&
387 git tag -a -m "Tag commit object" tag-commit HEAD &&
388 git tag -a -m "" tag-commit-nomessage HEAD &&
389 git tag -a -m "Tag tag object" tag-tag tag-commit &&
390 git tag -a -m "Tag tree object" tag-tree HEAD^{tree} &&
391 git tag -a -m "Tag blob object" tag-blob HEAD:file &&
392 git tag lightweight/tag-commit HEAD &&
393 git tag lightweight/tag-tag tag-commit &&
394 git tag lightweight/tag-tree HEAD^{tree} &&
395 git tag lightweight/tag-blob HEAD:file &&
396 gitweb_run "p=.git;a=tags"'
398 test_expect_success \
399 'tag: Tag to commit object' \
400 'gitweb_run "p=.git;a=tag;h=tag-commit"'
402 test_expect_success \
403 'tag: on lightweight tag (invalid)' \
404 'gitweb_run "p=.git;a=tag;h=lightweight/tag-commit"'
406 # ----------------------------------------------------------------------
409 test_expect_success \
410 'logs: log (implicit HEAD)' \
411 'gitweb_run "p=.git;a=log"'
413 test_expect_success \
414 'logs: shortlog (implicit HEAD)' \
415 'gitweb_run "p=.git;a=shortlog"'
417 test_expect_success \
418 'logs: history (implicit HEAD, file)' \
419 'gitweb_run "p=.git;a=history;f=file"'
421 test_expect_success \
422 'logs: history (implicit HEAD, non-existent file)' \
423 'gitweb_run "p=.git;a=history;f=non-existent"'
425 test_expect_success \
426 'logs: history (implicit HEAD, deleted file)' \
427 'git checkout master &&
428 echo "to be deleted" > deleted_file &&
429 git add deleted_file &&
430 git commit -m "Add file to be deleted" &&
431 git rm deleted_file &&
432 git commit -m "Delete file" &&
433 gitweb_run "p=.git;a=history;f=deleted_file"'
435 # ----------------------------------------------------------------------
437 test_expect_success \
438 'path_info: project' \
439 'gitweb_run "" "/.git"'
441 test_expect_success \
442 'path_info: project/branch' \
443 'gitweb_run "" "/.git/b"'
445 test_expect_success \
446 'path_info: project/branch:file' \
447 'gitweb_run "" "/.git/master:file"'
449 test_expect_success \
450 'path_info: project/branch:dir/' \
451 'gitweb_run "" "/.git/master:foo/"'
453 test_expect_success \
454 'path_info: project/branch:file (non-existent)' \
455 'gitweb_run "" "/.git/master:non-existent"'
457 test_expect_success \
458 'path_info: project/branch:dir/ (non-existent)' \
459 'gitweb_run "" "/.git/master:non-existent/"'
462 test_expect_success \
463 'path_info: project/branch:/file' \
464 'gitweb_run "" "/.git/master:/file"'
466 test_expect_success \
467 'path_info: project/:/file (implicit HEAD)' \
468 'gitweb_run "" "/.git/:/file"'
470 test_expect_success \
471 'path_info: project/:/ (implicit HEAD, top tree)' \
472 'gitweb_run "" "/.git/:/"'
475 # ----------------------------------------------------------------------
478 test_expect_success \
480 'gitweb_run "a=opml"'
482 test_expect_success \
484 'gitweb_run "p=.git;a=rss"'
486 test_expect_success \
488 'gitweb_run "p=.git;a=atom"'
490 # ----------------------------------------------------------------------
493 test_expect_success \
494 'encode(commit): utf8' \
495 '. "$TEST_DIRECTORY"/t3901-utf8.txt &&
496 test_when_finished "GIT_AUTHOR_NAME=\"A U Thor\"" &&
497 test_when_finished "GIT_COMMITTER_NAME=\"C O Mitter\"" &&
498 echo "UTF-8" >> file &&
500 git commit -F "$TEST_DIRECTORY"/t3900/1-UTF-8.txt &&
501 gitweb_run "p=.git;a=commit"'
503 test_expect_success \
504 'encode(commit): iso-8859-1' \
505 '. "$TEST_DIRECTORY"/t3901-8859-1.txt &&
506 test_when_finished "GIT_AUTHOR_NAME=\"A U Thor\"" &&
507 test_when_finished "GIT_COMMITTER_NAME=\"C O Mitter\"" &&
508 echo "ISO-8859-1" >> file &&
510 git config i18n.commitencoding ISO-8859-1 &&
511 test_when_finished "git config --unset i18n.commitencoding" &&
512 git commit -F "$TEST_DIRECTORY"/t3900/ISO8859-1.txt &&
513 gitweb_run "p=.git;a=commit"'
515 test_expect_success \
516 'encode(log): utf-8 and iso-8859-1' \
517 'gitweb_run "p=.git;a=log"'
519 # ----------------------------------------------------------------------
522 test_expect_success \
523 'opt: log --no-merges' \
524 'gitweb_run "p=.git;a=log;opt=--no-merges"'
526 test_expect_success \
527 'opt: atom --no-merges' \
528 'gitweb_run "p=.git;a=log;opt=--no-merges"'
530 test_expect_success \
531 'opt: "file" history --no-merges' \
532 'gitweb_run "p=.git;a=history;f=file;opt=--no-merges"'
534 test_expect_success \
535 'opt: log --no-such-option (invalid option)' \
536 'gitweb_run "p=.git;a=log;opt=--no-such-option"'
538 test_expect_success \
539 'opt: tree --no-merges (invalid option for action)' \
540 'gitweb_run "p=.git;a=tree;opt=--no-merges"'
542 # ----------------------------------------------------------------------
543 # testing config_to_multi / cloneurl
545 test_expect_success \
546 'URL: no project URLs, no base URL' \
547 'gitweb_run "p=.git;a=summary"'
549 test_expect_success \
550 'URL: project URLs via gitweb.url' \
551 'git config --add gitweb.url git://example.com/git/trash.git &&
552 git config --add gitweb.url http://example.com/git/trash.git &&
553 gitweb_run "p=.git;a=summary"'
555 cat >.git/cloneurl <<\EOF
556 git://example.com/git/trash.git
557 http://example.com/git/trash.git
560 test_expect_success \
561 'URL: project URLs via cloneurl file' \
562 'gitweb_run "p=.git;a=summary"'
564 # ----------------------------------------------------------------------
565 # gitweb config and repo config
567 cat >>gitweb_config.perl <<\EOF
569 # turn on override for each overridable feature
570 foreach my $key (keys %feature) {
571 if ($feature{$key}{'sub'}) {
572 $feature{$key}{'override'} = 1;
577 test_expect_success \
578 'config override: projects list (implicit)' \
581 test_expect_success \
582 'config override: tree view, features not overridden in repo config' \
583 'gitweb_run "p=.git;a=tree"'
585 test_expect_success \
586 'config override: tree view, features disabled in repo config' \
587 'git config gitweb.blame no &&
588 git config gitweb.snapshot none &&
589 git config gitweb.avatar gravatar &&
590 gitweb_run "p=.git;a=tree"'
592 test_expect_success \
593 'config override: tree view, features enabled in repo config (1)' \
594 'git config gitweb.blame yes &&
595 git config gitweb.snapshot "zip,tgz, tbz2" &&
596 gitweb_run "p=.git;a=tree"'
598 cat >.git/config <<\EOF
599 # testing noval and alternate separator
604 test_expect_success \
605 'config override: tree view, features enabled in repo config (2)' \
606 'gitweb_run "p=.git;a=tree"'
608 # ----------------------------------------------------------------------
609 # non-ASCII in README.html
611 test_expect_success \
612 'README.html with non-ASCII characters (utf-8)' \
613 'echo "<b>UTF-8 example:</b><br />" > .git/README.html &&
614 cat "$TEST_DIRECTORY"/t3900/1-UTF-8.txt >> .git/README.html &&
615 gitweb_run "p=.git;a=summary"'
617 # ----------------------------------------------------------------------
618 # syntax highlighting
621 highlight --version >/dev/null 2>&1
622 if [ $? -eq 127 ]; then
623 say "Skipping syntax highlighting test, because 'highlight' was not found"
625 test_set_prereq HIGHLIGHT
626 cat >>gitweb_config.perl <<-\EOF
627 our $highlight_bin = "highlight";
628 $feature{'highlight'}{'override'} = 1;
632 test_expect_success HIGHLIGHT \
633 'syntax highlighting (no highlight, unknown syntax)' \
634 'git config gitweb.highlight yes &&
635 gitweb_run "p=.git;a=blob;f=file"'
637 test_expect_success HIGHLIGHT \
638 'syntax highlighting (highlighted, shell script)' \
639 'git config gitweb.highlight yes &&
640 echo "#!/usr/bin/sh" > test.sh &&
642 git commit -m "Add test.sh" &&
643 gitweb_run "p=.git;a=blob;f=test.sh"'
645 # ----------------------------------------------------------------------
648 cat >>gitweb_config.perl <<\EOF &&
649 $feature{'forks'}{'default'} = [1];
652 test_expect_success \
654 'git init --bare foo.git &&
655 git --git-dir=foo.git --work-tree=. add file &&
656 git --git-dir=foo.git --work-tree=. commit -m "Initial commit" &&
657 echo "foo" > foo.git/description &&
660 git clone --shared --bare ../foo.git foo-forked.git &&
661 echo "fork of foo" > foo-forked.git/description)'
663 test_expect_success \
664 'forks: projects list' \
667 test_expect_success \
668 'forks: forks action' \
669 'gitweb_run "p=foo.git;a=forks"'
671 # ----------------------------------------------------------------------
672 # content tags (tag cloud)
674 cat >>gitweb_config.perl <<-\EOF &&
675 # we don't test _setting_ content tags, so any true value is good
676 $feature{'ctags'}{'default'} = ['ctags_script.cgi'];
679 test_expect_success \
680 'ctags: tag cloud in projects list' \
682 echo "2" > .git/ctags/foo &&
683 echo "1" > .git/ctags/bar &&
686 test_expect_success \
687 'ctags: search projects by existing tag' \
688 'gitweb_run "by_tag=foo"'
690 test_expect_success \
691 'ctags: search projects by non existent tag' \
692 'gitweb_run "by_tag=non-existent"'
694 test_expect_success \
695 'ctags: malformed tag weights' \
696 'mkdir -p .git/ctags &&
697 echo "not-a-number" > .git/ctags/nan &&
698 echo "not-a-number-2" > .git/ctags/nan2 &&
699 echo "0.1" >.git/ctags/floating-point &&
702 # ----------------------------------------------------------------------
705 test_expect_success \
706 'categories: projects list, only default category' \
707 'echo "\$projects_list_group_categories = 1;" >>gitweb_config.perl &&