]> git.vpit.fr Git - perl/modules/rgit.git/blobdiff - lib/App/Rgit/Config.pm
Make App::Rgit::Config->new discover the git executable itself
[perl/modules/rgit.git] / lib / App / Rgit / Config.pm
index 0442966b805d058f8bb7b27c639c228cbb0c5d12..94a3359ff98767303214c7a5e1a8a25afb0cbd8e 100644 (file)
@@ -5,7 +5,7 @@ use warnings;
 
 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/;
@@ -48,16 +48,28 @@ sub new {
  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';