5 Gitalist::Git::Repo - Model of a repository directory
9 my $repo = Gitalist::Git::Repo->new( repo_dir => $Dir );
10 my $project_list = $repo->projects;
11 my $first_project = @$project_list[0];
12 my $named_project = $repo->project('Gitalist');
16 This class models a Gitalist Repo, which is a collection of
17 Projects (git repositories). It is used for creating Project
23 class Gitalist::Git::Repo {
24 use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
25 use MooseX::Types::Path::Class qw/Dir/;
26 use MooseX::Types::Moose qw/ArrayRef/;
27 use aliased 'Gitalist::Git::Project';
33 L<Path::Class::Dir> for the root of the Repo.
46 An array of L<Gitalist::Git::Project> for each valid git repo
53 isa => ArrayRef['Gitalist::Git::Project'],
63 Returns a L<Gitalist::Git::Project> for the specified project
68 method project (NonEmptySimpleStr $project) {
69 my $path = $self->repo_dir->subdir($project);
70 die "Not a valid Project" unless $self->_is_git_repo($path);
71 return Project->new( $self->repo_dir->subdir($project) );
75 method _build_projects {
76 my $base = $self->repo_dir;
77 my $dh = $base->open || die "Could not open $base";
79 while (my $file = $dh->read) {
80 next if $file =~ /^.{1,2}$/;
82 my $obj = $base->subdir($file);
84 next unless $self->_is_git_repo($obj);
86 push @ret, $self->project($file);
89 return [sort { $a->name cmp $b->name } @ret];
92 # Determine whether a given directory is a git repo.
93 method _is_git_repo ($dir) {
94 return -f $dir->file('HEAD') || -f $dir->file('.git', 'HEAD');
102 L<Gitalist::Git::Project>
106 See L<Gitalist> for authors.
110 See L<Gitalist> for the license.