- $root = abs_path $root unless file_name_is_absolute $root;
- return unless defined $args{git} and -x $args{git};
+ $root = File::Spec->canonpath(Cwd::abs_path($root));
+
+ 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) {
+ my @acc;
+ for my $c (@candidates) {
+ push @acc, $c, map "$c.$_", qw/exe com bat cmd/;
+ }
+ @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));
+