10000 Support retrieving submodule Id in TreeEntry · libgit2/libgit2sharp@bf7c434 · GitHub
[go: up one dir, main page]

Skip to content

Commit bf7c434

Browse files
committed
Support retrieving submodule Id in TreeEntry
1 parent 7367fc3 commit bf7c434

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

LibGit2Sharp.Tests/SubmoduleFixture.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23
using System.Linq;
34
using LibGit2Sharp.Tests.TestHelpers;
45
using Xunit;
@@ -67,9 +68,17 @@ public void CanRetrieveTheCommitIdsOfASubmodule(string name, string headId, stri
6768
Assert.Equal((ObjectId)headId, submodule.HeadCommitId);
6869
Assert.Equal((ObjectId)indexId, submodule.IndexCommitId);
6970
Assert.Equal((ObjectId)workDirId, submodule.WorkDirCommitId);
71+
72+
AssertEntryId((ObjectId)headId, repo.Head[name], c => c.Target.Id);
73+
AssertEntryId((ObjectId)indexId, repo.Index[name], i => i.Id);
7074
}
7175
}
7276

77+
private static void AssertEntryId<T>(ObjectId expected, T entry, Func<T, ObjectId> selector)
78+
{
79+
Assert.Equal(expected, ReferenceEquals(entry, null) ? null : selector(entry));
80+
}
81+
7382
[Fact]
7483
public void CanEnumerateRepositorySubmodules()
7584
{

LibGit2Sharp/TreeEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ internal ObjectId TargetId
7272

7373
private GitObject RetrieveTreeEntryTarget()
7474
{
75-
if (!Type.HasAny(new[]{GitObjectType.Tree, GitObjectType.Blob}))
75+
if (!Type.HasAny(new[]{GitObjectType.Tree, GitObjectType.Blob, GitObjectType.Commit}))
7676
{
7777
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "TreeEntry target of type '{0}' are not supported.", Type));
7878
}

0 commit comments

Comments
 (0)
0