3 class Gitalist::Git::Repo {
4 use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
5 use MooseX::Types::Path::Class qw/Dir/;
6 use MooseX::Types::Moose qw/ArrayRef/;
7 use aliased 'Gitalist::Git::Project';
18 isa => ArrayRef['Gitalist::Git::Project'],
24 # Make sure repo_dir is an absolute path so that
25 # ->contains() works correctly.
26 $self->repo_dir->resolve;
30 method get_project (NonEmptySimpleStr $name) {
31 my $path = $self->repo_dir->subdir($name)->resolve;
32 die "Directory traversal prohibited"
33 unless $self->repo_dir->contains($path);
34 die "Not a valid Project"
35 unless $self->_is_git_repo($path);
36 return Project->new( $path );
40 method _build_projects {
41 my $dh = $self->repo_dir->open || die "Could not open repo_dir";
43 while (my $dir_entry = $dh->read) {
44 # try to get a project for each entry in repo_dir
46 my $p = $self->get_project($dir_entry);
51 return [sort { $a->name cmp $b->name } @ret];
55 # Determine whether a given directory is a git repo.
56 method _is_git_repo ($dir) {
57 return -f $dir->file('HEAD') || -f $dir->file('.git', 'HEAD');
65 Gitalist::Git::Repo - Model of a repository directory
69 my $repo = Gitalist::Git::Repo->new( repo_dir => $Dir );
70 my $project_list = $repo->projects;
71 my $first_project = @$project_list[0];
72 my $named_project = $repo->get_project('Gitalist');
76 This class models a Gitalist Repo, which is a collection of
77 Projects (git repositories). It is used for creating Project
83 =head2 repo_dir (C<Path::Class::Dir>)
85 The filesystem root of the Repo.
89 An array of all Repos found in C<repo_dir>.
95 =head2 get_project (Str $name)
97 Returns a L<Gitalist::Git::Project> for the specified project
103 L<Gitalist::Git::Project>
108 See L<Gitalist> for authors.
112 See L<Gitalist> for the license.