Merge and cleanup
[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;
6 use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
255ee743 7 has gitdir => ( isa => 'Path::Class::Dir', is => 'ro', required => 1 );
941bb5a1 8 has _git => ( isa => NonEmptySimpleStr, is => 'ro', lazy_build => 1 );
9 sub _build__git {
56b6dbe6 10 my $git = File::Which::which('git');
11
12 if (!$git) {
13 die <<EOR;
14Could not find a git executable.
15Please specify the which git executable to use in gitweb.yml
16EOR
17 }
18
19 return $git;
20 }
21
941bb5a1 22 has _gpp => ( isa => 'Git::PurePerl', is => 'rw', lazy_build => 1 );
23 method _build__gpp {
24 my $gpp = Git::PurePerl->new(gitdir => $self->gitdir);
25 return $gpp;
26 }
27
28 method run_cmd (@args) {
29 unshift @args, ( '--git-dir' => $self->gitdir );
30 print STDERR 'RUNNING: ', $self->_git, qq[ @args], $/;
31
32 open my $fh, '-|', $self->_git, @args
33 or die "failed to run git command";
34 binmode $fh, ':encoding(UTF-8)';
35
36 my $output = do { local $/ = undef; <$fh> };
37 close $fh;
38
39 return $output;
40 }
56b6dbe6 41
42
43
44
45
46#
47} # end class