3 class Gitalist::Git::Util {
6 use IPC::Run qw(run start);
7 use Symbol qw(geniosym);
8 use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
11 isa => 'Gitalist::Git::Repository',
12 handles => { gitdir => 'path' },
13 is => 'bare', # No accessor
14 weak_ref => 1, # Weak, you have to hold onto me.
15 predicate => 'has_repository',
17 has _git => ( isa => NonEmptySimpleStr, is => 'ro', lazy_build => 1 );
19 my $git = File::Which::which('git');
23 Could not find a git executable.
24 Please specify the which git executable to use in gitweb.yml
32 isa => 'Git::PurePerl', is => 'ro', lazy => 1,
35 confess("Cannot get gpp without repository")
36 unless $self->has_repository;
37 Git::PurePerl->new(gitdir => $self->gitdir);
41 method run_cmd (@args) {
42 unshift @args, ( '--git-dir' => $self->gitdir )
43 if $self->has_repository;
44 # print STDERR 'RUNNING: ', $self->_git, qq[ @args], $/;
45 run [$self->_git, @args], \my($in, $out, $err);
50 method run_cmd_fh (@args) {
51 my ($in, $out, $err) = (geniosym, geniosym, geniosym);
52 unshift @args, ('--git-dir' => $self->gitdir)
53 if $self->has_repository;
54 # print STDERR 'RUNNING: ', $self->_git, qq[ @args], $/;
55 start [$self->_git, @args],
59 or die "cmd returned *?";
63 method run_cmd_list (@args) {
64 my $cmdout = $self->run_cmd(@args);
65 return $cmdout ? split(/\n/, $cmdout) : ();
68 method get_gpp_object (NonEmptySimpleStr $sha1) {
69 return $self->gpp->get_object($sha1) || undef;
78 Gitalist::Git::Util - Class for utilities to run git or deal with Git::PurePerl
86 See L<Gitalist> for authors.
90 See L<Gitalist> for the license.