From 3866cd6c40195d015b7a567436779471e7cea5db Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Tue, 21 Sep 2021 09:53:32 -0600 Subject: [PATCH] Add test for version height with path filters and merge conflict This demonstrates the repro for #658 --- .../VersionOracleTests.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/NerdBank.GitVersioning.Tests/VersionOracleTests.cs b/src/NerdBank.GitVersioning.Tests/VersionOracleTests.cs index 4f10abf1..9ae579d6 100644 --- a/src/NerdBank.GitVersioning.Tests/VersionOracleTests.cs +++ b/src/NerdBank.GitVersioning.Tests/VersionOracleTests.cs @@ -751,6 +751,38 @@ public void GetVersion_PathFilterInTwoDeepSubDirAndVersionBump() Assert.Equal(1, this.GetVersionHeight(relativeDirectory)); } + [Fact] + public void GetVersion_PathFilterPlusMerge() + { + this.InitializeSourceControl(withInitialCommit: false); + this.WriteVersionFile(new VersionOptions + { + Version = new SemanticVersion("1.0"), + PathFilters = new FilterPath[] { new FilterPath(".", string.Empty) }, + }); + + string conflictedFilePath = Path.Combine(this.RepoPath, "foo.txt"); + + File.WriteAllText(conflictedFilePath, "foo"); + Commands.Stage(this.LibGit2Repository, conflictedFilePath); + this.LibGit2Repository.Commit("Add foo.txt with foo content.", this.Signer, this.Signer); + Branch originalBranch = this.LibGit2Repository.Head; + + Branch topicBranch = this.LibGit2Repository.Branches.Add("topic", "HEAD~1"); + Commands.Checkout(this.LibGit2Repository, topicBranch); + File.WriteAllText(conflictedFilePath, "bar"); + Commands.Stage(this.LibGit2Repository, conflictedFilePath); + this.LibGit2Repository.Commit("Add foo.txt with bar content.", this.Signer, this.Signer); + + Commands.Checkout(this.LibGit2Repository, originalBranch); + MergeResult result = this.LibGit2Repository.Merge(topicBranch, this.Signer, new MergeOptions { FileConflictStrategy = CheckoutFileConflictStrategy.Ours }); + Assert.Equal(MergeStatus.Conflicts, result.Status); + Commands.Stage(this.LibGit2Repository, conflictedFilePath); + this.LibGit2Repository.Commit("Merge two branches", this.Signer, this.Signer); + + Assert.Equal(3, this.GetVersionHeight()); + } + [Fact] public void GetVersionHeight_ProjectDirectoryDifferentToVersionJsonDirectory() {