The list of projects is now in working order, but nothing else.
[catagits/Gitalist.git] / lib / Gitalist / Model / Git.pm
index 9b0babc..902b331 100644 (file)
@@ -3,7 +3,8 @@ package Gitalist::Model::Git;
 use Moose;
 use namespace::autoclean;
 
-use Gitalist;
+BEGIN { extends 'Catalyst::Model' }
+
 use DateTime;
 use Path::Class;
 use Carp qw/croak/;
@@ -13,14 +14,11 @@ use File::Stat::ModeString;
 use List::MoreUtils qw/any/;
 use Scalar::Util qw/blessed/;
 
-BEGIN { extends 'Catalyst::Model' }
-
-has git => (
-       is      => 'ro',
-       isa     => 'Str',
-       lazy    => 1,
-       default => sub {
-               my $git;
+{
+       my $git;
+       sub git {
+               return $git
+                       if $git;
 
                if (my $config_git = Gitalist->config->{git}) {
                        $git = $config_git if -x $config_git;
@@ -38,14 +36,13 @@ EOR
                }
 
                return $git;
-       },
-);
+       }
+}
 
 sub is_git_repo {
     my ($self, $dir) = @_;
 
-    #FIXME: Only handles bare repos. Is that enough?
-    return -f $dir->file('HEAD');
+    return -f $dir->file('HEAD') || -f $dir->file('.git/HEAD');
 }
 
 sub project_info {
@@ -68,7 +65,7 @@ sub get_project_properties {
         chomp $props{description};
     };
 
-    if ($props{description} =~ /^Unnamed repository;/) {
+    if ($props{description} && $props{description} =~ /^Unnamed repository;/) {
         delete $props{description};
     }
 
@@ -101,9 +98,12 @@ sub list_projects {
         my $obj = $base->subdir($file);
         next unless -d $obj;
         next unless $self->is_git_repo($obj);
+               # XXX Leaky abstraction alert!
+               $obj = $obj->subdir('.git')
+                       if -d $obj->subdir('.git');
 
         push @ret, {
-            name => ($obj->dir_list)[-1],
+            name => (File::Spec->splitdir($base->subdir($file)))[-1],
             $self->get_project_properties($obj),
         };
     }