Skip to content

Commit 1074e57

Browse files
committed
Add tests of various lengths of partial commit matching
1 parent 912e129 commit 1074e57

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/NerdBank.GitVersioning.Tests/GitContextTests.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,15 @@ public void SelectCommitByPartialId(bool fromPack)
8585
Assert.Equal(this.LibGit2Repository.Head.Tip.Sha, this.Context.GitCommitId);
8686
}
8787

88-
[Fact]
89-
public void GetShortUniqueCommitId()
88+
[SkippableTheory]
89+
[InlineData(4)]
90+
[InlineData(7)]
91+
[InlineData(8)]
92+
[InlineData(11)]
93+
public void GetShortUniqueCommitId(int length)
9094
{
91-
Assert.Equal("51cd9ed3", this.Context.GetShortUniqueCommitId(8));
95+
Skip.If(length < 7 && this.Context is Nerdbank.GitVersioning.LibGit2.LibGit2Context);
96+
Assert.Equal(this.Context.GitCommitId.Substring(0, length), this.Context.GetShortUniqueCommitId(length));
9297
}
9398

9499
[Theory, CombinatorialData]

src/NerdBank.GitVersioning.Tests/VersionOracleTests.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -795,15 +795,22 @@ public void GetVersionHeight_ProjectDirectoryIsMoved()
795795
}
796796

797797
[Fact]
798-
public void OptimallyShortCommitId()
798+
public void GitCommitIdShort()
799799
{
800800
this.WriteVersionFile(new VersionOptions { Version = SemanticVersion.Parse("1.2"), GitCommitIdShortAutoMinimum = 4 });
801801
this.InitializeSourceControl();
802802
this.AddCommits(1);
803803
var oracle = new VersionOracle(this.Context);
804804

805-
// I'm not sure why libgit2 returns 7 as the minimum length when clearly a two commit repo would need fewer.
806-
Assert.Equal(7, oracle.GitCommitIdShort.Length);
805+
if (this.Context is Nerdbank.GitVersioning.LibGit2.LibGit2Context)
806+
{
807+
// I'm not sure why libgit2 returns 7 as the minimum length when clearly a two commit repo would need fewer.
808+
Assert.Equal(7, oracle.GitCommitIdShort.Length);
809+
}
810+
else
811+
{
812+
Assert.Equal(4, oracle.GitCommitIdShort.Length);
813+
}
807814
}
808815

809816
[Fact(Skip = "Slow test")]

0 commit comments

Comments
 (0)