Commit | Line | Data |
7e7f9335 |
1 | use MooseX::Declare; |
2 | |
38b9e5c8 |
3 | class Gitalist::Git::Repo with Gitalist::Git::HasUtils { |
7e7f9335 |
4 | use MooseX::Types::Common::String qw/NonEmptySimpleStr/; |
84f31a44 |
5 | use MooseX::Types::Path::Class qw/Dir/; |
6 | use MooseX::Types::Moose qw/ArrayRef/; |
38b9e5c8 |
7 | use aliased 'Gitalist::Git::Project'; |
8 | |
9 | # FIXME - this is nasty as we build the Git::Utils thing without a project name |
10 | # should refactor or something? |
11 | method _build__util { |
12 | Gitalist::Git::Util->new(); |
13 | } |
14 | |
84f31a44 |
15 | has repo_dir => ( |
16 | isa => Dir, |
17 | is => 'ro', |
18 | required => 1, |
19 | coerce => 1, |
20 | ); |
7e7f9335 |
21 | |
ba033c36 |
22 | method project (NonEmptySimpleStr $project) { |
38b9e5c8 |
23 | return Project->new( |
ba033c36 |
24 | name => $project, |
3742082a |
25 | path => $self->repo_dir->subdir($project), |
ba033c36 |
26 | ); |
27 | } |
28 | |
29 | |
7e7f9335 |
30 | =head2 _is_git_repo |
31 | |
32 | Determine whether a given directory (as a L<Path::Class::Dir> object) is a |
33 | C<git> repo. |
34 | |
35 | =cut |
36 | |
37 | method _is_git_repo ($dir) { |
255ee743 |
38 | return -f $dir->file('HEAD') || -f $dir->file('.git', 'HEAD'); |
7e7f9335 |
39 | } |
40 | |
7e7f9335 |
41 | =head2 list_projects |
42 | |
43 | For the C<repo_dir> specified in the config return an array of projects where |
44 | each item will contain the contents of L</project_info>. |
45 | |
46 | =cut |
47 | |
84f31a44 |
48 | has projects => ( |
49 | isa => ArrayRef['Gitalist::Git::Project'], |
50 | reader => 'list_projects', |
51 | lazy_build => 1, |
52 | ); |
53 | |
54 | method _build_projects { |
55 | my $base = $self->repo_dir; |
7e7f9335 |
56 | my $dh = $base->open || die "Could not open $base"; |
84f31a44 |
57 | my @ret; |
7e7f9335 |
58 | while (my $file = $dh->read) { |
59 | next if $file =~ /^.{1,2}$/; |
60 | |
61 | my $obj = $base->subdir($file); |
62 | next unless -d $obj; |
63 | next unless $self->_is_git_repo($obj); |
64 | |
38b9e5c8 |
65 | push @ret, $self->project($file); |
7e7f9335 |
66 | } |
67 | |
84f31a44 |
68 | return [sort { $a->name cmp $b->name } @ret]; |
7e7f9335 |
69 | } |
7e7f9335 |
70 | } # end class |