=cut
sub index :Path :Args(0) {
- my ( $self, $c ) = @_;
- $c->stash(current_model => 'GitRepos');
- # Leave actions up to gitweb at this point.
- return $self->run_gitweb($c)
- if $c->req->param('a');
-
- my $list = $c->model()->list_projects;
- unless(@$list) {
- die "No projects found in ". $c->model->repo_dir;
- }
-
- $c->stash(
- searchtext => $c->req->param('searchtext') || '',
- projects => $list,
- action => 'index',
- );
+ my ( $self, $c ) = @_;
+ $c->detach($c->req->param('a')) if $c->req->param('a');
+ $c->stash(current_model => 'GitRepos');
+
+ my $list = $c->model()->list_projects;
+ unless(@$list) {
+ die "No projects found in ". $c->model->repo_dir;
+ }
+
+ $c->stash(
+ searchtext => $c->req->param('searchtext') || '',
+ projects => $list,
+ action => 'index',
+ );
}
=head2 summary
sub summary : Local {
my ( $self, $c ) = @_;
-
+ $c->stash(current_model => 'GitRepos');
+ warn("project is " . $c->stash->{project});
+ my $project;
+ eval {
+ $project = $c->model()->project($c->stash->{project});
+ };
+ if ($@) {
+ $c->detach('error_404');
+ }
my $commit = $self->_get_commit($c);
$c->stash(
commit => $commit,
- info => $c->model()->project_info($c->model()->project),
- log_lines => [$c->model()->list_revs(
- sha1 => $commit->sha1, count => Gitalist->config->{paging}{summary}
+ info => $project->info,
+ log_lines => [$project->list_revs(
+ sha1 => $commit->sha1,
+ count => Gitalist->config->{paging}{summary} || 50
)],
- refs => $c->model()->references,
- heads => [$c->model()->heads],
+ refs => $project->references,
+ heads => [$project->heads],
action => 'summary',
- );
+);
}
=head2 heads
}
}
+sub error_404 :Private {
+ my ($self, $c) = @_;
+ $c->response->status(404);
+ $c->stash(
+ title => 'Page not found',
+ content => 'Page not found',
+ )
+}
+
sub age_string {
my $age = shift;
my $age_str;
#!/usr/bin/env perl
use strict;
use warnings;
-use Test::More qw/no_plan/;
+use Test::More;
+use FindBin qw/$Bin/;
-BEGIN { use_ok 'Catalyst::Test', 'Gitalist' }
-
-# Full tests are only run if the APP_TEST env var is set.
-# This is needed to load the test configuration.
-diag("*** SKIPPING app tests.
-*** Set APP_TEST for the tests to run fully") if !$ENV{APP_TEST};
-SKIP: {
- skip "Set APP_TEST for the tests to run fully",
- 1 if !$ENV{APP_TEST};
+BEGIN {
+ $ENV{GITALIST_CONFIG} = $Bin;
+ use_ok 'Catalyst::Test', 'Gitalist'
+}
- ok( request('/')->is_success, 'Request should succeed' );
+ok( request('/')->is_success, 'Request should succeed' );
+for my $p (qw/ repo1 nodescription /) {
+ my $path = '/summary?p=' . $p;
+ ok( request($path)->is_success, "$path should succeed");
+}
+is request('/summary?p=DoesNotExist')->code, 404,
+ '/summary?p=DoesNotExist 404s';
+{
# URI tests for repo1
- use Data::Dumper;
- my $test_repo1 = curry_test_uri('repo1');
- &$test_repo1('/summary');
- &$test_repo1('/heads');
- &$test_repo1('/shortlog');
- &$test_repo1('/log');
- &$test_repo1('/commit');
- &$test_repo1('/commitdiff');
- &$test_repo1('/tree');
+ local *test = curry_test_uri('repo1');
+ test('/summary');
+ test('/shortlog');
+ test('/log');
+ test('/commit');
+ test('/commitdiff', 'h=36c6c6708b8360d7023e8a1649c45bcf9b3bd818');
+ test('/tree', 'h=145dc3ef5d307be84cb9b325d70bd08aeed0eceb;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818');
+
+ # legacy URIs
- &$test_repo1('/', 'a=summary');
- &$test_repo1('/', 'a=heads');
- &$test_repo1('/', 'a=shortlog');
- &$test_repo1('/', 'a=log');
- &$test_repo1('/', 'a=commit');
- &$test_repo1('/', 'a=commitdiff');
- &$test_repo1('/', 'a=tree');
-# &$test_repo1('/', 'a=blob;f=file1');
-
-} # Close APP_TEST skip
++ test('/', 'a=summary');
++ test('/', 'a=heads');
++ test('/', 'a=shortlog');
++ test('/', 'a=log');
++ test('/', 'a=commit');
++ test('/', 'a=commitdiff');
++ test('/', 'a=tree');
+# $test_repo1->('/', 'a=blob;f=file1');
+}
+
+done_testing;
sub test_uri {
my ($p, $uri, $qs) = @_;
sub curry_test_uri {
my $p = shift;
sub {
- my $uri = shift;
- test_uri($p, $uri);
+ my ($uri, $qs) = @_;
+ test_uri($p, $uri, $qs);
};
};