X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FGitalist%2FGit%2FRepository.pm;h=7e873cd27b828203e20d5a0b8c82693458b33813;hb=03686cdc7927a63853a4399c04e8c9cd1fa68014;hp=4aee01eb32199ef198593134e072351d2915ccc4;hpb=87581f054e0fa1c46688ffce55aedd21cd6e7530;p=catagits%2FGitalist.git diff --git a/lib/Gitalist/Git/Repository.pm b/lib/Gitalist/Git/Repository.pm index 4aee01e..7e873cd 100644 --- a/lib/Gitalist/Git/Repository.pm +++ b/lib/Gitalist/Git/Repository.pm @@ -6,6 +6,7 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils { use MooseX::Types::Path::Class qw/Dir/; use MooseX::Types::Moose qw/Str Maybe Bool HashRef ArrayRef/; use Gitalist::Git::Types qw/SHA1/; + use MooseX::MultiMethods; use Moose::Autobox; use List::MoreUtils qw/any zip/; use DateTime; @@ -74,6 +75,15 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils { } ## Public methods + + multi method get_object_or_head (SHA1 $sha1) { + $self->get_object($sha1); + } + multi method get_object_or_head (NonEmptySimpleStr $ref) { + my $sha1 = $self->head_hash($ref); + $self->get_object($sha1); + } + method head_hash (Str $head?) { my $output = $self->run_cmd(qw/rev-parse --verify/, $head || 'HEAD' ); confess("No such head: " . $head) unless defined $output; @@ -96,7 +106,7 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils { chomp($type); my $class = 'Gitalist::Git::Object::' . ucfirst($type); $class->new( - project => $self, + repository => $self, sha1 => $sha1, type => $type, ); @@ -176,11 +186,11 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils { method diff ( Gitalist::Git::Object :$commit!, Bool :$patch?, Maybe[NonEmptySimpleStr] :$parent?, - NonEmptySimpleStr :$file? + NonEmptySimpleStr :$filename? ) { return $commit->diff( patch => $patch, parent => $parent, - file => $file); + filename => $filename); } method reflog (@logargs) { @@ -227,7 +237,7 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils { ## BUILDERS method _build_util { Gitalist::Git::Util->new( - project => $self, + repository => $self, ); } @@ -237,6 +247,8 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils { $description = $self->path->file('description')->slurp; chomp $description; }; + $description = "Unnamed repository, edit the .git/description file to set a description" + if $description eq "Unnamed repository; edit this file 'description' to name the repository."; return $description; } @@ -339,10 +351,10 @@ Gitalist::Git::Repository - Model of a git repository =head1 SYNOPSIS my $gitrepo = dir('/repo/base/Gitalist'); - my $project = Gitalist::Git::Repository->new($gitrepo); - $project->name; # 'Gitalist' - $project->path; # '/repo/base/Gitalist/.git' - $project->description; # 'Unnamed repository.' + my $repository = Gitalist::Git::Repository->new($gitrepo); + $repository->name; # 'Gitalist' + $repository->path; # '/repo/base/Gitalist/.git' + $repository->description; # 'Unnamed repository.' =head1 DESCRIPTION