public void GetHeight_Merge() { var firstCommit = this.LibGit2Repository.Commit("First", this.Signer, this.Signer, new CommitOptions { AllowEmptyCommit = true }); var anotherBranch = this.LibGit2Repository.CreateBranch("another"); var secondCommit = this.LibGit2Repository.Commit("Second", this.Signer, this.Signer, new CommitOptions { AllowEmptyCommit = true }); Commands.Checkout(this.LibGit2Repository, anotherBranch); Commit[] branchCommits = new Commit[5]; for (int i = 1; i <= branchCommits.Length; i++) { branchCommits[i - 1] = this.LibGit2Repository.Commit($"branch commit #{i}", this.Signer, this.Signer, new CommitOptions { AllowEmptyCommit = true }); } this.LibGit2Repository.Merge(secondCommit, new Signature("t", "*****@*****.**", DateTimeOffset.Now), new MergeOptions { FastForwardStrategy = FastForwardStrategy.NoFastForward }); this.SetContextToHead(); // While we've created 8 commits, the tallest height is only 7. Assert.Equal(7, LibGit2GitExtensions.GetHeight(this.Context)); // Now stop enumerating early on just one branch of the ancestry -- the number should remain high. Assert.Equal(7, LibGit2GitExtensions.GetHeight(this.Context, c => c != secondCommit)); // This time stop in both branches of history, and verify that we count the taller one. Assert.Equal(3, LibGit2GitExtensions.GetHeight(this.Context, c => c != secondCommit && c != branchCommits[2])); }
public void GetHeight_EmptyRepo() { this.InitializeSourceControl(); Branch head = this.LibGit2Repository.Head; Assert.Throws <InvalidOperationException>(() => LibGit2GitExtensions.GetHeight(this.Context)); Assert.Throws <InvalidOperationException>(() => LibGit2GitExtensions.GetHeight(this.Context, c => true)); }
public void GetHeight_SinglePath() { var first = this.LibGit2Repository.Commit("First", this.Signer, this.Signer, new CommitOptions { AllowEmptyCommit = true }); var second = this.LibGit2Repository.Commit("Second", this.Signer, this.Signer, new CommitOptions { AllowEmptyCommit = true }); var third = this.LibGit2Repository.Commit("Third", this.Signer, this.Signer, new CommitOptions { AllowEmptyCommit = true }); this.SetContextToHead(); Assert.Equal(3, LibGit2GitExtensions.GetHeight(this.Context)); Assert.Equal(3, LibGit2GitExtensions.GetHeight(this.Context, c => true)); Assert.Equal(2, LibGit2GitExtensions.GetHeight(this.Context, c => c != first)); Assert.Equal(1, LibGit2GitExtensions.GetHeight(this.Context, c => c != second)); }