Fix legacy tests - atom action is no longer TODO.
[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
defb0050 30 has gpp => (
84f31a44 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;
32a371cc 43# print STDERR 'RUNNING: ', $self->_git, qq[ @args], $/;
839da3d7 44 run [$self->_git, @args], \my($in, $out, $err);
941bb5a1 45
839da3d7 46 return $out;
941bb5a1 47 }
4111e151 48
32a371cc 49 method run_cmd_list (@args) {
50 my $cmdout = $self->run_cmd(@args);
51 return $cmdout ? split(/\n/, $cmdout) : ();
52 }
53
4111e151 54 method get_gpp_object (NonEmptySimpleStr $sha1) {
defb0050 55 return $self->gpp->get_object($sha1) || undef;
4111e151 56 }
57
56b6dbe6 58} # end class