Skip to content

Commit e33b3f0

Browse files
committed
Only the last SHA1 for any given ref is returned from ref_sha1(). The reason for this is that the commit SHA1 is stored second in packed-refs if a commit is annoted with a tag object.
1 parent 51619c2 commit e33b3f0

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/Git/PurePerl.pm

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,20 @@ sub ref_sha1 {
198198

199199
my $packed_refs = file( $self->gitdir, 'packed-refs' );
200200
if ( -f $packed_refs ) {
201+
my $last_name;
202+
my $last_sha1;
201203
foreach my $line ( $packed_refs->slurp( chomp => 1 ) ) {
202204
next if $line =~ /^#/;
203205
my ( $sha1, my $name ) = split ' ', $line;
204-
return _ensure_sha1_is_sha1( $self, $sha1 ) if $name eq $wantref;
206+
$sha1 =~ s/^\^//;
207+
$name ||= $last_name;
208+
209+
return _ensure_sha1_is_sha1( $self, $last_sha1 ) if $last_name and $last_name eq $wantref and $name ne $wantref;
210+
211+
$last_name = $name;
212+
$last_sha1 = $sha1;
205213
}
214+
return _ensure_sha1_is_sha1( $self, $last_sha1 ) if $last_name eq $wantref;
206215
}
207216
return undef;
208217
}

0 commit comments

Comments
 (0)