Skip to content

Commit e098d50

Browse files
committedDec 11, 2009
Add support for the special HEAD ref, and associated methods
1 parent d8d7094 commit e098d50

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
 

‎lib/Git/PurePerl.pm

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ sub ref_sha1 {
164164
my @refs;
165165
my $dir = dir( $self->gitdir, 'refs' );
166166
return unless -d $dir;
167+
168+
if ($wantref eq "HEAD") {
169+
my $file = file($self->gitdir, 'HEAD');
170+
my $sha1 = file($file)->slurp
171+
|| confess("Error reading $file: $!");
172+
chomp $sha1;
173+
return $self->ref_sha1($1) if $sha1 =~ /^ref: (.*)/;
174+
return $sha1;
175+
}
176+
167177
foreach my $file ( File::Find::Rule->new->file->in($dir) ) {
168178
my $ref = 'refs/' . file($file)->relative($dir)->as_foreign('Unix');
169179
if ( $ref eq $wantref ) {
@@ -204,6 +214,16 @@ sub master {
204214
return $self->ref('refs/heads/master');
205215
}
206216

217+
sub head_sha1 {
218+
my $self = shift;
219+
return $self->ref_sha1('HEAD');
220+
}
221+
222+
sub head {
223+
my $self = shift;
224+
return $self->ref('HEAD');
225+
}
226+
207227
sub get_object {
208228
my ( $self, $sha1 ) = @_;
209229
return unless $sha1;

0 commit comments

Comments
 (0)
Please sign in to comment.