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