Added head_hash method to Project, and some test cleanups.
[catagits/Gitalist.git] / lib / Gitalist / Git / Project.pm
index d5671b6..3fdce70 100644 (file)
@@ -7,6 +7,8 @@ class Gitalist::Git::Project {
     use Path::Class;
     use Gitalist::Git::Util;
 
+    our $SHA1RE = qr/[0-9a-fA-F]{40}/;
+    
     has name => ( isa => NonEmptySimpleStr,
                   is => 'ro' );
     has path => ( isa => "Path::Class::Dir",
@@ -63,6 +65,20 @@ class Gitalist::Git::Project {
         return $last_change;
     }
 
+=head2 head_hash
+
+Find the hash of a given head (defaults to HEAD).
+
+=cut
+
+    method head_hash (Str $head?) {
+        my $output = $self->run_cmd(qw/rev-parse --verify/, $head || 'HEAD' );
+        return unless defined $output;
+
+        my($sha1) = $output =~ /^($SHA1RE)$/;
+        return $sha1;
+    }
+
     method project_dir (Path::Class::Dir $project) {
         my $dir = $project->stringify;
         $dir .= '/.git'