Skip to content

Support nextversion in config #307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions GitVersionCore.Tests/IntegrationTests/GitHubFlow/MasterTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using GitVersion;
using System;
using GitVersion;
using LibGit2Sharp;
using NUnit.Framework;
using Shouldly;

[TestFixture]
public class MasterTests
Expand Down Expand Up @@ -69,6 +71,31 @@ public void GivenARepositoryWithTagAndANextVersionTxtFile_VersionShouldMatchVers
}
}

[Test]
public void GivenARepositoryWithTagAndNextVersionInConfig_VersionShouldMatchVersionTxtFile()
{
const string ExpectedNextVersion = "1.1.0";
using (var fixture = new EmptyRepositoryFixture(new Config { NextVersion = ExpectedNextVersion }))
{
const string TaggedVersion = "1.0.3";
fixture.Repository.MakeATaggedCommit(TaggedVersion);
fixture.Repository.MakeCommits(5);

fixture.AssertFullSemver("1.1.0+5");
}
}

[Test]
public void GivenARepositoryWithANextVersionTxtFileAndNextVersionInConfig_ErrorIsThrown()
{
using (var fixture = new EmptyRepositoryFixture(new Config { NextVersion = "1.1.0" }))
{
fixture.Repository.AddNextVersionTxtFile("1.1.0");

Should.Throw<Exception>(() => fixture.AssertFullSemver("1.1.0+5"));
}
}

[Test]
public void GivenARepositoryWithTagAndANextVersionTxtFileAndNoCommits_VersionShouldBeTag()
{
Expand Down Expand Up @@ -123,6 +150,20 @@ public void GivenARepositoryWithTagAndOldNextVersionTxtFile_VersionShouldBeTagWi
}
}

[Test]
public void GivenARepositoryWithTagAndOldNextVersionConfig_VersionShouldBeTagWithBumpedPatch()
{
const string NextVersionConfig = "1.0.0";
using (var fixture = new EmptyRepositoryFixture(new Config { NextVersion = NextVersionConfig }))
{
const string TaggedVersion = "1.1.0";
fixture.Repository.MakeATaggedCommit(TaggedVersion);
fixture.Repository.MakeCommits(5);

fixture.AssertFullSemver("1.1.1+5");
}
}

[Test]
public void GivenARepositoryWithTagAndOldNextVersionTxtFileAndNoCommits_VersionShouldBeTag()
{
Expand All @@ -140,7 +181,7 @@ public void GivenARepositoryWithTagAndOldNextVersionTxtFileAndNoCommits_VersionS
[Test]
public void CanSpecifyTagPrefixes()
{
using (var fixture = new EmptyRepositoryFixture(new Config{ TagPrefix = "version-"}))
using (var fixture = new EmptyRepositoryFixture(new Config { TagPrefix = "version-" }))
{
const string TaggedVersion = "version-1.0.3";
fixture.Repository.MakeATaggedCommit(TaggedVersion);
Expand All @@ -153,7 +194,7 @@ public void CanSpecifyTagPrefixes()
[Test]
public void CanSpecifyTagPrefixesAsRegex()
{
using (var fixture = new EmptyRepositoryFixture(new Config{ TagPrefix = "[version-|v]"}))
using (var fixture = new EmptyRepositoryFixture(new Config { TagPrefix = "[version-|v]" }))
{
const string TaggedVersion = "v1.0.3";
fixture.Repository.MakeATaggedCommit(TaggedVersion);
Expand Down
5 changes: 4 additions & 1 deletion GitVersionCore/Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public Config()
AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch;
DevelopBranchTag = "unstable";
ReleaseBranchTag = "beta";
TagPrefix = "v";
TagPrefix = "[vV]";
}

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

[YamlAlias("tag-prefix")]
public string TagPrefix { get; set; }

[YamlAlias("next-version")]
public string NextVersion { get; set; }
}
}
15 changes: 14 additions & 1 deletion GitVersionCore/GitHubFlow/NextSemverCalculator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace GitVersion
{
using System;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -58,10 +59,22 @@ public IEnumerable<SemanticVersion> GetPossibleVersions()
}

SemanticVersion fileVersion;
if (nextVersionTxtFileFinder.TryGetNextVersion(out fileVersion))
var hasNextVersionTxtVersion = nextVersionTxtFileFinder.TryGetNextVersion(out fileVersion);
if (hasNextVersionTxtVersion && !string.IsNullOrEmpty(context.Configuration.NextVersion))
{
throw new Exception("You cannot specify a next version in both NextVersion.txt and GitVersionConfig.yaml. Please delete NextVersion.txt and use GitVersionConfig.yaml");
}

if (!string.IsNullOrEmpty(context.Configuration.NextVersion))
{
yield return SemanticVersion.Parse(context.Configuration.NextVersion, context.Configuration.TagPrefix);
}

if (hasNextVersionTxtVersion)
{
yield return fileVersion;
}

SemanticVersion tryGetVersion;
if (mergedBranchesWithVersionFinder.TryGetVersion(out tryGetVersion))
{
Expand Down
8 changes: 8 additions & 0 deletions GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class UpdateAssemblyInfo : Task

public string TagPrefix { get; set; }

public string NextVersion { get; set; }

[Required]
public string SolutionDirectory { get; set; }

Expand Down Expand Up @@ -87,6 +89,7 @@ public void InnerExecute()
}

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

if (NextVersion != null)
{
configuration.NextVersion = NextVersion;
}

CachedVersion semanticVersion;
if (!VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out semanticVersion, configuration))
{
Expand Down
7 changes: 7 additions & 0 deletions GitVersionTask/GetVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public class GetVersion : Task

public string TagPrefix { get; set; }

public string NextVersion { get; set; }

TaskLogger logger;

public GetVersion()
Expand Down Expand Up @@ -114,6 +116,11 @@ public override bool Execute()
configuration.TagPrefix = TagPrefix;
}

if (NextVersion != null)
{
configuration.NextVersion = NextVersion;
}

if (VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out versionAndBranch, configuration))
{
var thisType = typeof(GetVersion);
Expand Down