Merge remote branch 't0m/json' into json
[catagits/Gitalist.git] / lib / Gitalist / Git / Repository.pm
index a230129..e4eb595 100644 (file)
@@ -4,6 +4,7 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
     # FIXME, use Types::Path::Class and coerce
     use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
     use MooseX::Types::Moose qw/Str Maybe Bool HashRef ArrayRef/;
+    use MooseX::MultiMethods;
     use Gitalist::Git::Types qw/SHA1 DateTime Dir/;
     use Moose::Autobox;
     use List::MoreUtils qw/any zip/;
@@ -78,6 +79,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;
@@ -129,7 +139,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 = (
@@ -180,11 +190,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) {
@@ -241,6 +251,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;
     }