1#!/bin/sh
2#
3# Copyright (c) 2007 Jakub Narebski
4#
5
6test_description='gitweb as standalone script (basic tests).
7
8This test runs gitweb (git web interface) as CGI script from
9commandline, and checks that it would not write any errors
10or warnings to log.'
11
12gitweb_init () {
13 safe_pwd="$(perl -MPOSIX=getcwd -e 'print quotemeta(getcwd)')"
14 cat >gitweb_config.perl <<EOF
15#!/usr/bin/perl
16
17# gitweb configuration for tests
18
19our \$version = "current";
20our \$GIT = "git";
21our \$projectroot = "$safe_pwd";
22our \$project_maxdepth = 8;
23our \$home_link_str = "projects";
24our \$site_name = "[localhost]";
25our \$site_header = "";
26our \$site_footer = "";
27our \$home_text = "indextext.html";
28our @stylesheets = ("file:///$TEST_DIRECTORY/../gitweb/gitweb.css");
29our \$logo = "file:///$TEST_DIRECTORY/../gitweb/git-logo.png";
30our \$favicon = "file:///$TEST_DIRECTORY/../gitweb/git-favicon.png";
31our \$projects_list = "";
32our \$export_ok = "";
33our \$strict_export = "";
34
35EOF
36
37 cat >.git/description <<EOF
38$0 test repository
39EOF
40}
41
42gitweb_run () {
43 GATEWAY_INTERFACE="CGI/1.1"
44 HTTP_ACCEPT="*/*"
45 REQUEST_METHOD="GET"
46 QUERY_STRING=""$1""
47 PATH_INFO=""$2""
48 export GATEWAY_INTERFACE HTTP_ACCEPT REQUEST_METHOD QUERY_STRING PATH_INFO
49
50 GITWEB_CONFIG=$(pwd)/gitweb_config.perl
51 export GITWEB_CONFIG
52
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
56 rm -f gitweb.log &&
57 perl -- "$TEST_DIRECTORY/../gitweb/gitweb.perl" \
58 >/dev/null 2>gitweb.log &&
59 if grep -q -s "^[[]" gitweb.log >/dev/null; then false; else true; fi
60
61 # gitweb.log is left for debugging
62}
63
64safe_chmod () {
65 chmod "$1" "$2" &&
66 if [ "$(git config --get core.filemode)" = false ]
67 then
68 git update-index --chmod="$1" "$2"
69 fi
70}
71
72. ./test-lib.sh
73
74perl -MEncode -e 'decode_utf8("", Encode::FB_CROAK)' >/dev/null 2>&1 || {
75 test_expect_success 'skipping gitweb tests, perl version is too old' :
76 test_done
77 exit
78}
79
80gitweb_init
81
82# ----------------------------------------------------------------------
83# no commits (empty, just initialized repository)
84
85test_expect_success \
86 'no commits: projects_list (implicit)' \
87 'gitweb_run'
88test_debug 'cat gitweb.log'
89
90test_expect_success \
91 'no commits: projects_index' \
92 'gitweb_run "a=project_index"'
93test_debug 'cat gitweb.log'
94
95test_expect_success \
96 'no commits: .git summary (implicit)' \
97 'gitweb_run "p=.git"'
98test_debug 'cat gitweb.log'
99
100test_expect_success \
101 'no commits: .git commit (implicit HEAD)' \
102 'gitweb_run "p=.git;a=commit"'
103test_debug 'cat gitweb.log'
104
105test_expect_success \
106 'no commits: .git commitdiff (implicit HEAD)' \
107 'gitweb_run "p=.git;a=commitdiff"'
108test_debug 'cat gitweb.log'
109
110test_expect_success \
111 'no commits: .git tree (implicit HEAD)' \
112 'gitweb_run "p=.git;a=tree"'
113test_debug 'cat gitweb.log'
114
115test_expect_success \
116 'no commits: .git heads' \
117 'gitweb_run "p=.git;a=heads"'
118test_debug 'cat gitweb.log'
119
120test_expect_success \
121 'no commits: .git tags' \
122 'gitweb_run "p=.git;a=tags"'
123test_debug 'cat gitweb.log'
124
125
126# ----------------------------------------------------------------------
127# initial commit
128
129test_expect_success \
130 'Make initial commit' \
131 'echo "Not an empty file." > file &&
132 git add file &&
133 git commit -a -m "Initial commit." &&
134 git branch b'
135
136test_expect_success \
137 'projects_list (implicit)' \
138 'gitweb_run'
139test_debug 'cat gitweb.log'
140
141test_expect_success \
142 'projects_index' \
143 'gitweb_run "a=project_index"'
144test_debug 'cat gitweb.log'
145
146test_expect_success \
147 '.git summary (implicit)' \
148 'gitweb_run "p=.git"'
149test_debug 'cat gitweb.log'
150
151test_expect_success \
152 '.git commit (implicit HEAD)' \
153 'gitweb_run "p=.git;a=commit"'
154test_debug 'cat gitweb.log'
155
156test_expect_success \
157 '.git commitdiff (implicit HEAD, root commit)' \
158 'gitweb_run "p=.git;a=commitdiff"'
159test_debug 'cat gitweb.log'
160
161test_expect_success \
162 '.git commitdiff_plain (implicit HEAD, root commit)' \
163 'gitweb_run "p=.git;a=commitdiff_plain"'
164test_debug 'cat gitweb.log'
165
166test_expect_success \
167 '.git commit (HEAD)' \
168 'gitweb_run "p=.git;a=commit;h=HEAD"'
169test_debug 'cat gitweb.log'
170
171test_expect_success \
172 '.git tree (implicit HEAD)' \
173 'gitweb_run "p=.git;a=tree"'
174test_debug 'cat gitweb.log'
175
176test_expect_success \
177 '.git blob (file)' \
178 'gitweb_run "p=.git;a=blob;f=file"'
179test_debug 'cat gitweb.log'
180
181test_expect_success \
182 '.git blob_plain (file)' \
183 'gitweb_run "p=.git;a=blob_plain;f=file"'
184test_debug 'cat gitweb.log'
185
186# ----------------------------------------------------------------------
187# nonexistent objects
188
189test_expect_success \
190 '.git commit (non-existent)' \
191 'gitweb_run "p=.git;a=commit;h=non-existent"'
192test_debug 'cat gitweb.log'
193
194test_expect_success \
195 '.git commitdiff (non-existent)' \
196 'gitweb_run "p=.git;a=commitdiff;h=non-existent"'
197test_debug 'cat gitweb.log'
198
199test_expect_success \
200 '.git commitdiff (non-existent vs HEAD)' \
201 'gitweb_run "p=.git;a=commitdiff;hp=non-existent;h=HEAD"'
202test_debug 'cat gitweb.log'
203
204test_expect_success \
205 '.git tree (0000000000000000000000000000000000000000)' \
206 'gitweb_run "p=.git;a=tree;h=0000000000000000000000000000000000000000"'
207test_debug 'cat gitweb.log'
208
209test_expect_success \
210 '.git tag (0000000000000000000000000000000000000000)' \
211 'gitweb_run "p=.git;a=tag;h=0000000000000000000000000000000000000000"'
212test_debug 'cat gitweb.log'
213
214test_expect_success \
215 '.git blob (non-existent)' \
216 'gitweb_run "p=.git;a=blob;f=non-existent"'
217test_debug 'cat gitweb.log'
218
219test_expect_success \
220 '.git blob_plain (non-existent)' \
221 'gitweb_run "p=.git;a=blob_plain;f=non-existent"'
222test_debug 'cat gitweb.log'
223
224
225# ----------------------------------------------------------------------
226# commitdiff testing (implicit, one implicit tree-ish)
227
228test_expect_success \
229 'commitdiff(0): root' \
230 'gitweb_run "p=.git;a=commitdiff"'
231test_debug 'cat gitweb.log'
232
233test_expect_success \
234 'commitdiff(0): file added' \
235 'echo "New file" > new_file &&
236 git add new_file &&
237 git commit -a -m "File added." &&
238 gitweb_run "p=.git;a=commitdiff"'
239test_debug 'cat gitweb.log'
240
241test_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"'
246test_debug 'cat gitweb.log'
247
248test_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"'
253test_debug 'cat gitweb.log'
254
255test_expect_success \
256 'commitdiff(0): file to symlink' \
257 'rm renamed_file &&
258 ln -s file renamed_file &&
259 git commit -a -m "File to symlink." &&
260 gitweb_run "p=.git;a=commitdiff"'
261test_debug 'cat gitweb.log'
262
263test_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"'
269test_debug 'cat gitweb.log'
270
271test_expect_success \
272 'commitdiff(0): file copied / new file' \
273 'cp file file2 &&
274 git add file2 &&
275 git commit -a -m "File copied." &&
276 gitweb_run "p=.git;a=commitdiff"'
277test_debug 'cat gitweb.log'
278
279test_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"'
285test_debug 'cat gitweb.log'
286
287test_expect_success \
288 'commitdiff(0): renamed and modified' \
289 'cat >file2<<EOF &&
290Dominus regit me,
291et nihil mihi deerit.
292In loco pascuae ibi me collocavit,
293super aquam refectionis educavit me;
294animam meam convertit,
295deduxit me super semitas jusitiae,
296propter nomen suum.
297EOF
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"'
303test_debug 'cat gitweb.log'
304
305test_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"'
312test_debug 'cat gitweb.log'
313
314# ----------------------------------------------------------------------
315# commitdiff testing (taken from t4114-apply-typechange.sh)
316
317test_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 &&
323 rm -f foo &&
324 ln -s bar foo &&
325 git update-index foo &&
326 git commit -m "foo symlinked to bar" &&
327 git branch foo-symlinked-to-bar &&
328 rm -f foo &&
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 &&
333 rm -f foo &&
334 git update-index --remove foo &&
335 mkdir 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
344 '
345
346test_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"'
349test_debug 'cat gitweb.log'
350
351test_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"'
354test_debug 'cat gitweb.log'
355
356test_expect_success \
357 'commitdiff(2): directory becomes file' \
358 'gitweb_run "p=.git;a=commitdiff;hp=foo-becomes-a-directory;h=initial"'
359test_debug 'cat gitweb.log'
360
361test_expect_success \
362 'commitdiff(2): file becomes directory' \
363 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-becomes-a-directory"'
364test_debug 'cat gitweb.log'
365
366test_expect_success \
367 'commitdiff(2): file becomes symlink' \
368 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-symlinked-to-bar"'
369test_debug 'cat gitweb.log'
370
371test_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"'
374test_debug 'cat gitweb.log'
375
376test_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"'
379test_debug 'cat gitweb.log'
380
381test_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"'
384test_debug 'cat gitweb.log'
385
386# ----------------------------------------------------------------------
387# commit, commitdiff: merge, large
388test_expect_success \
389 'Create a merge' \
390 'git checkout b &&
391 echo "Branch" >> b &&
392 git add b &&
393 git commit -a -m "On branch" &&
394 git checkout master &&
395 git pull . b'
396
397test_expect_success \
398 'commit(0): merge commit' \
399 'gitweb_run "p=.git;a=commit"'
400test_debug 'cat gitweb.log'
401
402test_expect_success \
403 'commitdiff(0): merge commit' \
404 'gitweb_run "p=.git;a=commitdiff"'
405test_debug 'cat gitweb.log'
406
407test_expect_success \
408 'Prepare large commit' \
409 'git checkout b &&
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 &&
417 git add 0* &&
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 &&
423 git add 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" &&
431 git checkout master'
432
433test_expect_success \
434 'commit(1): large commit' \
435 'gitweb_run "p=.git;a=commit;h=b"'
436test_debug 'cat gitweb.log'
437
438test_expect_success \
439 'commitdiff(1): large commit' \
440 'gitweb_run "p=.git;a=commitdiff;h=b"'
441test_debug 'cat gitweb.log'
442
443# ----------------------------------------------------------------------
444# tags testing
445
446test_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"'
459test_debug 'cat gitweb.log'
460
461test_expect_success \
462 'tag: Tag to commit object' \
463 'gitweb_run "p=.git;a=tag;h=tag-commit"'
464test_debug 'cat gitweb.log'
465
466test_expect_success \
467 'tag: on lightweight tag (invalid)' \
468 'gitweb_run "p=.git;a=tag;h=lightweight/tag-commit"'
469test_debug 'cat gitweb.log'
470
471# ----------------------------------------------------------------------
472# logs
473
474test_expect_success \
475 'logs: log (implicit HEAD)' \
476 'gitweb_run "p=.git;a=log"'
477test_debug 'cat gitweb.log'
478
479test_expect_success \
480 'logs: shortlog (implicit HEAD)' \
481 'gitweb_run "p=.git;a=shortlog"'
482test_debug 'cat gitweb.log'
483
484test_expect_success \
485 'logs: history (implicit HEAD, file)' \
486 'gitweb_run "p=.git;a=history;f=file"'
487test_debug 'cat gitweb.log'
488
489test_expect_success \
490 'logs: history (implicit HEAD, non-existent file)' \
491 'gitweb_run "p=.git;a=history;f=non-existent"'
492test_debug 'cat gitweb.log'
493
494test_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"'
503test_debug 'cat gitweb.log'
504
505# ----------------------------------------------------------------------
506# feed generation
507
508test_expect_success \
509 'feeds: OPML' \
510 'gitweb_run "a=opml"'
511test_debug 'cat gitweb.log'
512
513test_expect_success \
514 'feed: RSS' \
515 'gitweb_run "p=.git;a=rss"'
516test_debug 'cat gitweb.log'
517
518test_expect_success \
519 'feed: Atom' \
520 'gitweb_run "p=.git;a=atom"'
521test_debug 'cat gitweb.log'
522
523# ----------------------------------------------------------------------
524# encoding/decoding
525
526test_expect_success \
527 'encode(commit): utf8' \
528 '. "$TEST_DIRECTORY"/t3901-utf8.txt &&
529 echo "UTF-8" >> file &&
530 git add file &&
531 git commit -F "$TEST_DIRECTORY"/t3900/1-UTF-8.txt &&
532 gitweb_run "p=.git;a=commit"'
533test_debug 'cat gitweb.log'
534
535test_expect_success \
536 'encode(commit): iso-8859-1' \
537 '. "$TEST_DIRECTORY"/t3901-8859-1.txt &&
538 echo "ISO-8859-1" >> file &&
539 git add file &&
540 git config i18n.commitencoding ISO-8859-1 &&
541 git commit -F "$TEST_DIRECTORY"/t3900/ISO-8859-1.txt &&
542 git config --unset i18n.commitencoding &&
543 gitweb_run "p=.git;a=commit"'
544test_debug 'cat gitweb.log'
545
546test_expect_success \
547 'encode(log): utf-8 and iso-8859-1' \
548 'gitweb_run "p=.git;a=log"'
549test_debug 'cat gitweb.log'
550
551# ----------------------------------------------------------------------
552# extra options
553
554test_expect_success \
555 'opt: log --no-merges' \
556 'gitweb_run "p=.git;a=log;opt=--no-merges"'
557test_debug 'cat gitweb.log'
558
559test_expect_success \
560 'opt: atom --no-merges' \
561 'gitweb_run "p=.git;a=log;opt=--no-merges"'
562test_debug 'cat gitweb.log'
563
564test_expect_success \
565 'opt: "file" history --no-merges' \
566 'gitweb_run "p=.git;a=history;f=file;opt=--no-merges"'
567test_debug 'cat gitweb.log'
568
569test_expect_success \
570 'opt: log --no-such-option (invalid option)' \
571 'gitweb_run "p=.git;a=log;opt=--no-such-option"'
572test_debug 'cat gitweb.log'
573
574test_expect_success \
575 'opt: tree --no-merges (invalid option for action)' \
576 'gitweb_run "p=.git;a=tree;opt=--no-merges"'
577test_debug 'cat gitweb.log'
578
579# ----------------------------------------------------------------------
580# testing config_to_multi / cloneurl
581
582test_expect_success \
583 'URL: no project URLs, no base URL' \
584 'gitweb_run "p=.git;a=summary"'
585test_debug 'cat gitweb.log'
586
587test_expect_success \
588 'URL: project URLs via gitweb.url' \
589 'git config --add gitweb.url git://example.com/git/trash.git &&
590 git config --add gitweb.url http://example.com/git/trash.git &&
591 gitweb_run "p=.git;a=summary"'
592test_debug 'cat gitweb.log'
593
594cat >.git/cloneurl <<\EOF
595git://example.com/git/trash.git
596http://example.com/git/trash.git
597EOF
598
599test_expect_success \
600 'URL: project URLs via cloneurl file' \
601 'gitweb_run "p=.git;a=summary"'
602test_debug 'cat gitweb.log'
603
604# ----------------------------------------------------------------------
605# gitweb config and repo config
606
607cat >>gitweb_config.perl <<EOF
608
609\$feature{'blame'}{'override'} = 1;
610\$feature{'snapshot'}{'override'} = 1;
611EOF
612
613test_expect_success \
614 'config override: tree view, features disabled in repo config' \
615 'git config gitweb.blame no &&
616 git config gitweb.snapshot none &&
617 gitweb_run "p=.git;a=tree"'
618test_debug 'cat gitweb.log'
619
620test_expect_success \
621 'config override: tree view, features enabled in repo config' \
622 'git config gitweb.blame yes &&
623 git config gitweb.snapshot "zip,tgz, tbz2" &&
624 gitweb_run "p=.git;a=tree"'
625test_debug 'cat gitweb.log'
626
627test_done