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:///$safe_pwd/../../gitweb/gitweb.css");
29 our \$logo = "file:///$safe_pwd/../../gitweb/git-logo.png";
30 our \$favicon = "file:///$safe_pwd/../../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
-- "$(pwd)/../../gitweb/gitweb.perl" \
58 >/dev
/null
2>gitweb.log
&&
59 if grep -q -s "^[[]" gitweb.log
>/dev
/null
; 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 say
'gitweb not supported, skipping tests.'
77 perl
-MEncode -e 'decode_utf8("", Encode::FB_CROAK)' >/dev
/null
2>&1 ||
{
78 test_expect_success
'skipping gitweb tests, perl version is too old' :
85 # ----------------------------------------------------------------------
86 # no commits (empty, just initialized repository)
89 'no commits: projects_list (implicit)' \
91 test_debug
'cat gitweb.log'
94 'no commits: projects_index' \
95 'gitweb_run "a=project_index"'
96 test_debug
'cat gitweb.log'
99 'no commits: .git summary (implicit)' \
100 'gitweb_run "p=.git"'
101 test_debug
'cat gitweb.log'
103 test_expect_success \
104 'no commits: .git commit (implicit HEAD)' \
105 'gitweb_run "p=.git;a=commit"'
106 test_debug
'cat gitweb.log'
108 test_expect_success \
109 'no commits: .git commitdiff (implicit HEAD)' \
110 'gitweb_run "p=.git;a=commitdiff"'
111 test_debug
'cat gitweb.log'
113 test_expect_success \
114 'no commits: .git tree (implicit HEAD)' \
115 'gitweb_run "p=.git;a=tree"'
116 test_debug
'cat gitweb.log'
118 test_expect_success \
119 'no commits: .git heads' \
120 'gitweb_run "p=.git;a=heads"'
121 test_debug
'cat gitweb.log'
123 test_expect_success \
124 'no commits: .git tags' \
125 'gitweb_run "p=.git;a=tags"'
126 test_debug
'cat gitweb.log'
129 # ----------------------------------------------------------------------
132 test_expect_success \
133 'Make initial commit' \
134 'echo "Not an empty file." > file &&
136 git commit -a -m "Initial commit." &&
139 test_expect_success \
140 'projects_list (implicit)' \
142 test_debug
'cat gitweb.log'
144 test_expect_success \
146 'gitweb_run "a=project_index"'
147 test_debug
'cat gitweb.log'
149 test_expect_success \
150 '.git summary (implicit)' \
151 'gitweb_run "p=.git"'
152 test_debug
'cat gitweb.log'
154 test_expect_success \
155 '.git commit (implicit HEAD)' \
156 'gitweb_run "p=.git;a=commit"'
157 test_debug
'cat gitweb.log'
159 test_expect_success \
160 '.git commitdiff (implicit HEAD, root commit)' \
161 'gitweb_run "p=.git;a=commitdiff"'
162 test_debug
'cat gitweb.log'
164 test_expect_success \
165 '.git commitdiff_plain (implicit HEAD, root commit)' \
166 'gitweb_run "p=.git;a=commitdiff_plain"'
167 test_debug
'cat gitweb.log'
169 test_expect_success \
170 '.git commit (HEAD)' \
171 'gitweb_run "p=.git;a=commit;h=HEAD"'
172 test_debug
'cat gitweb.log'
174 test_expect_success \
175 '.git tree (implicit HEAD)' \
176 'gitweb_run "p=.git;a=tree"'
177 test_debug
'cat gitweb.log'
179 test_expect_success \
181 'gitweb_run "p=.git;a=blob;f=file"'
182 test_debug
'cat gitweb.log'
184 test_expect_success \
185 '.git blob_plain (file)' \
186 'gitweb_run "p=.git;a=blob_plain;f=file"'
187 test_debug
'cat gitweb.log'
189 # ----------------------------------------------------------------------
190 # nonexistent objects
192 test_expect_success \
193 '.git commit (non-existent)' \
194 'gitweb_run "p=.git;a=commit;h=non-existent"'
195 test_debug
'cat gitweb.log'
197 test_expect_success \
198 '.git commitdiff (non-existent)' \
199 'gitweb_run "p=.git;a=commitdiff;h=non-existent"'
200 test_debug
'cat gitweb.log'
202 test_expect_success \
203 '.git commitdiff (non-existent vs HEAD)' \
204 'gitweb_run "p=.git;a=commitdiff;hp=non-existent;h=HEAD"'
205 test_debug
'cat gitweb.log'
207 test_expect_success \
208 '.git tree (0000000000000000000000000000000000000000)' \
209 'gitweb_run "p=.git;a=tree;h=0000000000000000000000000000000000000000"'
210 test_debug
'cat gitweb.log'
212 test_expect_success \
213 '.git tag (0000000000000000000000000000000000000000)' \
214 'gitweb_run "p=.git;a=tag;h=0000000000000000000000000000000000000000"'
215 test_debug
'cat gitweb.log'
217 test_expect_success \
218 '.git blob (non-existent)' \
219 'gitweb_run "p=.git;a=blob;f=non-existent"'
220 test_debug
'cat gitweb.log'
222 test_expect_success \
223 '.git blob_plain (non-existent)' \
224 'gitweb_run "p=.git;a=blob_plain;f=non-existent"'
225 test_debug
'cat gitweb.log'
228 # ----------------------------------------------------------------------
229 # commitdiff testing (implicit, one implicit tree-ish)
231 test_expect_success \
232 'commitdiff(0): root' \
233 'gitweb_run "p=.git;a=commitdiff"'
234 test_debug
'cat gitweb.log'
236 test_expect_success \
237 'commitdiff(0): file added' \
238 'echo "New file" > new_file &&
240 git commit -a -m "File added." &&
241 gitweb_run "p=.git;a=commitdiff"'
242 test_debug
'cat gitweb.log'
244 test_expect_success \
245 'commitdiff(0): mode change' \
246 'safe_chmod +x new_file &&
247 git commit -a -m "Mode changed." &&
248 gitweb_run "p=.git;a=commitdiff"'
249 test_debug
'cat gitweb.log'
251 test_expect_success \
252 'commitdiff(0): file renamed' \
253 'git mv new_file renamed_file &&
254 git commit -a -m "File renamed." &&
255 gitweb_run "p=.git;a=commitdiff"'
256 test_debug
'cat gitweb.log'
258 test_expect_success \
259 'commitdiff(0): file to symlink' \
261 ln -s file renamed_file &&
262 git commit -a -m "File to symlink." &&
263 gitweb_run "p=.git;a=commitdiff"'
264 test_debug
'cat gitweb.log'
266 test_expect_success \
267 'commitdiff(0): file deleted' \
268 'git rm renamed_file &&
269 rm -f renamed_file &&
270 git commit -a -m "File removed." &&
271 gitweb_run "p=.git;a=commitdiff"'
272 test_debug
'cat gitweb.log'
274 test_expect_success \
275 'commitdiff(0): file copied / new file' \
278 git commit -a -m "File copied." &&
279 gitweb_run "p=.git;a=commitdiff"'
280 test_debug
'cat gitweb.log'
282 test_expect_success \
283 'commitdiff(0): mode change and modified' \
284 'echo "New line" >> file2 &&
285 safe_chmod +x file2 &&
286 git commit -a -m "Mode change and modification." &&
287 gitweb_run "p=.git;a=commitdiff"'
288 test_debug
'cat gitweb.log'
290 test_expect_success \
291 'commitdiff(0): renamed and modified' \
294 et nihil mihi deerit.
295 In loco pascuae ibi me collocavit,
296 super aquam refectionis educavit me;
297 animam meam convertit,
298 deduxit me super semitas jusitiae,
301 git commit -a -m "File added." &&
302 git mv file2 file3 &&
303 echo "Propter nomen suum." >> file3 &&
304 git commit -a -m "File rename and modification." &&
305 gitweb_run "p=.git;a=commitdiff"'
306 test_debug
'cat gitweb.log'
308 test_expect_success \
309 'commitdiff(0): renamed, mode change and modified' \
310 'git mv file3 file2 &&
311 echo "Propter nomen suum." >> file2 &&
312 safe_chmod +x file2 &&
313 git commit -a -m "File rename, mode change and modification." &&
314 gitweb_run "p=.git;a=commitdiff"'
315 test_debug
'cat gitweb.log'
317 # ----------------------------------------------------------------------
318 # commitdiff testing (taken from t4114-apply-typechange.sh)
320 test_expect_success
'setup typechange commits' '
321 echo "hello world" > foo &&
322 echo "hi planet" > bar &&
323 git update-index --add foo bar &&
324 git commit -m initial &&
325 git branch initial &&
328 git update-index foo &&
329 git commit -m "foo symlinked to bar" &&
330 git branch foo-symlinked-to-bar &&
332 echo "how far is the sun?" > foo &&
333 git update-index foo &&
334 git commit -m "foo back to file" &&
335 git branch foo-back-to-file &&
337 git update-index --remove foo &&
339 echo "if only I knew" > foo/baz &&
340 git update-index --add foo/baz &&
341 git commit -m "foo becomes a directory" &&
342 git branch "foo-becomes-a-directory" &&
343 echo "hello world" > foo/baz &&
344 git update-index foo/baz &&
345 git commit -m "foo/baz is the original foo" &&
346 git branch foo-baz-renamed-from-foo
349 test_expect_success \
350 'commitdiff(2): file renamed from foo to foo/baz' \
351 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-baz-renamed-from-foo"'
352 test_debug
'cat gitweb.log'
354 test_expect_success \
355 'commitdiff(2): file renamed from foo/baz to foo' \
356 'gitweb_run "p=.git;a=commitdiff;hp=foo-baz-renamed-from-foo;h=initial"'
357 test_debug
'cat gitweb.log'
359 test_expect_success \
360 'commitdiff(2): directory becomes file' \
361 'gitweb_run "p=.git;a=commitdiff;hp=foo-becomes-a-directory;h=initial"'
362 test_debug
'cat gitweb.log'
364 test_expect_success \
365 'commitdiff(2): file becomes directory' \
366 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-becomes-a-directory"'
367 test_debug
'cat gitweb.log'
369 test_expect_success \
370 'commitdiff(2): file becomes symlink' \
371 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-symlinked-to-bar"'
372 test_debug
'cat gitweb.log'
374 test_expect_success \
375 'commitdiff(2): symlink becomes file' \
376 'gitweb_run "p=.git;a=commitdiff;hp=foo-symlinked-to-bar;h=foo-back-to-file"'
377 test_debug
'cat gitweb.log'
379 test_expect_success \
380 'commitdiff(2): symlink becomes directory' \
381 'gitweb_run "p=.git;a=commitdiff;hp=foo-symlinked-to-bar;h=foo-becomes-a-directory"'
382 test_debug
'cat gitweb.log'
384 test_expect_success \
385 'commitdiff(2): directory becomes symlink' \
386 'gitweb_run "p=.git;a=commitdiff;hp=foo-becomes-a-directory;h=foo-symlinked-to-bar"'
387 test_debug
'cat gitweb.log'
389 # ----------------------------------------------------------------------
390 # commit, commitdiff: merge, large
391 test_expect_success \
394 echo "Branch" >> b &&
396 git commit -a -m "On branch" &&
397 git checkout master &&
400 test_expect_success \
401 'commit(0): merge commit' \
402 'gitweb_run "p=.git;a=commit"'
403 test_debug
'cat gitweb.log'
405 test_expect_success \
406 'commitdiff(0): merge commit' \
407 'gitweb_run "p=.git;a=commitdiff"'
408 test_debug
'cat gitweb.log'
410 test_expect_success \
411 'Prepare large commit' \
413 echo "To be changed" > 01-change &&
414 echo "To be renamed" > 02-pure-rename-from &&
415 echo "To be deleted" > 03-delete &&
416 echo "To be renamed and changed" > 04-rename-from &&
417 echo "To have mode changed" > 05-mode-change &&
418 echo "File to symlink" > 06-file-or-symlink &&
419 echo "To be changed and have mode changed" > 07-change-mode-change &&
421 git commit -a -m "Prepare large commit" &&
422 echo "Changed" > 01-change &&
423 git mv 02-pure-rename-from 02-pure-rename-to &&
424 git rm 03-delete && rm -f 03-delete &&
425 echo "A new file" > 03-new &&
427 git mv 04-rename-from 04-rename-to &&
428 echo "Changed" >> 04-rename-to &&
429 safe_chmod +x 05-mode-change &&
430 rm -f 06-file-or-symlink && ln -s 01-change 06-file-or-symlink &&
431 echo "Changed and have mode changed" > 07-change-mode-change &&
432 safe_chmod +x 07-change-mode-change &&
433 git commit -a -m "Large commit" &&
436 test_expect_success \
437 'commit(1): large commit' \
438 'gitweb_run "p=.git;a=commit;h=b"'
439 test_debug
'cat gitweb.log'
441 test_expect_success \
442 'commitdiff(1): large commit' \
443 'gitweb_run "p=.git;a=commitdiff;h=b"'
444 test_debug
'cat gitweb.log'
446 # ----------------------------------------------------------------------
449 test_expect_success \
450 'tags: list of different types of tags' \
451 'git checkout master &&
452 git tag -a -m "Tag commit object" tag-commit HEAD &&
453 git tag -a -m "" tag-commit-nomessage HEAD &&
454 git tag -a -m "Tag tag object" tag-tag tag-commit &&
455 git tag -a -m "Tag tree object" tag-tree HEAD^{tree} &&
456 git tag -a -m "Tag blob object" tag-blob HEAD:file &&
457 git tag lightweight/tag-commit HEAD &&
458 git tag lightweight/tag-tag tag-commit &&
459 git tag lightweight/tag-tree HEAD^{tree} &&
460 git tag lightweight/tag-blob HEAD:file &&
461 gitweb_run "p=.git;a=tags"'
462 test_debug
'cat gitweb.log'
464 test_expect_success \
465 'tag: Tag to commit object' \
466 'gitweb_run "p=.git;a=tag;h=tag-commit"'
467 test_debug
'cat gitweb.log'
469 test_expect_success \
470 'tag: on lightweight tag (invalid)' \
471 'gitweb_run "p=.git;a=tag;h=lightweight/tag-commit"'
472 test_debug
'cat gitweb.log'
474 # ----------------------------------------------------------------------
477 test_expect_success \
478 'logs: log (implicit HEAD)' \
479 'gitweb_run "p=.git;a=log"'
480 test_debug
'cat gitweb.log'
482 test_expect_success \
483 'logs: shortlog (implicit HEAD)' \
484 'gitweb_run "p=.git;a=shortlog"'
485 test_debug
'cat gitweb.log'
487 test_expect_success \
488 'logs: history (implicit HEAD, file)' \
489 'gitweb_run "p=.git;a=history;f=file"'
490 test_debug
'cat gitweb.log'
492 test_expect_success \
493 'logs: history (implicit HEAD, non-existent file)' \
494 'gitweb_run "p=.git;a=history;f=non-existent"'
495 test_debug
'cat gitweb.log'
497 test_expect_success \
498 'logs: history (implicit HEAD, deleted file)' \
499 'git checkout master &&
500 echo "to be deleted" > deleted_file &&
501 git add deleted_file &&
502 git commit -m "Add file to be deleted" &&
503 git rm deleted_file &&
504 git commit -m "Delete file" &&
505 gitweb_run "p=.git;a=history;f=deleted_file"'
506 test_debug
'cat gitweb.log'
508 # ----------------------------------------------------------------------
511 test_expect_success \
513 'gitweb_run "a=opml"'
514 test_debug
'cat gitweb.log'
516 test_expect_success \
518 'gitweb_run "p=.git;a=rss"'
519 test_debug
'cat gitweb.log'
521 test_expect_success \
523 'gitweb_run "p=.git;a=atom"'
524 test_debug
'cat gitweb.log'
526 # ----------------------------------------------------------------------
529 test_expect_success \
530 'encode(commit): utf8' \
531 '. ../t3901-utf8.txt &&
532 echo "UTF-8" >> file &&
534 git commit -F ../t3900/1-UTF-8.txt &&
535 gitweb_run "p=.git;a=commit"'
536 test_debug
'cat gitweb.log'
538 test_expect_success \
539 'encode(commit): iso-8859-1' \
540 '. ../t3901-8859-1.txt &&
541 echo "ISO-8859-1" >> file &&
543 git config i18n.commitencoding ISO-8859-1 &&
544 git commit -F ../t3900/ISO-8859-1.txt &&
545 git config --unset i18n.commitencoding &&
546 gitweb_run "p=.git;a=commit"'
547 test_debug
'cat gitweb.log'
549 test_expect_success \
550 'encode(log): utf-8 and iso-8859-1' \
551 'gitweb_run "p=.git;a=log"'
552 test_debug
'cat gitweb.log'
554 # ----------------------------------------------------------------------
557 test_expect_success \
558 'opt: log --no-merges' \
559 'gitweb_run "p=.git;a=log;opt=--no-merges"'
560 test_debug
'cat gitweb.log'
562 test_expect_success \
563 'opt: atom --no-merges' \
564 'gitweb_run "p=.git;a=log;opt=--no-merges"'
565 test_debug
'cat gitweb.log'
567 test_expect_success \
568 'opt: "file" history --no-merges' \
569 'gitweb_run "p=.git;a=history;f=file;opt=--no-merges"'
570 test_debug
'cat gitweb.log'
572 test_expect_success \
573 'opt: log --no-such-option (invalid option)' \
574 'gitweb_run "p=.git;a=log;opt=--no-such-option"'
575 test_debug
'cat gitweb.log'
577 test_expect_success \
578 'opt: tree --no-merges (invalid option for action)' \
579 'gitweb_run "p=.git;a=tree;opt=--no-merges"'
580 test_debug
'cat gitweb.log'
582 # ----------------------------------------------------------------------
583 # testing config_to_multi / cloneurl
585 test_expect_success \
586 'URL: no project URLs, no base URL' \
587 'gitweb_run "p=.git;a=summary"'
588 test_debug
'cat gitweb.log'
590 test_expect_success \
591 'URL: project URLs via gitweb.url' \
592 'git config --add gitweb.url git://example.com/git/trash.git &&
593 git config --add gitweb.url http://example.com/git/trash.git &&
594 gitweb_run "p=.git;a=summary"'
595 test_debug
'cat gitweb.log'
597 cat >.git
/cloneurl
<<\EOF
598 git
://example.com
/git
/trash.git
599 http
://example.com
/git
/trash.git
602 test_expect_success \
603 'URL: project URLs via cloneurl file' \
604 'gitweb_run "p=.git;a=summary"'
605 test_debug
'cat gitweb.log'
607 # ----------------------------------------------------------------------
608 # gitweb config and repo config
610 cat >>gitweb_config.perl
<<EOF
612 \$feature{'blame'}{'override'} = 1;
613 \$feature{'snapshot'}{'override'} = 1;
616 test_expect_success \
617 'config override: tree view, features disabled in repo config' \
618 'git config gitweb.blame no &&
619 git config gitweb.snapshot none &&
620 gitweb_run "p=.git;a=tree"'
621 test_debug
'cat gitweb.log'
623 test_expect_success \
624 'config override: tree view, features enabled in repo config' \
625 'git config gitweb.blame yes &&
626 git config gitweb.snapshot "zip,tgz, tbz2" &&
627 gitweb_run "p=.git;a=tree"'
628 test_debug
'cat gitweb.log'