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';