Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2013-11-14 01:24:36 +0400
committernulltoken <emeric.fermas@gmail.com>2013-12-06 03:53:35 +0400
commita845db98d9eff7fe16a371d7c08b9f2715801d94 (patch)
tree40637aae49b8f03265315c2a991d8bdb977e0b7b /LibGit2Sharp.Tests
parent442f7a80502ed919d94891400f7766b8415f106d (diff)
Introduce ObjectDatabase.CalculateHistoryDivergence()
Fix #562
Diffstat (limited to 'LibGit2Sharp.Tests')
-rw-r--r--LibGit2Sharp.Tests/ObjectDatabaseFixture.cs51
1 files changed, 51 insertions, 0 deletions
diff --git a/LibGit2Sharp.Tests/ObjectDatabaseFixture.cs b/LibGit2Sharp.Tests/ObjectDatabaseFixture.cs
index e47697f3..9913aefc 100644
--- a/LibGit2Sharp.Tests/ObjectDatabaseFixture.cs
+++ b/LibGit2Sharp.Tests/ObjectDatabaseFixture.cs
@@ -481,5 +481,56 @@ namespace LibGit2Sharp.Tests
Assert.Equal(string.Empty, tagAnnotation.Message);
}
}
+
+ [Theory]
+ [InlineData("c47800c", "9fd738e", "5b5b025", 1, 2)]
+ [InlineData("9fd738e", "c47800c", "5b5b025", 2, 1)]
+ public void CanCalculateHistoryDivergence(
+ string sinceSha, string untilSha,
+ string expectedAncestorSha, int? expectedAheadBy, int? expectedBehindBy)
+ {
+ using (var repo = new Repository(BareTestRepoPath))
+ {
+ var since = repo.Lookup<Commit>(sinceSha);
+ var until = repo.Lookup<Commit>(untilSha);
+
+ HistoryDivergence div = repo.ObjectDatabase.CalculateHistoryDivergence(since, until);
+
+ Assert.Equal(expectedAheadBy, div.AheadBy);
+ Assert.Equal(expectedBehindBy, div.BehindBy);
+ Assert.Equal(expectedAncestorSha, div.CommonAncestor.Id.ToString(7));
+ }
+ }
+
+ [Theory]
+ [InlineData("c47800c", "41bc8c6907", 3, 2)]
+ public void CanCalculateHistoryDivergenceWhenNoAncestorIsShared(
+ string sinceSha, string untilSha,
+ int? expectedAheadBy, int? expectedBehindBy)
+ {
+ using (var repo = new Repository(BareTestRepoPath))
+ {
+ var since = repo.Lookup<Commit>(sinceSha);
+ var until = repo.Lookup<Commit>(untilSha);
+
+ HistoryDivergence div = repo.ObjectDatabase.CalculateHistoryDivergence(since, until);
+
+ Assert.Equal(expectedAheadBy, div.AheadBy);
+ Assert.Equal(expectedBehindBy, div.BehindBy);
+ Assert.Null(div.CommonAncestor);
+ }
+ }
+
+ [Fact]
+ public void CalculatingHistoryDivergenceWithBadParamsThrows()
+ {
+ using (var repo = new Repository(BareTestRepoPath))
+ {
+ Assert.Throws<ArgumentNullException>(
+ () => repo.ObjectDatabase.CalculateHistoryDivergence(repo.Head.Tip, null));
+ Assert.Throws<ArgumentNullException>(
+ () => repo.ObjectDatabase.CalculateHistoryDivergence(null, repo.Head.Tip));
+ }
+ }
}
}