use strict;
use warnings;
-use Cwd qw/cwd abs_path/;
-use File::Spec::Functions qw/canonpath catdir splitdir abs2rel/;
-use POSIX qw/WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG SIGINT SIGQUIT/;
+use Cwd (); # cwd, abs_path
+use File::Spec (); # canonpath, catdir, splitdir, abs2rel
+use POSIX qw/WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG SIGINT SIGQUIT/;
BEGIN {
no warnings 'redefine';
my $dir = $args{dir};
if (defined $dir) {
- $dir = abs_path $dir;
+ $dir = Cwd::abs_path($dir);
} else {
- $dir = cwd;
+ $dir = Cwd::cwd;
}
- $dir = canonpath $dir;
+ $dir = File::Spec->canonpath($dir);
my ($repo, $bare, $name, $work);
if ($args{fake}) {
and -d "$dir/objects"
and -e "$dir/HEAD";
- my @chunks = splitdir $dir;
+ my @chunks = File::Spec->splitdir($dir);
my $last = pop @chunks;
return unless defined $last;
- if ($last eq '.git') {
+ if (@chunks and $last eq '.git') {
$bare = 0;
$name = $chunks[-1];
- $work = catdir @chunks;
+ $work = File::Spec->catdir(@chunks);
} elsif ($last =~ /(.+)\.git$/) {
$bare = 1;
$name = $1;
- $work = catdir @chunks, $last;
+ $work = File::Spec->catdir(@chunks, $last);
} else {
return;
}
=cut
-sub _abs2rel {
- my $a = &abs2rel;
+my $abs2rel = sub {
+ my $a = File::Spec->abs2rel(@_);
$a = $_[0] unless defined $a;
$a;
-}
+};
my %escapes = (
'%' => sub { '%' },
'n' => sub { shift->name },
- 'g' => sub { _abs2rel(shift->repo, shift->root) },
+ 'g' => sub { $abs2rel->(shift->repo, shift->root) },
'G' => sub { shift->repo },
- 'w' => sub { _abs2rel(shift->work, shift->root) },
+ 'w' => sub { $abs2rel->(shift->work, shift->root) },
'W' => sub { shift->work },
'b' => sub {
my ($self, $conf) = @_;
- _abs2rel($self->bare ? $self->repo : $self->work . '.git', $conf->root)
+ $abs2rel->(
+ $self->bare ? $self->repo : $self->work . '.git',
+ $conf->root
+ );
},
'B' => sub { $_[0]->bare ? $_[0]->repo : $_[0]->work . '.git' },
'R' => sub { $_[1]->root },
my $self = shift;
my $conf = shift;
return unless $conf->isa('App::Rgit::Config');
+
my @args = @_;
+
unless ($self->fake) {
s/%($e)/$escapes{$1}->($self, $conf)/eg for @args;
}
+
unshift @args, $conf->git;
$conf->info('Executing "', join(' ', @args), '" into ', $self->work, "\n");
+
{
local $ENV{GIT_DIR} = $self->repo if exists $ENV{GIT_DIR};
local $ENV{GIT_EXEC_PATH} = $conf->git if exists $ENV{GIT_EXEC_PATH};
system { $args[0] } @args;
}
+
if ($? == -1) {
$conf->crit("Failed to execute git: $!\n");
return;
}
+
my $ret;
$ret = WEXITSTATUS($?) if WIFEXITED($?);
my $sig;
} elsif ($ret) {
$conf->info("git returned $ret\n");
}
+
return wantarray ? ($ret, $sig) : $ret;
}