use strict;
use warnings;
-use Carp qw/croak/;
-use Config qw/%Config/;
-use Cwd qw/cwd/;
-use File::Spec (); # catfile, path
+use Carp qw/croak/;
+use Config qw/%Config/;
+use Cwd qw/cwd/;
use App::Rgit;
use App::Rgit::Utils qw/:levels/;
setpgrp 0, 0 if $Config{d_setpgrp};
-my $git = $ENV{GIT_EXEC_PATH};
-unless (defined $git) {
- for (File::Spec->path) {
- my $g = File::Spec->catfile($_, 'git');
- if (-x $g) {
- $git = $g;
- last;
- }
- }
-}
-croak "Couldn't find any valid git executable" unless defined $git;
-
my $root = $ENV{GIT_DIR};
$root = cwd unless defined $root;
my $ar = App::Rgit->new(
- git => $git,
+ git => undef, # Autodiscovery
root => $root,
cmd => $cmd,
args => \@ARGV,
use Carp (); # confess
use Cwd (); # abs_path
-use File::Spec (); # canonpath
+use File::Spec (); # canonpath, catfile, path
use App::Rgit::Repository;
use App::Rgit::Utils qw/:levels/;
return unless defined $root and -d $root;
$root = File::Spec->canonpath(Cwd::abs_path($root));
- my $git = $args{git};
- return unless defined $git;
+ my $git;
+ my @candidates = (
+ defined $args{git}
+ ? $args{git}
+ : defined $ENV{GIT_EXEC_PATH}
+ ? $ENV{GIT_EXEC_PATH}
+ : map File::Spec->catfile($_, 'git'), File::Spec->path
+ );
if (IS_WIN32) {
- unless (-x $git) {
- $git .= '.bat';
- return unless -x $git;
+ my @acc;
+ for my $c (@candidates) {
+ push @acc, $c, map "$c.$_", qw/exe com bat cmd/;
}
- } else {
- return unless -x $git;
+ @candidates = @acc;
}
+ for my $c (@candidates) {
+ if (-x $c) {
+ $git = $c;
+ last;
+ }
+ }
+ Carp::confess("Couldn't find a proper git executable") unless defined $git;
$git = File::Spec->canonpath(Cwd::abs_path($git));
my $conf = 'App::Rgit::Config::Default';
use Cwd (); # cwd
use File::Spec (); # catdir
-use Test::More tests => 42;
+use Test::More tests => 43;
use App::Rgit;
is $res, undef, 'App::Rgit->new(): wrong root: returns undef';
$res = eval {
+ local $ENV{GIT_EXEC_PATH};
+ local $ENV{PATH} = 't/bin';
App::Rgit->new(
root => 't',
);
};
-is $@, '', "App::Rgit->new(): no git: doesn't croak";
-is $res, undef, 'App::Rgit->new(): no git: returns undef';
+is $@, '', "App::Rgit->new(): no git, no GIT_EXEC_PATH: doesn't croak";
+isa_ok $res, 'App::Rgit',
+ 'App::Rgit->new(): no git, no GIT_EXEC_PATH: returns object';
+
+$res = eval {
+ local $ENV{GIT_EXEC_PATH} = 't/bin/git';
+ App::Rgit->new(
+ root => 't',
+ );
+};
+is $@, '', "App::Rgit->new(): no git: doesn't croak";
+isa_ok $res, 'App::Rgit', 'App::Rgit->new(): no git: returns object';
$res = eval {
App::Rgit->new(
git => $0,
);
};
-is $@, '', "App::Rgit->new(): wrong git: doesn't croak";
-is $res, undef, 'App::Rgit->new(): wrong git: returns undef';
+like $@, qr/Couldn't find a proper git executable/,
+ 'App::Rgit->new(): wrong git: croaks';
$res = eval {
App::Rgit->new(