]> 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 7a247eb7dc67357b73d018a3c884eeb12ba5a5fa..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';
@@ -134,7 +146,8 @@ You can contact me by mail or on C<irc.perl.org> (vincent).
 
 =head1 BUGS
 
-Please report any bugs or feature requests to C<bug-rgit at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=rgit>.  I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
+Please report any bugs or feature requests to C<bug-rgit at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=rgit>.
+I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
 
 =head1 SUPPORT