use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
use DateTime;
use Path::Class;
+ use Gitalist::Git::Util;
has name => ( isa => NonEmptySimpleStr,
is => 'ro' );
is => 'ro',
lazy_build => 1,
);
+ has _util => ( isa => 'Gitalist::Git::Util',
+ is => 'ro',
+ lazy_build => 1,
+ handles => [ 'run_cmd' ],
+ );
+ method _build__util {
+ my $util = Gitalist::Git::Util->new(
+ gitdir => $self->path,
+ );
+ return $util;
+ }
method _build_description {
my $description = $self->path->file('description')->slurp;
return $last_change;
}
-
-=head2 run_cmd
-
-Call out to the C<git> binary and return a string consisting of the output.
-
-=cut
-
- method run_cmd (@args) {
- unshift @args, ( '--git-dir' => $self->path );
- print STDERR 'RUNNING: ', $self->_git, qq[ @args], $/;
-
- open my $fh, '-|', $self->_git, @args
- or die "failed to run git command";
- binmode $fh, ':encoding(UTF-8)';
-
- my $output = do { local $/ = undef; <$fh> };
- close $fh;
-
- return $output;
- }
-
- has _git => ( isa => NonEmptySimpleStr, is => 'ro', lazy_build => 1 );
- use File::Which;
- method _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;
- }
- has _gpp => ( isa => 'Git::PurePerl', is => 'rw', lazy_build => 1 );
- use Git::PurePerl;
- method _build__gpp {
- my $gpp = Git::PurePerl->new(gitdir => $self->path);
- return $gpp;
- }
-
method project_dir (Path::Class::Dir $project) {
my $dir = $project->stringify;
$dir .= '/.git'
return $dir;
}
-
# Compatibility
=head2 project_info
use MooseX::Declare;
class Gitalist::Git::Util {
- has git => ( isa => NonEmptySimpleStr, is => 'ro', lazy_build => 1 );
- sub _build_git {
+ use File::Which;
+ use Git::PurePerl;
+ use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
+ has gitdir => ( isa => "Path::Class::Dir", is => 'ro' );
+ has _git => ( isa => NonEmptySimpleStr, is => 'ro', lazy_build => 1 );
+ sub _build__git {
my $git = File::Which::which('git');
if (!$git) {
return $git;
}
-
+ has _gpp => ( isa => 'Git::PurePerl', is => 'rw', lazy_build => 1 );
+ method _build__gpp {
+ my $gpp = Git::PurePerl->new(gitdir => $self->gitdir);
+ return $gpp;
+ }
+
+ method run_cmd (@args) {
+ unshift @args, ( '--git-dir' => $self->gitdir );
+ print STDERR 'RUNNING: ', $self->_git, qq[ @args], $/;
+
+ open my $fh, '-|', $self->_git, @args
+ or die "failed to run git command";
+ binmode $fh, ':encoding(UTF-8)';
+
+ my $output = do { local $/ = undef; <$fh> };
+ close $fh;
+
+ return $output;
+ }
);
isa_ok($proj, 'Gitalist::Git::Project');
-like( $proj->_git, qr#/git$#, 'git binary found');
-isa_ok($proj->_gpp, 'Git::PurePerl', 'gpp instance created');
like($proj->path, qr#/repositories/repo1#, 'repository path is set');
is($proj->name, qw/repo1/, 'repository name is set');
is($proj->description, qq/some test repository/, 'repository description loaded');
--- /dev/null
+use strict;
+use warnings;
+use FindBin qw/$Bin/;
+use Test::More qw/no_plan/;
+
+use Data::Dumper;
+
+BEGIN { use_ok 'Gitalist::Git::Util' }
+
+use Path::Class;
+my $proj = Gitalist::Git::Util->new(
+ gitdir => dir("$Bin/../lib/repositories/repo1"),
+);
+isa_ok($proj, 'Gitalist::Git::Util');
+
+like( $proj->_git, qr#/git$#, 'git binary found');
+isa_ok($proj->_gpp, 'Git::PurePerl', 'gpp instance created');
+like($proj->gitdir, qr#/repositories/repo1#, 'repository path is set');
+
+
+