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