Add a branch to the test repository.
[catagits/Gitalist.git] / lib / Gitalist / Git / Util.pm
CommitLineData
56b6dbe6 1use MooseX::Declare;
2
3class Gitalist::Git::Util {
941bb5a1 4 use File::Which;
5 use Git::PurePerl;
839da3d7 6 use IPC::Run qw(run);
941bb5a1 7 use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
839da3d7 8
84f31a44 9 has project => (
10 isa => 'Gitalist::Git::Project',
b5b638f7 11 handles => { gitdir => 'path' },
84f31a44 12 is => 'bare', # No accessor
13 weak_ref => 1, # Weak, you have to hold onto me.
38b9e5c8 14 predicate => 'has_project',
84f31a44 15 );
941bb5a1 16 has _git => ( isa => NonEmptySimpleStr, is => 'ro', lazy_build => 1 );
17 sub _build__git {
56b6dbe6 18 my $git = File::Which::which('git');
19
20 if (!$git) {
21 die <<EOR;
22Could not find a git executable.
23Please specify the which git executable to use in gitweb.yml
24EOR
25 }
26
27 return $git;
28 }
29
84f31a44 30 has _gpp => (
31 isa => 'Git::PurePerl', is => 'ro', lazy => 1,
38b9e5c8 32 default => sub {
33 my $self = shift;
34 confess("Cannot get gpp without project")
35 unless $self->has_project;
36 Git::PurePerl->new(gitdir => $self->gitdir);
37 },
84f31a44 38 );
941bb5a1 39
40 method run_cmd (@args) {
38b9e5c8 41 unshift @args, ( '--git-dir' => $self->gitdir )
42 if $self->has_project;
941bb5a1 43
839da3d7 44 run [$self->_git, @args], \my($in, $out, $err);
941bb5a1 45
839da3d7 46 return $out;
941bb5a1 47 }
4111e151 48
49 method get_gpp_object (NonEmptySimpleStr $sha1) {
50 return $self->_gpp->get_object($sha1) || undef;
51 }
52
56b6dbe6 53} # end class