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 _build_repo_dir {
12 return Gitalist->config->{repo_dir};
17 Determine whether a given directory (as a L<Path::Class::Dir> object) is a
22 method _is_git_repo ($dir) {
23 return -f $dir->file('HEAD') || -f $dir->file('.git/HEAD');
28 The directory under which the given project will reside i.e C<.git/..>
32 method project_dir ($project) {
33 my $dir = blessed($project) && $project->isa('Path::Class::Dir')
35 : $self->dir_from_project_name($project);
38 if -f dir($dir)->file('.git/HEAD');
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 # XXX Leaky abstraction alert!
62 my $is_bare = !-d $obj->subdir('.git');
64 my $name = (File::Spec->splitdir($obj))[-1];
65 push @ret, Gitalist::Git::Project->new( name => $name,
69 # name => ($name . ( $is_bare ? '' : '/.git' )),
70 # $self->get_project_properties(
71 # $is_bare ? $obj : $obj->subdir('.git')
76 return [sort { $a->{name} cmp $b->{name} } @ret];
79 =head2 dir_from_project_name
81 Get the corresponding directory of a given project.
85 method dir_from_project_name (Str $project) {
86 return dir($self->repo_dir)->subdir($project);