1#!/bin/sh
   2#
   3# Copyright (c) 2007 Jakub Narebski
   4#
   5test_description='gitweb as standalone script (basic tests).
   7This test runs gitweb (git web interface) as CGI script from
   9commandline, and checks that it would not write any errors
  10or warnings to log.'
  11gitweb_init () {
  13        safe_pwd="$(perl -MPOSIX=getcwd -e 'print quotemeta(getcwd)')"
  14        cat >gitweb_config.perl <<EOF
  15#!/usr/bin/perl
  16# gitweb configuration for tests
  18our \$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:///$safe_pwd/../../gitweb/gitweb.css");
  29our \$logo = "file:///$safe_pwd/../../gitweb/git-logo.png";
  30our \$favicon = "file:///$safe_pwd/../../gitweb/git-favicon.png";
  31our \$projects_list = "";
  32our \$export_ok = "";
  33our \$strict_export = "";
  34EOF
  36        cat >.git/description <<EOF
  38$0 test repository
  39EOF
  40}
  41gitweb_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        GITWEB_CONFIG=$(pwd)/gitweb_config.perl
  51        export GITWEB_CONFIG
  52        # 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 -- "$(pwd)/../../gitweb/gitweb.perl" \
  58                >/dev/null 2>gitweb.log &&
  59        if grep -q -s "^[[]" gitweb.log >/dev/null; then false; else true; fi
  60        # gitweb.log is left for debugging
  62}
  63safe_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. ./test-lib.sh
  73perl -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}
  79gitweb_init
  81# ----------------------------------------------------------------------
  83# no commits (empty, just initialized repository)
  84test_expect_success \
  86        'no commits: projects_list (implicit)' \
  87        'gitweb_run'
  88test_debug 'cat gitweb.log'
  89test_expect_success \
  91        'no commits: projects_index' \
  92        'gitweb_run "a=project_index"'
  93test_debug 'cat gitweb.log'
  94test_expect_success \
  96        'no commits: .git summary (implicit)' \
  97        'gitweb_run "p=.git"'
  98test_debug 'cat gitweb.log'
  99test_expect_success \
 101        'no commits: .git commit (implicit HEAD)' \
 102        'gitweb_run "p=.git;a=commit"'
 103test_debug 'cat gitweb.log'
 104test_expect_success \
 106        'no commits: .git commitdiff (implicit HEAD)' \
 107        'gitweb_run "p=.git;a=commitdiff"'
 108test_debug 'cat gitweb.log'
 109test_expect_success \
 111        'no commits: .git tree (implicit HEAD)' \
 112        'gitweb_run "p=.git;a=tree"'
 113test_debug 'cat gitweb.log'
 114test_expect_success \
 116        'no commits: .git heads' \
 117        'gitweb_run "p=.git;a=heads"'
 118test_debug 'cat gitweb.log'
 119test_expect_success \
 121        'no commits: .git tags' \
 122        'gitweb_run "p=.git;a=tags"'
 123test_debug 'cat gitweb.log'
 124# ----------------------------------------------------------------------
 127# initial commit
 128test_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'
 135test_expect_success \
 137        'projects_list (implicit)' \
 138        'gitweb_run'
 139test_debug 'cat gitweb.log'
 140test_expect_success \
 142        'projects_index' \
 143        'gitweb_run "a=project_index"'
 144test_debug 'cat gitweb.log'
 145test_expect_success \
 147        '.git summary (implicit)' \
 148        'gitweb_run "p=.git"'
 149test_debug 'cat gitweb.log'
 150test_expect_success \
 152        '.git commit (implicit HEAD)' \
 153        'gitweb_run "p=.git;a=commit"'
 154test_debug 'cat gitweb.log'
 155test_expect_success \
 157        '.git commitdiff (implicit HEAD, root commit)' \
 158        'gitweb_run "p=.git;a=commitdiff"'
 159test_debug 'cat gitweb.log'
 160test_expect_success \
 162        '.git commitdiff_plain (implicit HEAD, root commit)' \
 163        'gitweb_run "p=.git;a=commitdiff_plain"'
 164test_debug 'cat gitweb.log'
 165test_expect_success \
 167        '.git commit (HEAD)' \
 168        'gitweb_run "p=.git;a=commit;h=HEAD"'
 169test_debug 'cat gitweb.log'
 170test_expect_success \
 172        '.git tree (implicit HEAD)' \
 173        'gitweb_run "p=.git;a=tree"'
 174test_debug 'cat gitweb.log'
 175test_expect_success \
 177        '.git blob (file)' \
 178        'gitweb_run "p=.git;a=blob;f=file"'
 179test_debug 'cat gitweb.log'
 180test_expect_success \
 182        '.git blob_plain (file)' \
 183        'gitweb_run "p=.git;a=blob_plain;f=file"'
 184test_debug 'cat gitweb.log'
 185# ----------------------------------------------------------------------
 187# nonexistent objects
 188test_expect_success \
 190        '.git commit (non-existent)' \
 191        'gitweb_run "p=.git;a=commit;h=non-existent"'
 192test_debug 'cat gitweb.log'
 193test_expect_success \
 195        '.git commitdiff (non-existent)' \
 196        'gitweb_run "p=.git;a=commitdiff;h=non-existent"'
 197test_debug 'cat gitweb.log'
 198test_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'
 203test_expect_success \
 205        '.git tree (0000000000000000000000000000000000000000)' \
 206        'gitweb_run "p=.git;a=tree;h=0000000000000000000000000000000000000000"'
 207test_debug 'cat gitweb.log'
 208test_expect_success \
 210        '.git tag (0000000000000000000000000000000000000000)' \
 211        'gitweb_run "p=.git;a=tag;h=0000000000000000000000000000000000000000"'
 212test_debug 'cat gitweb.log'
 213test_expect_success \
 215        '.git blob (non-existent)' \
 216        'gitweb_run "p=.git;a=blob;f=non-existent"'
 217test_debug 'cat gitweb.log'
 218test_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# ----------------------------------------------------------------------
 226# commitdiff testing (implicit, one implicit tree-ish)
 227test_expect_success \
 229        'commitdiff(0): root' \
 230        'gitweb_run "p=.git;a=commitdiff"'
 231test_debug 'cat gitweb.log'
 232test_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'
 240test_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'
 247test_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'
 254test_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'
 262test_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'
 270test_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'
 278test_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'
 286test_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'
 304test_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# ----------------------------------------------------------------------
 315# commitdiff testing (taken from t4114-apply-typechange.sh)
 316test_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        '
 345test_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'
 350test_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'
 355test_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'
 360test_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'
 365test_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'
 370test_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'
 375test_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'
 380test_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# ----------------------------------------------------------------------
 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'
 396test_expect_success \
 398        'commit(0): merge commit' \
 399        'gitweb_run "p=.git;a=commit"'
 400test_debug 'cat gitweb.log'
 401test_expect_success \
 403        'commitdiff(0): merge commit' \
 404        'gitweb_run "p=.git;a=commitdiff"'
 405test_debug 'cat gitweb.log'
 406test_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'
 432test_expect_success \
 434        'commit(1): large commit' \
 435        'gitweb_run "p=.git;a=commit;h=b"'
 436test_debug 'cat gitweb.log'
 437test_expect_success \
 439        'commitdiff(1): large commit' \
 440        'gitweb_run "p=.git;a=commitdiff;h=b"'
 441test_debug 'cat gitweb.log'
 442# ----------------------------------------------------------------------
 444# tags testing
 445test_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'
 460test_expect_success \
 462        'tag: Tag to commit object' \
 463        'gitweb_run "p=.git;a=tag;h=tag-commit"'
 464test_debug 'cat gitweb.log'
 465test_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# ----------------------------------------------------------------------
 472# logs
 473test_expect_success \
 475        'logs: log (implicit HEAD)' \
 476        'gitweb_run "p=.git;a=log"'
 477test_debug 'cat gitweb.log'
 478test_expect_success \
 480        'logs: shortlog (implicit HEAD)' \
 481        'gitweb_run "p=.git;a=shortlog"'
 482test_debug 'cat gitweb.log'
 483test_expect_success \
 485        'logs: history (implicit HEAD, file)' \
 486        'gitweb_run "p=.git;a=history;f=file"'
 487test_debug 'cat gitweb.log'
 488test_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'
 493test_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# ----------------------------------------------------------------------
 506# feed generation
 507test_expect_success \
 509        'feeds: OPML' \
 510        'gitweb_run "a=opml"'
 511test_debug 'cat gitweb.log'
 512test_expect_success \
 514        'feed: RSS' \
 515        'gitweb_run "p=.git;a=rss"'
 516test_debug 'cat gitweb.log'
 517test_expect_success \
 519        'feed: Atom' \
 520        'gitweb_run "p=.git;a=atom"'
 521test_debug 'cat gitweb.log'
 522# ----------------------------------------------------------------------
 524# encoding/decoding
 525test_expect_success \
 527        'encode(commit): utf8' \
 528        '. ../t3901-utf8.txt &&
 529         echo "UTF-8" >> file &&
 530         git add file &&
 531         git commit -F ../t3900/1-UTF-8.txt &&
 532         gitweb_run "p=.git;a=commit"'
 533test_debug 'cat gitweb.log'
 534test_expect_success \
 536        'encode(commit): iso-8859-1' \
 537        '. ../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 ../t3900/ISO-8859-1.txt &&
 542         git config --unset i18n.commitencoding &&
 543         gitweb_run "p=.git;a=commit"'
 544test_debug 'cat gitweb.log'
 545test_expect_success \
 547        'encode(log): utf-8 and iso-8859-1' \
 548        'gitweb_run "p=.git;a=log"'
 549test_debug 'cat gitweb.log'
 550# ----------------------------------------------------------------------
 552# extra options
 553test_expect_success \
 555        'opt: log --no-merges' \
 556        'gitweb_run "p=.git;a=log;opt=--no-merges"'
 557test_debug 'cat gitweb.log'
 558test_expect_success \
 560        'opt: atom --no-merges' \
 561        'gitweb_run "p=.git;a=log;opt=--no-merges"'
 562test_debug 'cat gitweb.log'
 563test_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'
 568test_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'
 573test_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# ----------------------------------------------------------------------
 580# testing config_to_multi / cloneurl
 581test_expect_success \
 583       'URL: no project URLs, no base URL' \
 584       'gitweb_run "p=.git;a=summary"'
 585test_debug 'cat gitweb.log'
 586test_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'
 593cat >.git/cloneurl <<\EOF
 595git://example.com/git/trash.git
 596http://example.com/git/trash.git
 597EOF
 598test_expect_success \
 600       'URL: project URLs via cloneurl file' \
 601       'gitweb_run "p=.git;a=summary"'
 602test_debug 'cat gitweb.log'
 603# ----------------------------------------------------------------------
 605# gitweb config and repo config
 606cat >>gitweb_config.perl <<EOF
 608\$feature{'blame'}{'override'} = 1;
 610\$feature{'snapshot'}{'override'} = 1;
 611EOF
 612test_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'
 619test_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'
 626test_done