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"
48 export GATEWAY_INTERFACE HTTP_ACCEPT REQUEST_METHOD QUERY_STRING PATH_INFO
50 GITWEB_CONFIG=$(pwd)/gitweb_config.perl
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
57 perl -- "$TEST_DIRECTORY/../gitweb/gitweb.perl" \
58 >/dev/null 2>gitweb.log &&
59 if grep "^[[]" gitweb.log >/dev/null 2>&1; then false; else true; fi
61 # gitweb.log is left for debugging
66 if [ "$(git config --get core.filemode)" = false ]
68 git update-index --chmod="$1" "$2"
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' :
82 # ----------------------------------------------------------------------
83 # no commits (empty, just initialized repository)
86 'no commits: projects_list (implicit)' \
88 test_debug 'cat gitweb.log'
91 'no commits: projects_index' \
92 'gitweb_run "a=project_index"'
93 test_debug 'cat gitweb.log'
96 'no commits: .git summary (implicit)' \
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 # ----------------------------------------------------------------------
129 test_expect_success \
130 'Make initial commit' \
131 'echo "Not an empty file." > file &&
133 git commit -a -m "Initial commit." &&
136 test_expect_success \
137 'projects_list (implicit)' \
139 test_debug 'cat gitweb.log'
141 test_expect_success \
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 \
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 &&
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' \
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' \
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' \
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,
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 &&
325 git update-index foo &&
326 git commit -m "foo symlinked to bar" &&
327 git branch foo-symlinked-to-bar &&
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 &&
334 git update-index --remove 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
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 \
391 echo "Branch" >> b &&
393 git commit -a -m "On branch" &&
394 git checkout master &&
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' \
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 &&
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 &&
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" &&
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 # ----------------------------------------------------------------------
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 # ----------------------------------------------------------------------
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 # ----------------------------------------------------------------------
507 test_expect_success \
508 'path_info: project' \
509 'gitweb_run "" "/.git"'
510 test_debug 'cat gitweb.log'
512 test_expect_success \
513 'path_info: project/branch' \
514 'gitweb_run "" "/.git/b"'
515 test_debug 'cat gitweb.log'
517 test_expect_success \
518 'path_info: project/branch:file' \
519 'gitweb_run "" "/.git/master:file"'
520 test_debug 'cat gitweb.log'
522 test_expect_success \
523 'path_info: project/branch:dir/' \
524 'gitweb_run "" "/.git/master:foo/"'
525 test_debug 'cat gitweb.log'
527 test_expect_success \
528 'path_info: project/branch:file (non-existent)' \
529 'gitweb_run "" "/.git/master:non-existent"'
530 test_debug 'cat gitweb.log'
532 test_expect_success \
533 'path_info: project/branch:dir/ (non-existent)' \
534 'gitweb_run "" "/.git/master:non-existent/"'
535 test_debug 'cat gitweb.log'
538 test_expect_success \
539 'path_info: project/branch:/file' \
540 'gitweb_run "" "/.git/master:/file"'
541 test_debug 'cat gitweb.log'
543 test_expect_success \
544 'path_info: project/:/file (implicit HEAD)' \
545 'gitweb_run "" "/.git/:/file"'
546 test_debug 'cat gitweb.log'
548 test_expect_success \
549 'path_info: project/:/ (implicit HEAD, top tree)' \
550 'gitweb_run "" "/.git/:/"'
551 test_debug 'cat gitweb.log'
554 # ----------------------------------------------------------------------
557 test_expect_success \
559 'gitweb_run "a=opml"'
560 test_debug 'cat gitweb.log'
562 test_expect_success \
564 'gitweb_run "p=.git;a=rss"'
565 test_debug 'cat gitweb.log'
567 test_expect_success \
569 'gitweb_run "p=.git;a=atom"'
570 test_debug 'cat gitweb.log'
572 # ----------------------------------------------------------------------
575 test_expect_success \
576 'encode(commit): utf8' \
577 '. "$TEST_DIRECTORY"/t3901-utf8.txt &&
578 echo "UTF-8" >> file &&
580 git commit -F "$TEST_DIRECTORY"/t3900/1-UTF-8.txt &&
581 gitweb_run "p=.git;a=commit"'
582 test_debug 'cat gitweb.log'
584 test_expect_success \
585 'encode(commit): iso-8859-1' \
586 '. "$TEST_DIRECTORY"/t3901-8859-1.txt &&
587 echo "ISO-8859-1" >> file &&
589 git config i18n.commitencoding ISO-8859-1 &&
590 git commit -F "$TEST_DIRECTORY"/t3900/ISO-8859-1.txt &&
591 git config --unset i18n.commitencoding &&
592 gitweb_run "p=.git;a=commit"'
593 test_debug 'cat gitweb.log'
595 test_expect_success \
596 'encode(log): utf-8 and iso-8859-1' \
597 'gitweb_run "p=.git;a=log"'
598 test_debug 'cat gitweb.log'
600 # ----------------------------------------------------------------------
603 test_expect_success \
604 'opt: log --no-merges' \
605 'gitweb_run "p=.git;a=log;opt=--no-merges"'
606 test_debug 'cat gitweb.log'
608 test_expect_success \
609 'opt: atom --no-merges' \
610 'gitweb_run "p=.git;a=log;opt=--no-merges"'
611 test_debug 'cat gitweb.log'
613 test_expect_success \
614 'opt: "file" history --no-merges' \
615 'gitweb_run "p=.git;a=history;f=file;opt=--no-merges"'
616 test_debug 'cat gitweb.log'
618 test_expect_success \
619 'opt: log --no-such-option (invalid option)' \
620 'gitweb_run "p=.git;a=log;opt=--no-such-option"'
621 test_debug 'cat gitweb.log'
623 test_expect_success \
624 'opt: tree --no-merges (invalid option for action)' \
625 'gitweb_run "p=.git;a=tree;opt=--no-merges"'
626 test_debug 'cat gitweb.log'
628 # ----------------------------------------------------------------------
629 # testing config_to_multi / cloneurl
631 test_expect_success \
632 'URL: no project URLs, no base URL' \
633 'gitweb_run "p=.git;a=summary"'
634 test_debug 'cat gitweb.log'
636 test_expect_success \
637 'URL: project URLs via gitweb.url' \
638 'git config --add gitweb.url git://example.com/git/trash.git &&
639 git config --add gitweb.url http://example.com/git/trash.git &&
640 gitweb_run "p=.git;a=summary"'
641 test_debug 'cat gitweb.log'
643 cat >.git/cloneurl <<\EOF
644 git://example.com/git/trash.git
645 http://example.com/git/trash.git
648 test_expect_success \
649 'URL: project URLs via cloneurl file' \
650 'gitweb_run "p=.git;a=summary"'
651 test_debug 'cat gitweb.log'
653 # ----------------------------------------------------------------------
654 # gitweb config and repo config
656 cat >>gitweb_config.perl <<EOF
658 \$feature{'blame'}{'override'} = 1;
659 \$feature{'snapshot'}{'override'} = 1;
662 test_expect_success \
663 'config override: tree view, features disabled in repo config' \
664 'git config gitweb.blame no &&
665 git config gitweb.snapshot none &&
666 gitweb_run "p=.git;a=tree"'
667 test_debug 'cat gitweb.log'
669 test_expect_success \
670 'config override: tree view, features enabled in repo config' \
671 'git config gitweb.blame yes &&
672 git config gitweb.snapshot "zip,tgz, tbz2" &&
673 gitweb_run "p=.git;a=tree"'
674 test_debug 'cat gitweb.log'