Allow top-level directories in the Repo constructor.
Dan Brook [Tue, 11 Jan 2011 22:07:38 +0000 (17:07 -0500)]
The problem being that the constructor couldn't handle paths like foo/repo
which is what CollectionOfRepositories considers (rightly) a repo path.

lib/Gitalist/Git/Repository.pm

index 328e10a..571656e 100644 (file)
@@ -25,7 +25,12 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
         # Last path component becomes $self->name
         # Full path to git objects becomes $self->path
         my $name = $dir->dir_list(-1);
-        $dir = $dir->subdir('.git') if (-f $dir->file('.git', 'HEAD'));
+       if(-f $dir->file('.git', 'HEAD')) { # Non-bare repo above .git
+           $dir  = $dir->subdir('.git');
+           $name = $dir->dir_list(-2, 1); # .../name/.git
+       } elsif('.git' eq $dir->dir_list(-1)) { # Non-bare repo in .git
+           $name = $dir->dir_list(-2);
+       }
         confess("Can't find a git repository at " . $dir)
             unless ( -f $dir->file('HEAD') );
         return $class->$orig(name => $name,