Skip to content

Commit f5ebe41

Browse files
committed
remove need for empty
1 parent 2d602c3 commit f5ebe41

File tree

8 files changed

+30
-52
lines changed

8 files changed

+30
-52
lines changed

GitVersionCore.Tests/SemanticVersionTests.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,6 @@ public void VersionSorting()
6767
SemanticVersion.Parse("1.0.0").ShouldBeGreaterThan(SemanticVersion.Parse("1.0.0-beta"));
6868
}
6969

70-
[Test]
71-
public void EmptyVersion()
72-
{
73-
Assert.IsTrue(SemanticVersion.Empty.IsEmpty());
74-
75-
var emptyVersion = new SemanticVersion();
76-
Assert.IsTrue(emptyVersion.IsEmpty());
77-
}
7870
[Test]
7971
public void ToStringJTests()
8072
{

GitVersionCore/GitFlow/BranchFinders/MasterVersionFinder.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,12 @@ public SemanticVersion FindVersion(IRepository repository, Commit tip)
1515
}
1616
}
1717

18-
var semanticVersion = new SemanticVersion();
19-
2018
ShortVersion versionFromTip;
2119
if (MergeMessageParser.TryParse(tip, out versionFromTip))
2220
{
23-
semanticVersion = BuildVersion(tip, versionFromTip);
21+
return BuildVersion(tip, versionFromTip);
2422
}
25-
26-
if (semanticVersion == null || semanticVersion.IsEmpty())
27-
{
28-
throw new WarningException("The head of master should always be a merge commit if you follow gitflow. Please create one or work around this by tagging the commit with SemVer compatible Id.");
29-
}
30-
31-
return semanticVersion;
23+
throw new WarningException("The head of master should always be a merge commit if you follow gitflow. Please create one or work around this by tagging the commit with SemVer compatible Id.");
3224
}
3325

3426
SemanticVersion BuildVersion(Commit tip, ShortVersion shortVersion)

GitVersionCore/GitFlow/BranchFinders/SupportVersionFinder.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,21 @@ public SemanticVersion FindVersion(IRepository repository, Commit tip)
88
{
99
foreach (var tag in repository.TagsByDate(tip))
1010
{
11-
ShortVersion shortVersion;
12-
if (ShortVersionParser.TryParse(tag.Name, out shortVersion))
11+
ShortVersion shortVersion;
12+
if (ShortVersionParser.TryParse(tag.Name, out shortVersion))
1313
{
1414
return BuildVersion(tip, shortVersion);
1515
}
1616
}
1717

18-
var semanticVersion = new SemanticVersion();
19-
2018
ShortVersion versionFromTip;
2119
if (MergeMessageParser.TryParse(tip, out versionFromTip))
2220
{
23-
semanticVersion = BuildVersion(tip, versionFromTip);
24-
}
25-
26-
semanticVersion.OverrideVersionManuallyIfNeeded(repository);
27-
28-
if (semanticVersion == null || semanticVersion.IsEmpty())
29-
{
30-
throw new WarningException("The head of a support branch should always be a merge commit if you follow gitflow. Please create one or work around this by tagging the commit with SemVer compatible Id.");
21+
var semanticVersion = BuildVersion(tip, versionFromTip);
22+
semanticVersion.OverrideVersionManuallyIfNeeded(repository);
23+
return semanticVersion;
3124
}
32-
33-
return semanticVersion;
25+
throw new WarningException("The head of a support branch should always be a merge commit if you follow gitflow. Please create one or work around this by tagging the commit with SemVer compatible Id.");
3426
}
3527

3628
SemanticVersion BuildVersion(Commit tip, ShortVersion shortVersion)

GitVersionCore/GitHubFlow/NextSemverCalculator.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace GitVersion
22
{
3+
using System.Collections.Generic;
34
using System.Linq;
45

56
public class NextSemverCalculator
@@ -26,13 +27,21 @@ public SemanticVersion NextVersion()
2627
{
2728
var versionZero = new SemanticVersion();
2829
var lastRelease = lastTaggedReleaseFinder.GetVersion();
29-
var fileVersion = nextVersionTxtFileFinder.GetNextVersion();
30-
var mergedBranchVersion = mergedBranchesWithVersionFinder.GetVersion();
30+
var versions = new List<SemanticVersion>();
31+
SemanticVersion fileVersion;
32+
if(nextVersionTxtFileFinder.TryGetNextVersion(out fileVersion))
33+
{
34+
versions.Add(fileVersion);
35+
}
36+
versions.Add(mergedBranchesWithVersionFinder.GetVersion());
3137
var otherBranchVersion = unknownBranchFinder.FindVersion(context);
3238
if (otherBranchVersion != null && otherBranchVersion.PreReleaseTag != null && otherBranchVersion.PreReleaseTag.Name == "release")
39+
{
3340
otherBranchVersion.PreReleaseTag.Name = "beta";
41+
}
42+
versions.Add(otherBranchVersion);
3443

35-
var maxCalculated = new[] { fileVersion, otherBranchVersion, mergedBranchVersion }.Max();
44+
var maxCalculated = versions.Max();
3645

3746
if (lastRelease.SemVer == versionZero && maxCalculated == versionZero)
3847
{

GitVersionCore/GitHubFlow/NextVersionTxtFileFinder.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,29 @@ public NextVersionTxtFileFinder(string repositoryDirectory)
1212
this.repositoryDirectory = repositoryDirectory;
1313
}
1414

15-
public SemanticVersion GetNextVersion()
15+
public bool TryGetNextVersion(out SemanticVersion semanticVersion)
1616
{
1717
var filePath = Path.Combine(repositoryDirectory, "NextVersion.txt");
1818
if (!File.Exists(filePath))
1919
{
20-
return new SemanticVersion();
20+
semanticVersion = null;
21+
return false;
2122
}
2223

2324
var version = File.ReadAllText(filePath);
2425
if (string.IsNullOrEmpty(version))
2526
{
26-
return new SemanticVersion();
27+
semanticVersion = null;
28+
return false;
2729
}
2830

29-
SemanticVersion semanticVersion;
3031
if (!SemanticVersion.TryParse(version, out semanticVersion))
3132
{
3233
throw new ArgumentException("Make sure you have a valid semantic version in NextVersion.txt");
3334
}
3435

35-
return semanticVersion;
36+
37+
return true;
3638
}
3739
}
3840
}

GitVersionCore/SemanticVersion.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ namespace GitVersion
55

66
public class SemanticVersion : IFormattable, IComparable<SemanticVersion>
77
{
8-
public static SemanticVersion Empty = new SemanticVersion();
9-
108
static Regex ParseSemVer = new Regex(
119
@"[vV]?(?<SemVer>(?<Major>\d+)(\.(?<Minor>\d+))?(\.(?<Patch>\d+))?)(\.(?<FourthPart>\d+))?(-(?<Tag>[^\+]*))?(\+(?<BuildMetaData>.*))?",
1210
RegexOptions.Compiled);
@@ -36,11 +34,6 @@ public bool Equals(SemanticVersion obj)
3634
BuildMetaData == obj.BuildMetaData;
3735
}
3836

39-
public bool IsEmpty()
40-
{
41-
return Equals(Empty);
42-
}
43-
4437
public static bool operator ==(SemanticVersion v1, SemanticVersion v2)
4538
{
4639
if (ReferenceEquals(v1, null))

GitVersionCore/SemanticVersionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ public static class SemanticVersionExtensions
77
public static void OverrideVersionManuallyIfNeeded(this SemanticVersion version, IRepository repository)
88
{
99
var nextVersionTxtFileFinder = new NextVersionTxtFileFinder(repository.GetRepositoryDirectory());
10-
var manualNextVersion = nextVersionTxtFileFinder.GetNextVersion();
11-
if (!manualNextVersion.IsEmpty())
10+
SemanticVersion manualNextVersion ;
11+
if (nextVersionTxtFileFinder.TryGetNextVersion(out manualNextVersion))
1212
{
1313
if (manualNextVersion > version)
1414
{
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
{
22
"Major": 0,
3-
"Minor": 3,
4-
"Timestamp": "2000-10-09T23:59:58Z",
5-
"CommitSha": "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
3+
"Minor": 3
64
}

0 commit comments

Comments
 (0)