Skip to content

Commit 663b748

Browse files
author
Guillaume Rouchon
committed
Scoped prerelease number to prerelease label
1 parent 2bbe5bb commit 663b748

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

src/GitVersionCore.Tests/VersionCalculation/NextVersionCalculatorTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
namespace GitVersionCore.Tests.VersionCalculation
22
{
33
using System;
4+
using System.Collections.Generic;
45
using GitVersion;
56
using GitVersion.VersionCalculation;
7+
using LibGit2Sharp;
68
using NUnit.Framework;
79
using Shouldly;
810

@@ -94,5 +96,32 @@ public void PreReleaseTagCanUseBranchNameVariable()
9496

9597
version.ToString("f").ShouldBe("1.0.0-alpha.foo.1+2");
9698
}
99+
100+
[Test]
101+
public void PreReleaseNumberShouldBeScopeToPreReleaseLabelInContinuousDelivery()
102+
{
103+
var config = new Config();
104+
config.VersioningMode = VersioningMode.ContinuousDelivery;
105+
config.Branches = new Dictionary<string, BranchConfig> {
106+
{ "master", new BranchConfig() { Tag = "beta" } },
107+
};
108+
109+
using (var fixture = new EmptyRepositoryFixture(config))
110+
{
111+
fixture.Repository.MakeACommit();
112+
113+
fixture.Repository.CreateBranch("feature/test");
114+
fixture.Repository.Checkout("feature/test");
115+
fixture.Repository.MakeATaggedCommit("0.1.0-test.1");
116+
fixture.Repository.MakeACommit();
117+
118+
fixture.AssertFullSemver("0.1.0-test.2+2");
119+
120+
fixture.Repository.Checkout("master");
121+
fixture.Repository.Merge(fixture.Repository.FindBranch("feature/test"), Constants.SignatureNow());
122+
123+
fixture.AssertFullSemver("0.1.0-beta.1+2");
124+
}
125+
}
97126
}
98127
}

src/GitVersionCore/LibGitExtensions.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static Branch FindBranch(this IRepository repository, string branchName)
2929
return repository.Branches.FirstOrDefault(x => x.Name == "origin/" + branchName);
3030
}
3131

32-
public static SemanticVersion LastVersionTagOnBranch(this Branch branch, IRepository repository, string tagPrefixRegex)
32+
public static IEnumerable<SemanticVersion> GetVersionTagsOnBranch(this Branch branch, IRepository repository, string tagPrefixRegex)
3333
{
3434
var tags = repository.Tags.Select(t => t).ToList();
3535

@@ -43,8 +43,7 @@ public static SemanticVersion LastVersionTagOnBranch(this Branch branch, IReposi
4343
if (SemanticVersion.TryParse(t.Name, tagPrefixRegex, out semver))
4444
return new [] { semver };
4545
return new SemanticVersion[0];
46-
}))
47-
.FirstOrDefault();
46+
}));
4847
}
4948

5049

src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs

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

@@ -98,7 +99,10 @@ void UpdatePreReleaseTag(GitVersionContext context, SemanticVersion semanticVers
9899
}
99100
}
100101

101-
var lastTag = context.CurrentBranch.LastVersionTagOnBranch(context.Repository, context.Configuration.GitTagPrefix);
102+
var lastTag = context.CurrentBranch
103+
.GetVersionTagsOnBranch(context.Repository, context.Configuration.GitTagPrefix)
104+
.FirstOrDefault(v => v.PreReleaseTag.Name == tagToUse);
105+
102106
if (number == null &&
103107
lastTag != null &&
104108
MajorMinorPatchEqual(lastTag, semanticVersion) &&

0 commit comments

Comments
 (0)