3 class Gitalist::Git::Repo {
4 use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
6 use Gitalist::Git::Project;
7 has repo_dir => ( isa => NonEmptySimpleStr,
11 method project (NonEmptySimpleStr $project) {
12 my $pd = $self->dir_from_project_name($project);
13 return Gitalist::Git::Project->new(
22 Determine whether a given directory (as a L<Path::Class::Dir> object) is a
27 method _is_git_repo ($dir) {
28 return -f $dir->file('HEAD') || -f $dir->file('.git/HEAD');
33 The directory under which the given project will reside i.e C<.git/..>
37 method project_dir ($project) {
38 my $dir = blessed($project) && $project->isa('Path::Class::Dir')
40 : $self->dir_from_project_name($project);
43 if -f dir($dir)->file('.git/HEAD');
50 For the C<repo_dir> specified in the config return an array of projects where
51 each item will contain the contents of L</project_info>.
55 method list_projects {
56 my $base = dir($self->repo_dir);
58 my $dh = $base->open || die "Could not open $base";
59 while (my $file = $dh->read) {
60 next if $file =~ /^.{1,2}$/;
62 my $obj = $base->subdir($file);
64 next unless $self->_is_git_repo($obj);
66 # XXX Leaky abstraction alert!
67 my $is_bare = !-d $obj->subdir('.git');
69 my $name = (File::Spec->splitdir($obj))[-1];
70 push @ret, Gitalist::Git::Project->new( name => $name,
75 return [sort { $a->{name} cmp $b->{name} } @ret];
78 =head2 dir_from_project_name
80 Get the corresponding directory of a given project.
84 method dir_from_project_name (Str $project) {
85 return dir($self->repo_dir)->subdir($project);