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        cat >gitweb_config.perl <<EOF
  14#!/usr/bin/perl
  15# gitweb configuration for tests
  17our \$version = "current";
  19our \$GIT = "git";
  20our \$projectroot = "$(pwd)";
  21our \$home_link_str = "projects";
  22our \$site_name = "[localhost]";
  23our \$site_header = "";
  24our \$site_footer = "";
  25our \$home_text = "indextext.html";
  26our @stylesheets = ("file:///$(pwd)/../../gitweb/gitweb.css");
  27our \$logo = "file:///$(pwd)/../../gitweb/git-logo.png";
  28our \$favicon = "file:///$(pwd)/../../gitweb/git-favicon.png";
  29our \$projects_list = "";
  30our \$export_ok = "";
  31our \$strict_export = "";
  32CGI::Carp::set_programname("gitweb/gitweb.cgi");
  34EOF
  35        cat >.git/description <<EOF
  37$0 test repository
  38EOF
  39}
  40gitweb_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        export GITWEB_CONFIG=$(pwd)/gitweb_config.perl
  49        # 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        # gitweb.log is left for debugging
  59}
  60safe_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. ./test-lib.sh
  70perl -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}
  76gitweb_init
  78# ----------------------------------------------------------------------
  80# no commits (empty, just initialized repository)
  81test_expect_success \
  83        'no commits: projects_list (implicit)' \
  84        'gitweb_run'
  85test_debug 'cat gitweb.log'
  86test_expect_success \
  88        'no commits: projects_index' \
  89        'gitweb_run "a=project_index"'
  90test_debug 'cat gitweb.log'
  91test_expect_success \
  93        'no commits: .git summary (implicit)' \
  94        'gitweb_run "p=.git"'
  95test_debug 'cat gitweb.log'
  96test_expect_success \
  98        'no commits: .git commit (implicit HEAD)' \
  99        'gitweb_run "p=.git;a=commit"'
 100test_debug 'cat gitweb.log'
 101test_expect_success \
 103        'no commits: .git commitdiff (implicit HEAD)' \
 104        'gitweb_run "p=.git;a=commitdiff"'
 105test_debug 'cat gitweb.log'
 106test_expect_success \
 108        'no commits: .git tree (implicit HEAD)' \
 109        'gitweb_run "p=.git;a=tree"'
 110test_debug 'cat gitweb.log'
 111test_expect_success \
 113        'no commits: .git heads' \
 114        'gitweb_run "p=.git;a=heads"'
 115test_debug 'cat gitweb.log'
 116test_expect_success \
 118        'no commits: .git tags' \
 119        'gitweb_run "p=.git;a=tags"'
 120test_debug 'cat gitweb.log'
 121# ----------------------------------------------------------------------
 124# initial commit
 125test_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'
 132test_expect_success \
 134        'projects_list (implicit)' \
 135        'gitweb_run'
 136test_debug 'cat gitweb.log'
 137test_expect_success \
 139        'projects_index' \
 140        'gitweb_run "a=project_index"'
 141test_debug 'cat gitweb.log'
 142test_expect_success \
 144        '.git summary (implicit)' \
 145        'gitweb_run "p=.git"'
 146test_debug 'cat gitweb.log'
 147test_expect_success \
 149        '.git commit (implicit HEAD)' \
 150        'gitweb_run "p=.git;a=commit"'
 151test_debug 'cat gitweb.log'
 152test_expect_success \
 154        '.git commitdiff (implicit HEAD, root commit)' \
 155        'gitweb_run "p=.git;a=commitdiff"'
 156test_debug 'cat gitweb.log'
 157test_expect_success \
 159        '.git commitdiff_plain (implicit HEAD, root commit)' \
 160        'gitweb_run "p=.git;a=commitdiff_plain"'
 161test_debug 'cat gitweb.log'
 162test_expect_success \
 164        '.git commit (HEAD)' \
 165        'gitweb_run "p=.git;a=commit;h=HEAD"'
 166test_debug 'cat gitweb.log'
 167test_expect_success \
 169        '.git tree (implicit HEAD)' \
 170        'gitweb_run "p=.git;a=tree"'
 171test_debug 'cat gitweb.log'
 172test_expect_success \
 174        '.git blob (file)' \
 175        'gitweb_run "p=.git;a=blob;f=file"'
 176test_debug 'cat gitweb.log'
 177test_expect_success \
 179        '.git blob_plain (file)' \
 180        'gitweb_run "p=.git;a=blob_plain;f=file"'
 181test_debug 'cat gitweb.log'
 182# ----------------------------------------------------------------------
 184# nonexistent objects
 185test_expect_success \
 187        '.git commit (non-existent)' \
 188        'gitweb_run "p=.git;a=commit;h=non-existent"'
 189test_debug 'cat gitweb.log'
 190test_expect_success \
 192        '.git commitdiff (non-existent)' \
 193        'gitweb_run "p=.git;a=commitdiff;h=non-existent"'
 194test_debug 'cat gitweb.log'
 195test_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'
 200test_expect_success \
 202        '.git tree (0000000000000000000000000000000000000000)' \
 203        'gitweb_run "p=.git;a=tree;h=0000000000000000000000000000000000000000"'
 204test_debug 'cat gitweb.log'
 205test_expect_success \
 207        '.git tag (0000000000000000000000000000000000000000)' \
 208        'gitweb_run "p=.git;a=tag;h=0000000000000000000000000000000000000000"'
 209test_debug 'cat gitweb.log'
 210test_expect_success \
 212        '.git blob (non-existent)' \
 213        'gitweb_run "p=.git;a=blob;f=non-existent"'
 214test_debug 'cat gitweb.log'
 215test_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# ----------------------------------------------------------------------
 223# commitdiff testing (implicit, one implicit tree-ish)
 224test_expect_success \
 226        'commitdiff(0): root' \
 227        'gitweb_run "p=.git;a=commitdiff"'
 228test_debug 'cat gitweb.log'
 229test_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'
 237test_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'
 244test_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'
 251test_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'
 259test_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'
 267test_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'
 275test_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'
 283test_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'
 301test_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# ----------------------------------------------------------------------
 312# commitdiff testing (taken from t4114-apply-typechange.sh)
 313test_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        '
 342test_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'
 347test_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'
 352test_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'
 357test_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'
 362test_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'
 367test_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'
 372test_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'
 377test_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# ----------------------------------------------------------------------
 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'
 393test_expect_success \
 395        'commit(0): merge commit' \
 396        'gitweb_run "p=.git;a=commit"'
 397test_debug 'cat gitweb.log'
 398test_expect_success \
 400        'commitdiff(0): merge commit' \
 401        'gitweb_run "p=.git;a=commitdiff"'
 402test_debug 'cat gitweb.log'
 403test_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'
 429test_expect_success \
 431        'commit(1): large commit' \
 432        'gitweb_run "p=.git;a=commit;h=b"'
 433test_debug 'cat gitweb.log'
 434test_expect_success \
 436        'commitdiff(1): large commit' \
 437        'gitweb_run "p=.git;a=commitdiff;h=b"'
 438test_debug 'cat gitweb.log'
 439# ----------------------------------------------------------------------
 441# tags testing
 442test_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'
 457test_expect_success \
 459        'tag: Tag to commit object' \
 460        'gitweb_run "p=.git;a=tag;h=tag-commit"'
 461test_debug 'cat gitweb.log'
 462test_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# ----------------------------------------------------------------------
 469# logs
 470test_expect_success \
 472        'logs: log (implicit HEAD)' \
 473        'gitweb_run "p=.git;a=log"'
 474test_debug 'cat gitweb.log'
 475test_expect_success \
 477        'logs: shortlog (implicit HEAD)' \
 478        'gitweb_run "p=.git;a=shortlog"'
 479test_debug 'cat gitweb.log'
 480test_expect_success \
 482        'logs: history (implicit HEAD, file)' \
 483        'gitweb_run "p=.git;a=history;f=file"'
 484test_debug 'cat gitweb.log'
 485# ----------------------------------------------------------------------
 487# feed generation
 488test_expect_success \
 490        'feeds: OPML' \
 491        'gitweb_run "a=opml"'
 492test_debug 'cat gitweb.log'
 493test_expect_success \
 495        'feed: RSS' \
 496        'gitweb_run "p=.git;a=rss"'
 497test_debug 'cat gitweb.log'
 498test_expect_success \
 500        'feed: Atom' \
 501        'gitweb_run "p=.git;a=atom"'
 502test_debug 'cat gitweb.log'
 503# ----------------------------------------------------------------------
 505# encoding/decoding
 506test_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'
 515test_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'
 526test_expect_success \
 528        'encode(log): utf-8 and iso-8859-1' \
 529        'gitweb_run "p=.git;a=log"'
 530test_debug 'cat gitweb.log'
 531# ----------------------------------------------------------------------
 533# extra options
 534test_expect_success \
 536        'opt: log --no-merges' \
 537        'gitweb_run "p=.git;a=log;opt=--no-merges"'
 538test_debug 'cat gitweb.log'
 539test_expect_success \
 541        'opt: atom --no-merges' \
 542        'gitweb_run "p=.git;a=log;opt=--no-merges"'
 543test_debug 'cat gitweb.log'
 544test_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'
 549test_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'
 554test_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'
 559test_done