- } else {
- my @tries = ($dir);
- my @chunks = splitdir $dir;
- my $last = pop @chunks;
- push @tries, "$dir.git" unless $last =~ /\.git$/;
- push @tries, catdir($dir, '.git') unless $last eq '.git';
- for (@tries) {
- if (-d $_ && -d "$_/refs" and -d "$_/objects" and -e "$_/HEAD") {
- $repo = $_;
- last;
- }
- }
- return unless defined $repo;
- @chunks = splitdir $repo;
- $last = pop @chunks;
- if ($last eq '.git') {
+ } else {
+ return unless -d $dir
+ and -d "$dir/refs"
+ and -d "$dir/objects"
+ and -e "$dir/HEAD";
+
+ my @chunks = File::Spec->splitdir($dir);
+ my $last = pop @chunks;
+ return unless defined $last;
+
+ if (@chunks and $last eq '.git') {