From 0e6554ea90468c086a1ac3e070d1c376413c581e Mon Sep 17 00:00:00 2001 From: Alexander Pykavy Date: Wed, 30 Nov 2022 18:56:40 +0100 Subject: [PATCH] Remove baseVersionBuildMetaData == null check --- .../NextVersionCalculatorTests.cs | 20 ++++++++++++++----- .../NextVersionCalculator.cs | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/GitVersion.Core.Tests/VersionCalculation/NextVersionCalculatorTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/NextVersionCalculatorTests.cs index 7393e7e7f8..f0248cf82e 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/NextVersionCalculatorTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/NextVersionCalculatorTests.cs @@ -313,7 +313,9 @@ public void ChoosesHighestVersionReturnedFromStrategies() repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); var dateTimeOffset = DateTimeOffset.Now; var versionStrategies = new IVersionStrategy[] { new V1Strategy(DateTimeOffset.Now), new V2Strategy(dateTimeOffset) }; - var unitUnderTest = new NextVersionCalculator(Substitute.For(), Substitute.For(), + var mainlineVersionCalculatorMock = Substitute.For(); + mainlineVersionCalculatorMock.CreateVersionBuildMetaData(Arg.Any()).Returns(new SemanticVersionBuildMetaData()); + var unitUnderTest = new NextVersionCalculator(Substitute.For(), mainlineVersionCalculatorMock, repositoryStoreMock, new(context), versionStrategies, effectiveBranchConfigurationFinderMock, incrementStrategyFinderMock); // Act @@ -342,7 +344,9 @@ public void UsesWhenFromNextBestMatchIfHighestDoesntHaveWhen() repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); var when = DateTimeOffset.Now; var versionStrategies = new IVersionStrategy[] { new V1Strategy(when), new V2Strategy(null) }; - var unitUnderTest = new NextVersionCalculator(Substitute.For(), Substitute.For(), + var mainlineVersionCalculatorMock = Substitute.For(); + mainlineVersionCalculatorMock.CreateVersionBuildMetaData(Arg.Any()).Returns(new SemanticVersionBuildMetaData()); + var unitUnderTest = new NextVersionCalculator(Substitute.For(), mainlineVersionCalculatorMock, repositoryStoreMock, new(context), versionStrategies, effectiveBranchConfigurationFinderMock, incrementStrategyFinderMock); // Act @@ -371,7 +375,9 @@ public void UsesWhenFromNextBestMatchIfHighestDoesntHaveWhenReversedOrder() repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); var when = DateTimeOffset.Now; var versionStrategies = new IVersionStrategy[] { new V2Strategy(null), new V1Strategy(when) }; - var unitUnderTest = new NextVersionCalculator(Substitute.For(), Substitute.For(), + var mainlineVersionCalculatorMock = Substitute.For(); + mainlineVersionCalculatorMock.CreateVersionBuildMetaData(Arg.Any()).Returns(new SemanticVersionBuildMetaData()); + var unitUnderTest = new NextVersionCalculator(Substitute.For(), mainlineVersionCalculatorMock, repositoryStoreMock, new(context), versionStrategies, effectiveBranchConfigurationFinderMock, incrementStrategyFinderMock); // Act @@ -401,7 +407,9 @@ public void ShouldNotFilterVersion() repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any>()).Returns(Enumerable.Empty()); var version = new BaseVersion("dummy", false, new SemanticVersion(2), GitToolsTestingExtensions.CreateMockCommit(), null); var versionStrategies = new IVersionStrategy[] { new TestVersionStrategy(version) }; - var unitUnderTest = new NextVersionCalculator(Substitute.For(), Substitute.For(), + var mainlineVersionCalculatorMock = Substitute.For(); + mainlineVersionCalculatorMock.CreateVersionBuildMetaData(Arg.Any()).Returns(new SemanticVersionBuildMetaData()); + var unitUnderTest = new NextVersionCalculator(Substitute.For(), mainlineVersionCalculatorMock, repositoryStoreMock, new(context), versionStrategies, effectiveBranchConfigurationFinderMock, incrementStrategyFinderMock); // Act @@ -431,7 +439,9 @@ public void ShouldFilterVersion() var higherVersion = new BaseVersion("exclude", false, new SemanticVersion(2), GitToolsTestingExtensions.CreateMockCommit(), null); var lowerVersion = new BaseVersion("dummy", false, new SemanticVersion(1), GitToolsTestingExtensions.CreateMockCommit(), null); var versionStrategies = new IVersionStrategy[] { new TestVersionStrategy(higherVersion, lowerVersion) }; - var unitUnderTest = new NextVersionCalculator(Substitute.For(), Substitute.For(), + var mainlineVersionCalculatorMock = Substitute.For(); + mainlineVersionCalculatorMock.CreateVersionBuildMetaData(Arg.Any()).Returns(new SemanticVersionBuildMetaData()); + var unitUnderTest = new NextVersionCalculator(Substitute.For(), mainlineVersionCalculatorMock, repositoryStoreMock, new(context), versionStrategies, effectiveBranchConfigurationFinderMock, incrementStrategyFinderMock); // Act diff --git a/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs index f6d6da9922..d08166852b 100644 --- a/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs +++ b/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs @@ -60,7 +60,7 @@ public virtual NextVersion FindVersion() { var baseVersionBuildMetaData = this.mainlineVersionCalculator.CreateVersionBuildMetaData(baseVersion.BaseVersionSource); - if (baseVersionBuildMetaData == null || baseVersionBuildMetaData.Sha != nextVersion.IncrementedVersion.BuildMetaData?.Sha) + if (baseVersionBuildMetaData.Sha != nextVersion.IncrementedVersion.BuildMetaData?.Sha) { semver = nextVersion.IncrementedVersion; }