Skip to content

Commit d9e3dbc

Browse files
tclemnulltoken
authored andcommitted
Add ParentsCount property to Commit
1 parent 4130b94 commit d9e3dbc

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

LibGit2Sharp.Tests/CommitFixture.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ public void CanEnumerateCommitsWithReverseTopoSorting()
164164
}
165165
}
166166

167+
[Test]
168+
public void CanGetParentsCount()
169+
{
170+
using (var repo = new Repository(BareTestRepoPath))
171+
{
172+
repo.Commits.First().ParentsCount.ShouldEqual(1);
173+
}
174+
}
175+
167176
[Test]
168177
public void CanEnumerateCommitsWithTimeSorting()
169178
{
@@ -378,7 +387,7 @@ public void CanReadCommitData()
378387

379388
commit.Tree.Sha.ShouldEqual("181037049a54a1eb5fab404658a3a250b44335d7");
380389

381-
commit.Parents.Count().ShouldEqual(0);
390+
commit.ParentsCount.ShouldEqual(0);
382391
}
383392
}
384393

@@ -389,6 +398,7 @@ public void CanReadCommitWithMultipleParents()
389398
{
390399
var commit = repo.Lookup<Commit>("a4a7dce85cf63874e984719f4fdd239f5145052f");
391400
commit.Parents.Count().ShouldEqual(2);
401+
commit.ParentsCount.ShouldEqual(2);
392402
}
393403
}
394404

@@ -493,7 +503,7 @@ public void CanCommitALittleBit()
493503
AssertBlobContent(repo.Head[relativeFilepath], "nulltoken\n");
494504
AssertBlobContent(commit[relativeFilepath], "nulltoken\n");
495505

496-
commit.Parents.Count().ShouldEqual(0);
506+
commit.ParentsCount.ShouldEqual(0);
497507
repo.Info.IsEmpty.ShouldBeFalse();
498508

499509
File.WriteAllText(filePath, "nulltoken commits!\n");
@@ -505,7 +515,7 @@ public void CanCommitALittleBit()
505515
AssertBlobContent(repo.Head[relativeFilepath], "nulltoken commits!\n");
506516
AssertBlobContent(commit2[relativeFilepath], "nulltoken commits!\n");
507517

508-
commit2.Parents.Count().ShouldEqual(1);
518+
commit2.ParentsCount.ShouldEqual(1);
509519
commit2.Parents.First().Id.ShouldEqual(commit.Id);
510520

511521
Branch firstCommitBranch = repo.CreateBranch("davidfowl-rules", commit.Id.Sha); //TODO: This cries for a shortcut method :-/
@@ -521,7 +531,7 @@ public void CanCommitALittleBit()
521531
AssertBlobContent(repo.Head[relativeFilepath], "davidfowl commits!\n");
522532
AssertBlobContent(commit3[relativeFilepath], "davidfowl commits!\n");
523533

524-
commit3.Parents.Count().ShouldEqual(1);
534+
commit3.ParentsCount.ShouldEqual(1);
525535
commit3.Parents.First().Id.ShouldEqual(commit.Id);
526536

527537
AssertBlobContent(firstCommitBranch[relativeFilepath], "nulltoken\n");
@@ -580,7 +590,7 @@ public void CanAmendARootCommit()
580590
repo.Head.Commits.Count().ShouldEqual(1);
581591

582592
Commit originalCommit = repo.Head.Tip;
583-
originalCommit.Parents.Count().ShouldEqual(0);
593+
originalCommit.ParentsCount.ShouldEqual(0);
584594

585595
CreateAndStageANewFile(repo);
586596

@@ -600,7 +610,7 @@ public void CanAmendACommitWithMoreThanOneParent()
600610
{
601611
var mergedCommit = repo.Lookup<Commit>("be3563a");
602612
mergedCommit.ShouldNotBeNull();
603-
mergedCommit.Parents.Count().ShouldEqual(2);
613+
mergedCommit.ParentsCount.ShouldEqual(2);
604614

605615
repo.Reset(ResetOptions.Soft, mergedCommit.Sha);
606616

LibGit2Sharp/Commit.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ public IEnumerable<Commit> Parents
8989
get { return parents.Value; }
9090
}
9191

92+
/// <summary>
93+
/// Gets The count of parent commits.
94+
/// </summary>
95+
public uint ParentsCount
96+
{
97+
get
98+
{
99+
using (var obj = new ObjectSafeWrapper(Id, repo))
100+
{
101+
return NativeMethods.git_commit_parentcount(obj.ObjectPtr);
102+
}
103+
}
104+
}
105+
92106
private IEnumerable<Commit> RetrieveParentsOfCommit(ObjectId oid)
93107
{
94108
using (var obj = new ObjectSafeWrapper(oid, repo))

0 commit comments

Comments
 (0)