Skip to content

Commit 9cff862

Browse files
committed
Add git height tests for inheriting version.json files
1 parent 43d3aab commit 9cff862

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/NerdBank.GitVersioning.Tests/VersionFileTests.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public void VersionJson_Inheritance(bool commitInSourceControl, bool bareRepo)
308308
this.InitializeSourceControl();
309309
}
310310

311-
VersionOptions level1, level2, level3, level2NoInherit;
311+
VersionOptions level1, level2, level3, level2NoInherit, level2InheritButResetVersion;
312312
this.WriteVersionFile(
313313
level1 = new VersionOptions
314314
{
@@ -335,6 +335,13 @@ public void VersionJson_Inheritance(bool commitInSourceControl, bool bareRepo)
335335
Version = SemanticVersion.Parse("10.1"),
336336
},
337337
@"noInherit");
338+
this.WriteVersionFile(
339+
level2InheritButResetVersion = new VersionOptions
340+
{
341+
Inherit = true,
342+
Version = SemanticVersion.Parse("8.2"),
343+
},
344+
@"inheritWithVersion");
338345

339346
Repository operatingRepo = this.Repo;
340347
if (bareRepo)
@@ -368,6 +375,25 @@ public void VersionJson_Inheritance(bool commitInSourceControl, bool bareRepo)
368375
Assert.Equal(level2NoInherit.Version, level2NoInheritOptions.Version);
369376
Assert.Equal(VersionOptions.DefaultVersionPrecision, level2NoInheritOptions.AssemblyVersionOrDefault.PrecisionOrDefault);
370377
Assert.False(level2NoInheritOptions.Inherit);
378+
379+
var level2InheritButResetVersionOptions = GetOption("inheritWithVersion");
380+
Assert.Equal(level2InheritButResetVersion.Version, level2InheritButResetVersionOptions.Version);
381+
Assert.True(level2InheritButResetVersionOptions.Inherit);
382+
383+
if (commitInSourceControl)
384+
{
385+
int totalCommits = operatingRepo.Head.Commits.Count();
386+
387+
// The version height should be the same for all those that inherit the version from the base,
388+
// even though the inheriting files were introduced in successive commits.
389+
Assert.Equal(totalCommits, operatingRepo.GetVersionHeight());
390+
Assert.Equal(totalCommits, operatingRepo.GetVersionHeight("foo"));
391+
Assert.Equal(totalCommits, operatingRepo.GetVersionHeight(@"foo\bar"));
392+
393+
// These either don't inherit, or inherit but reset versions, so the commits were reset.
394+
Assert.Equal(2, operatingRepo.GetVersionHeight("noInherit"));
395+
Assert.Equal(1, operatingRepo.GetVersionHeight("inheritWithVersion"));
396+
}
371397
}
372398
}
373399

0 commit comments

Comments
 (0)