Skip to content

Commit

Permalink
Reduce taggedSemanticVersion variable scope
Browse files Browse the repository at this point in the history
To simplify the method workflow.
  • Loading branch information
AlexPykavy committed Nov 24, 2022
1 parent 2712a69 commit a219a42
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,6 @@ public virtual NextVersion FindVersion()
EnsureHeadIsNotDetached(Context);
}

// TODO: It is totally unimportant that the current commit has been tagged or not IMO. We can make a double check actually if the result
// is the same or make it configurable but each run should be deterministic.Even if the development process goes on the tagged commit
// should always calculating the same result. Otherwise something is wrong with the configuration or someone messed up the branching history.

SemanticVersion? taggedSemanticVersion = null;

if (Context.IsCurrentCommitTagged)
{
// Will always be 0, don't bother with the +0 on tags
var semanticVersionBuildMetaData = this.mainlineVersionCalculator.CreateVersionBuildMetaData(Context.CurrentCommit!);
semanticVersionBuildMetaData.CommitsSinceTag = null;
var semanticVersion = new SemanticVersion(Context.CurrentCommitTaggedVersion) { BuildMetaData = semanticVersionBuildMetaData };
taggedSemanticVersion = semanticVersion;
}

//

var nextVersion = Calculate(Context.CurrentBranch, Context.Configuration);

SemanticVersion semver;
Expand Down Expand Up @@ -93,21 +76,29 @@ public virtual NextVersion FindVersion()
UpdatePreReleaseTag(new(nextVersion.Branch, nextVersion.Configuration), semver, nextVersion.BaseVersion.BranchNameOverride);
}

if (taggedSemanticVersion != null)
// TODO: It is totally unimportant that the current commit has been tagged or not IMO. We can make a double check actually if the result
// is the same or make it configurable but each run should be deterministic.Even if the development process goes on the tagged commit
// should always calculating the same result. Otherwise something is wrong with the configuration or someone messed up the branching history.

if (Context.IsCurrentCommitTagged)
{
// Will always be 0, don't bother with the +0 on tags
var semanticVersionBuildMetaData = this.mainlineVersionCalculator.CreateVersionBuildMetaData(Context.CurrentCommit!);
semanticVersionBuildMetaData.CommitsSinceTag = null;

SemanticVersion taggedSemanticVersion = new SemanticVersion(Context.CurrentCommitTaggedVersion) { BuildMetaData = semanticVersionBuildMetaData };

// replace calculated version with tagged version only if tagged version greater or equal to calculated version
if (semver.CompareTo(taggedSemanticVersion, false) > 0)
{
taggedSemanticVersion = null;
}
else if (taggedSemanticVersion.BuildMetaData != null)
if (taggedSemanticVersion.CompareTo(semver, false) >= 0)
{
// set the commit count on the tagged ver
taggedSemanticVersion.BuildMetaData.CommitsSinceVersionSource = semver.BuildMetaData?.CommitsSinceVersionSource;

semver = taggedSemanticVersion;
}
}

return new(taggedSemanticVersion ?? semver, nextVersion.BaseVersion, new(nextVersion.Branch, nextVersion.Configuration));
return new(semver, nextVersion.BaseVersion, new(nextVersion.Branch, nextVersion.Configuration));
}

private void UpdatePreReleaseTag(EffectiveBranchConfiguration configuration, SemanticVersion semanticVersion, string? branchNameOverride)
Expand Down

0 comments on commit a219a42

Please sign in to comment.