Skip to content

Commit 25f1c53

Browse files
authored
Merge pull request #599 from ap0llo/master
Abort prepare-release command when version on current branch is not incremented
2 parents a6d49f3 + 48ef902 commit 25f1c53

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/NerdBank.GitVersioning.Tests/ReleaseManagerTests.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,30 @@ public void PrepareRelease_MasterWithVersionDecrement(string initialVersion, str
392392
this.WriteVersionFile(versionOptions);
393393

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

401+
[Theory]
402+
[InlineData("1.2", "1.2")]
403+
public void PrepareRelease_MasterWithoutVersionIncrement(string initialVersion, string nextVersion)
404+
{
405+
// create and configure repository
406+
this.InitializeSourceControl();
407+
408+
// create version.json
409+
var versionOptions = new VersionOptions() { Version = SemanticVersion.Parse(initialVersion) };
410+
this.WriteVersionFile(versionOptions);
411+
412+
// running PrepareRelease should result in an error
413+
// because we're trying to set master to the version it already has
414+
this.AssertError(
415+
() => new ReleaseManager().PrepareRelease(this.RepoPath, null, (nextVersion == null ? null : Version.Parse(nextVersion))),
416+
ReleasePreparationError.NoVersionIncrement);
417+
}
418+
401419
[Fact]
402420
public void PrepareRelease_DetachedHead()
403421
{

src/NerdBank.GitVersioning/ReleaseManager.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public enum ReleasePreparationError
4747
/// </summary>
4848
VersionDecrement,
4949

50+
/// <summary>
51+
/// Branch cannot be set to the specified version because the new version is not higher than the current version
52+
/// </summary>
53+
NoVersionIncrement,
54+
5055
/// <summary>
5156
/// Cannot create a branch because it already exists
5257
/// </summary>
@@ -273,6 +278,14 @@ public void PrepareRelease(string projectDirectory, string releaseUnstableTag =
273278

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

281+
// check if the current version on the current branch is different from the next version
282+
// otherwise, both the release branch and the dev branch would have the same version
283+
if (versionOptions.Version.Version == nextDevVersion.Version)
284+
{
285+
this.stderr.WriteLine($"Version on '{originalBranchName}' is already set to next version {nextDevVersion.Version}.");
286+
throw new ReleasePreparationException(ReleasePreparationError.NoVersionIncrement);
287+
}
288+
276289
// check if the release branch already exists
277290
if (repository.Branches[releaseBranchName] != null)
278291
{

src/nbgv/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ private static int OnPrepareReleaseCommand(string project, string nextVersion, s
736736
case ReleaseManager.ReleasePreparationError.NoVersionFile:
737737
return (int)ExitCodes.NoVersionJsonFound;
738738
case ReleaseManager.ReleasePreparationError.VersionDecrement:
739+
case ReleaseManager.ReleasePreparationError.NoVersionIncrement:
739740
return (int)ExitCodes.InvalidVersionSpec;
740741
case ReleaseManager.ReleasePreparationError.BranchAlreadyExists:
741742
return (int)ExitCodes.BranchAlreadyExists;

0 commit comments

Comments
 (0)