8000 Handle tags that do not have a tagger. · GiTechLab/libgit2sharp@f2baf87 · GitHub
[go: up one dir, main page]

Skip to content

Commit f2baf87

Browse files
committed
Handle tags that do not have a tagger.
Not all tags have a tagger. For example, the v2.6.11 tag on the linux repository does not have a tagger. For these cases, return null for the Tagger property on a tag annotation.
1 parent 18c57ac commit f2baf87

File tree

5 files changed

+39
-7
lines changed

5 files changed

+39
-7
lines changed

LibGit2Sharp.Tests/ReferenceFixture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class ReferenceFixture : BaseFixture
1313
{
1414
"refs/heads/br2", "refs/heads/deadbeef", "refs/heads/master", "refs/heads/packed", "refs/heads/packed-test",
1515
"refs/heads/test", "refs/notes/answer", "refs/notes/answer2", "refs/notes/commits", "refs/tags/e90810b",
16-
"refs/tags/lw", "refs/tags/point_to_blob", "refs/tags/test"
16+
"refs/tags/lw", "refs/tags/point_to_blob", "refs/tags/tag_without_tagger", "refs/tags/test"
1717
};
1818

1919
[Fact]
@@ -320,7 +320,7 @@ public void CanListAllReferencesEvenCorruptedOnes()
320320

321321
Assert.Equal(expectedRefs, SortedRefs(repo, r => r.CanonicalName));
322322

323-
Assert.Equal(13, repo.Refs.Count());
323+
Assert.Equal(14, repo.Refs.Count());
324324
}
325325
}
326326

@@ -730,9 +730,9 @@ public void CanFilterReferencesWithAGlob()
730730
{
731731
using (var repo = new Repository(BareTestRepoPath))
732732
{
733-
Assert.Equal(12, repo.Refs.FromGlob("*").Count());
733+
Assert.Equal(13, repo.Refs.FromGlob("*").Count());
734734
Assert.Equal(5, repo.Refs.FromGlob("refs/heads/*").Count());
735-
Assert.Equal(4, repo.Refs.FromGlob("refs/tags/*").Count());
735+
Assert.Equal(5, repo.Refs.FromGlob("refs/tags/*").Count());
736736
Assert.Equal(3, repo.Refs.FromGlob("*t?[pqrs]t*").Count());
737737
Assert.Equal(0, repo.Refs.FromGlob("test").Count());
738738
}

LibGit2Sharp.Tests/Resources/testrepo.git/objects/25/2846a95d7b031136d19f5a8a85ebed204cdbef

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x��� D=SŖ ?�j �.�A��1v/&��&� �h����,i���੕Rr�z�H�葔Ӌw����|!
2+
n-�[8ׇ�� /!8����G�����$
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
252846a95d7b031136d19f5a8a85ebed204cdbef

LibGit2Sharp.Tests/TagFixture.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace LibGit2Sharp.Tests
99
{
1010
public class TagFixture : BaseFixture
1111
{
12-
private readonly string[] expectedTags = new[] { "e90810b", "lw", "point_to_blob", "test", };
12+
private readonly string[] expectedTags = new[] { "e90810b", "lw", "point_to_blob", "tag_without_tagger", "test", };
1313

1414
private static readonly Signature signatureTim = new Signature("Tim Clem", "timothy.clem@gmail.com", TruncateSubSeconds(DateTimeOffset.UtcNow));
1515
private static readonly Signature signatureNtk = new Signature("nulltoken", "emeric.fermas@gmail.com", Epoch.ToDateTimeOffset(1300557894, 60));
@@ -350,6 +350,25 @@ public void CanAddATagPointingToATree()
350350
}
351351
}
352352

353+
[Fact]
354+
public void CanReadTagWithoutTagger()
355+
{
356+
// Not all tags have a tagger.
357+
using (var repo = new Repository(BareTestRepoPath))
358+
{
359+
Tag tag = repo.Tags["tag_without_tagger"];
360+
361+
Assert.True(tag.IsAnnotated);
362+
Assert.NotNull(tag.Target);
363+
Assert.Null(tag.Annotation.Tagger);
364+
365+
Tree tree = repo.Lookup<Tree>("581f9824ecaf824221bd36edf5430f2739a7c4f5");
366+
Assert.NotNull(tree);
367+
368+
Assert.Equal(tree.Id, tag.Target.Id);
369+
}
370+
}
371+
353372
[Fact]
354373
public void CanAddATagPointingToABlob()
355374
{
@@ -590,7 +609,7 @@ public void CanListTags()
590609
{
591610
Assert.Equal(expectedTags, SortedTags(repo.Tags, t => t.Name));
592611

593-
1E11 Assert.Equal(4, repo.Tags.Count());
612+
Assert.Equal(5, repo.Tags.Count());
594613
}
595614
}
596615

LibGit2Sharp/Core/Proxy.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2885,7 +2885,17 @@ public static string git_tag_name(GitObjectSafeHandle tag)
28852885

28862886
public static Signature git_tag_tagger(GitObjectSafeHandle tag)
28872887
{
2888-
return new Signature(NativeMethods.git_tag_tagger(tag));
2888+
IntPtr taggerHandle = NativeMethods.git_tag_tagger(tag);
2889+
2890+
// Not all tags have a tagger signature - we need to handle
2891+
// this case.
2892+
Signature tagger = null;
2893+
if (taggerHandle != IntPtr.Zero)
2894+
{
2895+
tagger = new Signature(NativeMethods.git_tag_tagger(tag));
2896+
}
2897+
2898+
return tagger;
28892899
}
28902900

28912901
public static ObjectId git_tag_target_id(GitObjectSafeHandle tag)

0 commit comments

Comments
 (0)
0