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 -f $project->file('.git', 'HEAD')
39 ? $project->subdir('.git')
45 For the C<repo_dir> specified in the config return an array of projects where
46 each item will contain the contents of L</project_info>.
50 method list_projects {
51 my $base = dir($self->repo_dir);
53 my $dh = $base->open || die "Could not open $base";
54 while (my $file = $dh->read) {
55 next if $file =~ /^.{1,2}$/;
57 my $obj = $base->subdir($file);
59 next unless $self->_is_git_repo($obj);
61 # FIXME - Is resolving project_dir here sane?
62 # I think not, just pass $obj down, and
63 # resolve $project->path and $project->is_bare
65 push @ret, Gitalist::Git::Project->new( name => $file,
66 path => $self->project_dir($obj),
70 return [sort { $a->{name} cmp $b->{name} } @ret];
73 =head2 dir_from_project_name
75 Get the corresponding directory of a given project.
79 method dir_from_project_name (Str $project) {
80 return dir($self->repo_dir)->subdir($project);