Stop breaking trees when submodules are encountered
[catagits/Gitalist.git] / lib / Gitalist / Git / Object / HasTree.pm
CommitLineData
0250a92d 1package Gitalist::Git::Object::HasTree;
2use MooseX::Declare;
3
4role Gitalist::Git::Object::HasTree {
5 has tree => ( isa => 'ArrayRef[Gitalist::Git::Object]',
6 required => 0,
7 is => 'ro',
8 lazy_build => 1 );
9
10
11## Builders
12 method _build_tree {
13 my $output = $self->_run_cmd(qw/ls-tree -z/, $self->sha1);
14 return unless defined $output;
15
16 my @ret;
17 for my $line (split /\0/, $output) {
18 my ($mode, $type, $object, $file) = split /\s+/, $line, 4;
b1c8b22c 19 # Ignore commits, these represent submodules
20 next if $type eq 'commit';
0250a92d 21 my $class = 'Gitalist::Git::Object::' . ucfirst($type);
22 push @ret, $class->new( mode => oct $mode,
23 type => $type,
24 sha1 => $object,
25 file => $file,
82bc0f05 26 repository => $self->repository,
0250a92d 27 );
28 }
29 return \@ret;
30 }
31
32}
775e96e0 33
341;
35
36
371;
38
39__END__
40
41=head1 NAME
42
2298d93f 43Gitalist::Git::Object::HasTree - Git::Object::HasTree module for Gitalist
775e96e0 44
c19af0d0 45=head1 SYNOPSIS
46
44a9ed75 47 my $tree = Repository->get_object($tree_sha1);
c19af0d0 48
775e96e0 49=head1 DESCRIPTION
50
c19af0d0 51Role for objects which have a tree - C<Commit> and C<Tree> objects.
52
53
54=head1 ATTRIBUTES
55
56=head2 tree
57
58
59=head1 METHODS
60
775e96e0 61
62=head1 AUTHORS
63
64See L<Gitalist> for authors.
65
66=head1 LICENSE
67
68See L<Gitalist> for the license.
69
70=cut