Skip to content

Commit

Permalink
Move comparison into SemanticVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
arturcic committed Dec 13, 2019
1 parent f6cbe6a commit 495ba8a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/GitVersionCore/SemanticVersioning/SemanticVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ public static bool TryParse(string version, string tagPrefixRegex, out SemanticV
}

public int CompareTo(SemanticVersion value)
{
return CompareTo(value, true);
}

public int CompareTo(SemanticVersion value, bool includePrerelease)
{
if (value == null)
{
Expand Down Expand Up @@ -213,7 +218,7 @@ public int CompareTo(SemanticVersion value)
}
return -1;
}
if (PreReleaseTag != value.PreReleaseTag)
if (includePrerelease && PreReleaseTag != value.PreReleaseTag)
{
if (PreReleaseTag > value.PreReleaseTag)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ public SemanticVersion FindVersion(GitVersionContext context)
if (taggedSemanticVersion != null)
{
// replace calculated version with tagged version only if tagged version greater or equal to calculated version
if (semver.Major > taggedSemanticVersion.Major ||
(semver.Major == taggedSemanticVersion.Major && semver.Minor > taggedSemanticVersion.Minor) ||
(semver.Major == taggedSemanticVersion.Major && semver.Minor == taggedSemanticVersion.Minor && semver.Patch > taggedSemanticVersion.Patch))
if (semver.CompareTo(taggedSemanticVersion, false) > 0)
{
taggedSemanticVersion = null;
}
Expand Down

0 comments on commit 495ba8a

Please sign in to comment.