From 4664ed916c7f4f8530fe107abb523c2d84166862 Mon Sep 17 00:00:00 2001 From: HHobeck Date: Mon, 19 Feb 2024 16:04:01 +0100 Subject: [PATCH] Removing Contract.Assume --- src/GitVersion.Core/Git/ReferenceName.cs | 3 --- .../ContinuousDeliveryVersionCalculator.cs | 8 ++------ .../ContinuousDeploymentVersionCalculator.cs | 4 +--- .../ManualDeploymentVersionCalculator.cs | 2 -- 4 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/GitVersion.Core/Git/ReferenceName.cs b/src/GitVersion.Core/Git/ReferenceName.cs index 8aeb350104..601ddc1348 100644 --- a/src/GitVersion.Core/Git/ReferenceName.cs +++ b/src/GitVersion.Core/Git/ReferenceName.cs @@ -1,5 +1,4 @@ using System.Diagnostics.CodeAnalysis; -using System.Diagnostics.Contracts; using System.Text.RegularExpressions; using GitVersion.Extensions; using GitVersion.Helpers; @@ -85,8 +84,6 @@ public bool TryGetSemanticVersion([NotNullWhen(true)] out (SemanticVersion Value { result = default; - Contract.Assume(versionPatternRegex.ToString().StartsWith('^')); - int length = 0; foreach (var branchPart in WithoutOrigin.Split(GetBranchSeparator())) { diff --git a/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeliveryVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeliveryVersionCalculator.cs index 579f50eca2..8e90c0e432 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeliveryVersionCalculator.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeliveryVersionCalculator.cs @@ -1,4 +1,3 @@ -using System.Diagnostics.Contracts; using GitVersion.Common; using GitVersion.Logging; @@ -23,20 +22,17 @@ public SemanticVersion Calculate(SemanticVersion semanticVersion, ICommit? baseV private SemanticVersion CalculateInternal(SemanticVersion semanticVersion, ICommit? baseVersionSource) { - Contract.Assume(semanticVersion.PreReleaseTag.Number.HasValue); - var buildMetaData = CreateVersionBuildMetaData(baseVersionSource); - Contract.Assume(buildMetaData.CommitsSinceTag.HasValue); return new SemanticVersion(semanticVersion) { PreReleaseTag = new SemanticVersionPreReleaseTag(semanticVersion.PreReleaseTag) { - Number = semanticVersion.PreReleaseTag.Number.Value + buildMetaData.CommitsSinceTag - 1 + Number = semanticVersion.PreReleaseTag.Number!.Value + buildMetaData.CommitsSinceTag - 1 }, BuildMetaData = new SemanticVersionBuildMetaData(buildMetaData) { - CommitsSinceVersionSource = buildMetaData.CommitsSinceTag.Value, + CommitsSinceVersionSource = buildMetaData.CommitsSinceTag!.Value, CommitsSinceTag = null } }; diff --git a/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeploymentVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeploymentVersionCalculator.cs index c89baeec34..7ed5b72042 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeploymentVersionCalculator.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionCalculators/ContinuousDeploymentVersionCalculator.cs @@ -1,4 +1,3 @@ -using System.Diagnostics.Contracts; using GitVersion.Common; using GitVersion.Logging; @@ -18,14 +17,13 @@ public SemanticVersion Calculate(SemanticVersion semanticVersion, ICommit? baseV private SemanticVersion CalculateInternal(SemanticVersion semanticVersion, ICommit? baseVersionSource) { var buildMetaData = CreateVersionBuildMetaData(baseVersionSource); - Contract.Assume(buildMetaData.CommitsSinceTag.HasValue); return new SemanticVersion(semanticVersion) { PreReleaseTag = SemanticVersionPreReleaseTag.Empty, BuildMetaData = new SemanticVersionBuildMetaData(buildMetaData) { - CommitsSinceVersionSource = buildMetaData.CommitsSinceTag.Value, + CommitsSinceVersionSource = buildMetaData.CommitsSinceTag!.Value, CommitsSinceTag = null } }; diff --git a/src/GitVersion.Core/VersionCalculation/VersionCalculators/ManualDeploymentVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/VersionCalculators/ManualDeploymentVersionCalculator.cs index e4a6c6afeb..842bc6ad74 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionCalculators/ManualDeploymentVersionCalculator.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionCalculators/ManualDeploymentVersionCalculator.cs @@ -1,4 +1,3 @@ -using System.Diagnostics.Contracts; using GitVersion.Common; using GitVersion.Logging; @@ -18,7 +17,6 @@ public SemanticVersion Calculate(SemanticVersion semanticVersion, ICommit? baseV private SemanticVersion CalculateInternal(SemanticVersion semanticVersion, ICommit? baseVersionSource) { var buildMetaData = CreateVersionBuildMetaData(baseVersionSource); - Contract.Assume(buildMetaData.CommitsSinceTag.HasValue); return new SemanticVersion(semanticVersion) {