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