Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 19 additions & 1 deletion src/NerdBank.GitVersioning.Tests/ReleaseManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,30 @@ public void PrepareRelease_MasterWithVersionDecrement(string initialVersion, str
this.WriteVersionFile(versionOptions);

// running PrepareRelease should result in an error
// because we're trying to add a prerelease tag to a version without prerelease tag
// because we're setting the version on master to a lower version
this.AssertError(
() => new ReleaseManager().PrepareRelease(this.RepoPath, releaseUnstableTag, (nextVersion == null ? null : Version.Parse(nextVersion))),
ReleasePreparationError.VersionDecrement);
}

[Theory]
[InlineData("1.2", "1.2")]
public void PrepareRelease_MasterWithoutVersionIncrement(string initialVersion, string nextVersion)
{
// create and configure repository
this.InitializeSourceControl();

// create version.json
var versionOptions = new VersionOptions() { Version = SemanticVersion.Parse(initialVersion) };
this.WriteVersionFile(versionOptions);

// running PrepareRelease should result in an error
// because we're trying to set master to the version it already has
this.AssertError(
() => new ReleaseManager().PrepareRelease(this.RepoPath, null, (nextVersion == null ? null : Version.Parse(nextVersion))),
ReleasePreparationError.NoVersionIncrement);
}

[Fact]
public void PrepareRelease_DetachedHead()
{
Expand Down
13 changes: 13 additions & 0 deletions src/NerdBank.GitVersioning/ReleaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public enum ReleasePreparationError
/// </summary>
VersionDecrement,

/// <summary>
/// Branch cannot be set to the specified version because the new version is not higher than the current version
/// </summary>
NoVersionIncrement,

/// <summary>
/// Cannot create a branch because it already exists
/// </summary>
Expand Down Expand Up @@ -273,6 +278,14 @@ public void PrepareRelease(string projectDirectory, string releaseUnstableTag =

var nextDevVersion = this.GetNextDevVersion(versionOptions, nextVersion, versionIncrement);

// check if the current version on the main branch is different from the next version
// otherwise, both the release branch and the dev branch would have the same version
if (versionOptions.Version.Version == nextDevVersion.Version)
{
this.stderr.WriteLine($"Version on '{originalBranchName}' is already set to next version {nextDevVersion.Version}.");
throw new ReleasePreparationException(ReleasePreparationError.NoVersionIncrement);
}

// check if the release branch already exists
if (repository.Branches[releaseBranchName] != null)
{
Expand Down
1 change: 1 addition & 0 deletions src/nbgv/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ private static int OnPrepareReleaseCommand(string project, string nextVersion, s
case ReleaseManager.ReleasePreparationError.NoVersionFile:
return (int)ExitCodes.NoVersionJsonFound;
case ReleaseManager.ReleasePreparationError.VersionDecrement:
case ReleaseManager.ReleasePreparationError.NoVersionIncrement:
return (int)ExitCodes.InvalidVersionSpec;
case ReleaseManager.ReleasePreparationError.BranchAlreadyExists:
return (int)ExitCodes.BranchAlreadyExists;
Expand Down