Add the serializeable role everywhere
[catagits/Gitalist.git] / lib / Gitalist / Git / Repository.pm
index f82a026..1d7500c 100644 (file)
@@ -15,6 +15,8 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
     use Gitalist::Git::Object::Tree;
     use Gitalist::Git::Object::Commit;
     use Gitalist::Git::Object::Tag;
+    
+    with 'Gitalist::Serializeable';
 
     our $SHA1RE = qr/[0-9a-fA-F]{40}/;
 
@@ -74,6 +76,12 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
     }
 
     ## Public methods
+
+    method get_object_or_head (NonEmptySimpleStr $ref) {
+        my $sha1 = is_SHA1($ref) ? $ref : $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 +104,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,
         );
@@ -125,7 +133,7 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
             if !$sha1 || $sha1 !~ $SHA1RE;
 
         my @search_opts;
-        if ($search) {
+        if ($search and exists $search->{text}) {
             $search->{type} = 'grep'
                 if $search->{type} eq 'commit';
             @search_opts = (
@@ -173,16 +181,6 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
         # TODO - support compressed archives
     }
 
-    method diff ( Gitalist::Git::Object :$commit!,
-                  Bool :$patch?,
-                  Maybe[NonEmptySimpleStr] :$parent?,
-                  NonEmptySimpleStr :$file?
-              ) {
-              return $commit->diff( patch => $patch,
-                                    parent => $parent,
-                                    file => $file);
-    }
-
     method reflog (@logargs) {
         my @entries
             =  $self->run_cmd(qw(log -g), @logargs)
@@ -227,7 +225,7 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
     ## BUILDERS
     method _build_util {
         Gitalist::Git::Util->new(
-            project => $self,
+            repository => $self,
         );
     }
 
@@ -237,6 +235,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,22 +339,22 @@ 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
 
 This class models a git repository, referred to in Gitalist
-as a "Project".
+as a "Repository".
 
 
 =head1 ATTRIBUTES
 
 =head2 name
 
-The name of the Project.  If unspecified, this will be derived from the path to the git repository.
+The name of the Repository.  If unspecified, this will be derived from the path to the git repository.
 
 =head2 path