requires 'namespace::autoclean';
requires 'Config::General'; # This should reflect the config file format you've chosen
# See Catalyst::Plugin::ConfigLoader for supported formats
+requires 'MooseX::Types::Common';
catalyst;
requires 'File::Find::Rule';
requires 'File::Stat::ModeString';
requires 'File::Slurp';
requires 'DateTime::Format::Mail';
requires 'IO::Capture::Stdout';
+requires 'File::Which';
install_script glob('script/*.pl');
auto_install;
# Bring in the libified gitweb.cgi.
use gitweb;
-# Load the testing config if we're invoked under test
-if ($ENV{APP_TEST} ) {
- __PACKAGE__->config( 'Plugin::ConfigLoader' =>
- { file => __PACKAGE__->path_to
- ('t/lib/gitalist_testing.conf')}
- );
-}
+before 'setup' => sub {
+ my $app = shift;
+ $app->config('Model::Git' => { repo_dir => $app->config('repo_dir') });
+};
+
__PACKAGE__->config(
name => 'Gitalist',
default_view => 'Default',
package Gitalist::Model::Git;
use Moose;
+use MooseX::Types::Common::String qw/NonEmptySimpleStr/; # FIXME, use Types::Path::Class and coerce
use namespace::autoclean;
BEGIN { extends 'Catalyst::Model' }
use DateTime::Format::Mail;
use File::Stat::ModeString;
use List::MoreUtils qw/any/;
-use Scalar::Util qw/blessed/;
+use File::Which;
-# abstraction fail - but currently needed for unit tests to work
-use Gitalist;
+sub BUILD {
+ my ($self) = @_;
+ $self->git; # Cause lazy value build.
+}
-{
- my $git;
- sub git {
- return $git
- if $git;
-
- if (my $config_git = Gitalist->config->{git}) {
- $git = $config_git if -x $config_git;
- }
- else {
- require File::Which;
- $git = File::Which::which('git');
- }
-
- if (!$git) {
- die <<EOR
+has git => ( isa => NonEmptySimpleStr, is => 'ro', lazy_build => 1 );
+
+sub _build_git {
+ my $git = File::Which::which('git');
+
+ if (!$git) {
+ die <<EOR
Could not find a git executable.
Please specify the which git executable to use in gitweb.yml
EOR
- }
-
- return $git;
}
+
+ return $git;
}
sub is_git_repo {
return %props;
}
+has repo_dir => ( isa => NonEmptySimpleStr, required => 1, is => 'ro' ); # Fixme - path::class
+
sub list_projects {
my ($self) = @_;
- my $base = dir(Gitalist->config->{repo_dir});
+ my $base = dir($self->repo_dir);
my @ret;
my $dh = $base->open;
sub run_cmd {
my ($self, @args) = @_;
- open my $fh, '-|', __PACKAGE__->git, @args
+ open my $fh, '-|', $self->git, @args
or die "failed to run git command";
binmode $fh, ':encoding(UTF-8)';
sub git_dir_from_project_name {
my ($self, $project) = @_;
- return dir(Gitalist->config->{repo_dir})->subdir($project);
+ return dir($self->repo_dir)->subdir($project);
}
sub get_head_hash {
use strict;
use warnings;
+use FindBin qw/$Bin/;
use Test::More qw/no_plan/;
BEGIN { use_ok 'Gitalist::Model::Git' }
-my $Git = Gitalist::Model::Git->new;
+my $c = bless {}, 'Gitalist';
+my $Git = Gitalist::Model::Git->new($c, { repo_dir => "$Bin/lib/repositories" });
# 'bare.git' is a bare git repository in the repository dir
use Path::Class;
my $repoEmpty = Path::Class::Dir->new('t/lib/repositories/empty.git');
ok( ! $Git->is_git_repo( $repoEmpty ), 'is_git_repo is false for empty dir' );
-# At present, these tests only work 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",
- 2 if !$ENV{APP_TEST};
-
my $projectList = $Git->list_projects;
ok( scalar @{$projectList} == 1, 'list_projects returns an array with the correct number of members' );
ok( $projectList->[0]->{name} eq 'bare.git', 'list_projects has correct name for "bare.git" repo' );
#ok( $projectList->[1]->{name} eq 'working/.git', 'list_projects has correct name for "working" repo' );
use Data::Dumper;
-warn( Dumper($projectList) );
+#warn( Dumper($projectList) );
-} # Close APP_TEST skip