From f2baf871b71add1a456f90cfa83e7a45b583b571 Mon Sep 17 00:00:00 2001 From: Jameson Miller Date: Mon, 30 Jun 2014 15:44:04 -0400 Subject: [PATCH] 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. --- LibGit2Sharp.Tests/ReferenceFixture.cs | 8 +++---- .../25/2846a95d7b031136d19f5a8a85ebed204cdbef | 2 ++ .../testrepo.git/refs/tags/tag_without_tagger | 1 + LibGit2Sharp.Tests/TagFixture.cs | 23 +++++++++++++++++-- LibGit2Sharp/Core/Proxy.cs | 12 +++++++++- 5 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 LibGit2Sharp.Tests/Resources/testrepo.git/objects/25/2846a95d7b031136d19f5a8a85ebed204cdbef create mode 100644 LibGit2Sharp.Tests/Resources/testrepo.git/refs/tags/tag_without_tagger diff --git a/LibGit2Sharp.Tests/ReferenceFixture.cs b/LibGit2Sharp.Tests/ReferenceFixture.cs index 9b25d47b4..6090d8e09 100644 --- a/LibGit2Sharp.Tests/ReferenceFixture.cs +++ b/LibGit2Sharp.Tests/ReferenceFixture.cs @@ -13,7 +13,7 @@ public class ReferenceFixture : BaseFixture { "refs/heads/br2", "refs/heads/deadbeef", "refs/heads/master", "refs/heads/packed", "refs/heads/packed-test", "refs/heads/test", "refs/notes/answer", "refs/notes/answer2", "refs/notes/commits", "refs/tags/e90810b", - "refs/tags/lw", "refs/tags/point_to_blob", "refs/tags/test" + "refs/tags/lw", "refs/tags/point_to_blob", "refs/tags/tag_without_tagger", "refs/tags/test" }; [Fact] @@ -320,7 +320,7 @@ public void CanListAllReferencesEvenCorruptedOnes() Assert.Equal(expectedRefs, SortedRefs(repo, r => r.CanonicalName)); - Assert.Equal(13, repo.Refs.Count()); + Assert.Equal(14, repo.Refs.Count()); } } @@ -730,9 +730,9 @@ public void CanFilterReferencesWithAGlob() { using (var repo = new Repository(BareTestRepoPath)) { - Assert.Equal(12, repo.Refs.FromGlob("*").Count()); + Assert.Equal(13, repo.Refs.FromGlob("*").Count()); Assert.Equal(5, repo.Refs.FromGlob("refs/heads/*").Count()); - Assert.Equal(4, repo.Refs.FromGlob("refs/tags/*").Count()); + Assert.Equal(5, repo.Refs.FromGlob("refs/tags/*").Count()); Assert.Equal(3, repo.Refs.FromGlob("*t?[pqrs]t*").Count()); Assert.Equal(0, repo.Refs.FromGlob("test").Count()); } diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/objects/25/2846a95d7b031136d19f5a8a85ebed204cdbef b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/25/2846a95d7b031136d19f5a8a85ebed204cdbef new file mode 100644 index 000000000..483e735a3 --- /dev/null +++ b/LibGit2Sharp.Tests/Resources/testrepo.git/objects/25/2846a95d7b031136d19f5a8a85ebed204cdbef @@ -0,0 +1,2 @@ +x D=SŖ ?j .A1v/&& h,i੕RrzH葔Ӌw|! +n-[8ׇ /!8 G$ \ No newline at end of file diff --git a/LibGit2Sharp.Tests/Resources/testrepo.git/refs/tags/tag_without_tagger b/LibGit2Sharp.Tests/Resources/testrepo.git/refs/tags/tag_without_tagger new file mode 100644 index 000000000..9488f855f --- /dev/null +++ b/LibGit2Sharp.Tests/Resources/testrepo.git/refs/tags/tag_without_tagger @@ -0,0 +1 @@ +252846a95d7b031136d19f5a8a85ebed204cdbef diff --git a/LibGit2Sharp.Tests/TagFixture.cs b/LibGit2Sharp.Tests/TagFixture.cs index 7d5751ad1..97f5b24d5 100644 --- a/LibGit2Sharp.Tests/TagFixture.cs +++ b/LibGit2Sharp.Tests/TagFixture.cs @@ -9,7 +9,7 @@ namespace LibGit2Sharp.Tests { public class TagFixture : BaseFixture { - private readonly string[] expectedTags = new[] { "e90810b", "lw", "point_to_blob", "test", }; + private readonly string[] expectedTags = new[] { "e90810b", "lw", "point_to_blob", "tag_without_tagger", "test", }; private static readonly Signature signatureTim = new Signature("Tim Clem", "timothy.clem@gmail.com", TruncateSubSeconds(DateTimeOffset.UtcNow)); private static readonly Signature signatureNtk = new Signature("nulltoken", "emeric.fermas@gmail.com", Epoch.ToDateTimeOffset(1300557894, 60)); @@ -350,6 +350,25 @@ public void CanAddATagPointingToATree() } } + [Fact] + public void CanReadTagWithoutTagger() + { + // Not all tags have a tagger. + using (var repo = new Repository(BareTestRepoPath)) + { + Tag tag = repo.Tags["tag_without_tagger"]; + + Assert.True(tag.IsAnnotated); + Assert.NotNull(tag.Target); + Assert.Null(tag.Annotation.Tagger); + + Tree tree = repo.Lookup("581f9824ecaf824221bd36edf5430f2739a7c4f5"); + Assert.NotNull(tree); + + Assert.Equal(tree.Id, tag.Target.Id); + } + } + [Fact] public void CanAddATagPointingToABlob() { @@ -590,7 +609,7 @@ public void CanListTags() { Assert.Equal(expectedTags, SortedTags(repo.Tags, t => t.Name)); - Assert.Equal(4, repo.Tags.Count()); + Assert.Equal(5, repo.Tags.Count()); } } diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs index f49ea662a..829794652 100644 --- a/LibGit2Sharp/Core/Proxy.cs +++ b/LibGit2Sharp/Core/Proxy.cs @@ -2885,7 +2885,17 @@ public static string git_tag_name(GitObjectSafeHandle tag) public static Signature git_tag_tagger(GitObjectSafeHandle tag) { - return new Signature(NativeMethods.git_tag_tagger(tag)); + IntPtr taggerHandle = NativeMethods.git_tag_tagger(tag); + + // Not all tags have a tagger signature - we need to handle + // this case. + Signature tagger = null; + if (taggerHandle != IntPtr.Zero) + { + tagger = new Signature(NativeMethods.git_tag_tagger(tag)); + } + + return tagger; } public static ObjectId git_tag_target_id(GitObjectSafeHandle tag)