Skip to content

Commit e1baf9a

Browse files
committed
Merge pull request #307 from JakeGinnivan/NextVersionConfig
Support nextversion in config
2 parents ad9738e + 9f7761f commit e1baf9a

File tree

5 files changed

+77
-5
lines changed

5 files changed

+77
-5
lines changed

GitVersionCore.Tests/IntegrationTests/GitHubFlow/MasterTests.cs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
using GitVersion;
1+
using System;
2+
using GitVersion;
23
using LibGit2Sharp;
34
using NUnit.Framework;
5+
using Shouldly;
46

57
[TestFixture]
68
public class MasterTests
@@ -69,6 +71,31 @@ public void GivenARepositoryWithTagAndANextVersionTxtFile_VersionShouldMatchVers
6971
}
7072
}
7173

74+
[Test]
75+
public void GivenARepositoryWithTagAndNextVersionInConfig_VersionShouldMatchVersionTxtFile()
76+
{
77+
const string ExpectedNextVersion = "1.1.0";
78+
using (var fixture = new EmptyRepositoryFixture(new Config { NextVersion = ExpectedNextVersion }))
79+
{
80+
const string TaggedVersion = "1.0.3";
81+
fixture.Repository.MakeATaggedCommit(TaggedVersion);
82+
fixture.Repository.MakeCommits(5);
83+
84+
fixture.AssertFullSemver("1.1.0+5");
85+
}
86+
}
87+
88+
[Test]
89+
public void GivenARepositoryWithANextVersionTxtFileAndNextVersionInConfig_ErrorIsThrown()
90+
{
91+
using (var fixture = new EmptyRepositoryFixture(new Config { NextVersion = "1.1.0" }))
92+
{
93+
fixture.Repository.AddNextVersionTxtFile("1.1.0");
94+
95+
Should.Throw<Exception>(() => fixture.AssertFullSemver("1.1.0+5"));
96+
}
97+
}
98+
7299
[Test]
73100
public void GivenARepositoryWithTagAndANextVersionTxtFileAndNoCommits_VersionShouldBeTag()
74101
{
@@ -123,6 +150,20 @@ public void GivenARepositoryWithTagAndOldNextVersionTxtFile_VersionShouldBeTagWi
123150
}
124151
}
125152

153+
[Test]
154+
public void GivenARepositoryWithTagAndOldNextVersionConfig_VersionShouldBeTagWithBumpedPatch()
155+
{
156+
const string NextVersionConfig = "1.0.0";
157+
using (var fixture = new EmptyRepositoryFixture(new Config { NextVersion = NextVersionConfig }))
158+
{
159+
const string TaggedVersion = "1.1.0";
160+
fixture.Repository.MakeATaggedCommit(TaggedVersion);
161+
fixture.Repository.MakeCommits(5);
162+
163+
fixture.AssertFullSemver("1.1.1+5");
164+
}
165+
}
166+
126167
[Test]
127168
public void GivenARepositoryWithTagAndOldNextVersionTxtFileAndNoCommits_VersionShouldBeTag()
128169
{
@@ -140,7 +181,7 @@ public void GivenARepositoryWithTagAndOldNextVersionTxtFileAndNoCommits_VersionS
140181
[Test]
141182
public void CanSpecifyTagPrefixes()
142183
{
143-
using (var fixture = new EmptyRepositoryFixture(new Config{ TagPrefix = "version-"}))
184+
using (var fixture = new EmptyRepositoryFixture(new Config { TagPrefix = "version-" }))
144185
{
145186
const string TaggedVersion = "version-1.0.3";
146187
fixture.Repository.MakeATaggedCommit(TaggedVersion);
@@ -153,7 +194,7 @@ public void CanSpecifyTagPrefixes()
153194
[Test]
154195
public void CanSpecifyTagPrefixesAsRegex()
155196
{
156-
using (var fixture = new EmptyRepositoryFixture(new Config{ TagPrefix = "[version-|v]"}))
197+
using (var fixture = new EmptyRepositoryFixture(new Config { TagPrefix = "[version-|v]" }))
157198
{
158199
const string TaggedVersion = "v1.0.3";
159200
fixture.Repository.MakeATaggedCommit(TaggedVersion);

GitVersionCore/Configuration/Config.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public Config()
99
AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch;
1010
DevelopBranchTag = "unstable";
1111
ReleaseBranchTag = "beta";
12-
TagPrefix = "v";
12+
TagPrefix = "[vV]";
1313
}
1414

1515
public AssemblyVersioningScheme AssemblyVersioningScheme { get; set; }
@@ -22,5 +22,8 @@ public Config()
2222

2323
[YamlAlias("tag-prefix")]
2424
public string TagPrefix { get; set; }
25+
26+
[YamlAlias("next-version")]
27+
public string NextVersion { get; set; }
2528
}
2629
}

GitVersionCore/GitHubFlow/NextSemverCalculator.cs

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

@@ -58,10 +59,22 @@ public IEnumerable<SemanticVersion> GetPossibleVersions()
5859
}
5960

6061
SemanticVersion fileVersion;
61-
if (nextVersionTxtFileFinder.TryGetNextVersion(out fileVersion))
62+
var hasNextVersionTxtVersion = nextVersionTxtFileFinder.TryGetNextVersion(out fileVersion);
63+
if (hasNextVersionTxtVersion && !string.IsNullOrEmpty(context.Configuration.NextVersion))
64+
{
65+
throw new Exception("You cannot specify a next version in both NextVersion.txt and GitVersionConfig.yaml. Please delete NextVersion.txt and use GitVersionConfig.yaml");
66+
}
67+
68+
if (!string.IsNullOrEmpty(context.Configuration.NextVersion))
69+
{
70+
yield return SemanticVersion.Parse(context.Configuration.NextVersion, context.Configuration.TagPrefix);
71+
}
72+
73+
if (hasNextVersionTxtVersion)
6274
{
6375
yield return fileVersion;
6476
}
77+
6578
SemanticVersion tryGetVersion;
6679
if (mergedBranchesWithVersionFinder.TryGetVersion(out tryGetVersion))
6780
{

GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public class UpdateAssemblyInfo : Task
1717

1818
public string TagPrefix { get; set; }
1919

20+
public string NextVersion { get; set; }
21+
2022
[Required]
2123
public string SolutionDirectory { get; set; }
2224

@@ -87,6 +89,7 @@ public void InnerExecute()
8789
}
8890

8991
// TODO This should be covered by tests
92+
// TODO would be good to not have to duplicate this in both msbuild tasks
9093
// Null is intentional. Empty string means the user has set the value to an empty string and wants to clear the tag
9194
if (DevelopBranchTag != null)
9295
{
@@ -103,6 +106,11 @@ public void InnerExecute()
103106
configuration.TagPrefix = TagPrefix;
104107
}
105108

109+
if (NextVersion != null)
110+
{
111+
configuration.NextVersion = NextVersion;
112+
}
113+
106114
CachedVersion semanticVersion;
107115
if (!VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out semanticVersion, configuration))
108116
{

GitVersionTask/GetVersion.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public class GetVersion : Task
8080

8181
public string TagPrefix { get; set; }
8282

83+
public string NextVersion { get; set; }
84+
8385
TaskLogger logger;
8486

8587
public GetVersion()
@@ -114,6 +116,11 @@ public override bool Execute()
114116
configuration.TagPrefix = TagPrefix;
115117
}
116118

119+
if (NextVersion != null)
120+
{
121+
configuration.NextVersion = NextVersion;
122+
}
123+
117124
if (VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out versionAndBranch, configuration))
118125
{
119126
var thisType = typeof(GetVersion);

0 commit comments

Comments
 (0)