Gitalist::Git::Object.
--- /dev/null
+use MooseX::Declare;
+
+class Gitalist::Git::Object {
+ use File::Stat::ModeString qw/mode_to_string/;
+
+ has sha1 => ( isa => 'Str',
+ is => 'ro' );
+ has type => ( isa => 'Str',
+ is => 'ro' );
+ has file => ( isa => 'Str',
+ is => 'ro' );
+ has mode => ( isa => 'Int',
+ is => 'ro' );
+ has modestr => ( isa => 'Str',
+ is => 'ro',
+ lazy_build => 1,
+ );
+
+ method _build_modestr {
+ my $modestr = mode_to_string($self->{mode});
+ return $modestr;
+ }
+
+
+
+} # end class
use DateTime;
use Path::Class;
use Gitalist::Git::Util;
+ use aliased 'Gitalist::Git::Object';
our $SHA1RE = qr/[0-9a-fA-F]{40}/;
return $sha1;
}
+=head2 list_tree
+
+Return an array of contents for a given tree.
+The tree is specified by sha1, and defaults to HEAD.
+The keys for each item will be:
+
+ mode
+ type
+ object
+ file
+
+=cut
+
+ method list_tree (Str $sha1?) {
+ $sha1 ||= $self->head_hash;
+
+ my $output = $self->run_cmd(qw/ls-tree -z/, $sha1);
+ return unless defined $output;
+
+ my @ret;
+ for my $line (split /\0/, $output) {
+ my ($mode, $type, $object, $file) = split /\s+/, $line, 4;
+ push @ret, Object->new( mode => oct $mode,
+ type => $type,
+ sha1 => $object,
+ file => $file,
+ );
+ }
+ return @ret;
+ }
+
+
method project_dir (Path::Class::Dir $project) {
my $dir = $project->stringify;
$dir .= '/.git'
--- /dev/null
+use strict;
+use warnings;
+use FindBin qw/$Bin/;
+use Test::More qw/no_plan/;
+
+use Data::Dumper;
+
+BEGIN { use_ok 'Gitalist::Git::Object' }
+
+my $object = Gitalist::Git::Object->new(
+ sha1 => '729a7c3f6ba5453b42d16a43692205f67fb23bc1',
+ type => 'tree',
+ file => 'dir1',
+ mode => 16384,
+);
+isa_ok($object, 'Gitalist::Git::Object');
+
+warn( Dumper($object) );
+is($object->{sha1},'729a7c3f6ba5453b42d16a43692205f67fb23bc1', 'sha1 is correct');
+is($object->{type}, 'tree', 'type is correct');
+is($object->{file}, 'dir1', 'file is correct');
+is($object->mode, 16384, 'mode is correct');
+is($object->modestr, 'd---------', "modestr is correct" );
+
isa_ok($proj->last_change, 'DateTime', 'last_change');
is($proj->head_hash, qw/36c6c6708b8360d7023e8a1649c45bcf9b3bd818/, 'head_hash for HEAD is correct');
+
+is(scalar $proj->list_tree, 2, 'expected number of entries in tree');
+isa_ok(($proj->list_tree)[0], 'Gitalist::Git::Object');
+warn( Dumper($proj->list_tree) );