Skip to content

Commit 50833b4

Browse files
committed
Merge branch 'AddressTagParsing'
2 parents bec5eb5 + 140b790 commit 50833b4

File tree

9 files changed

+99
-35
lines changed

9 files changed

+99
-35
lines changed

GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
assembly-versioning-scheme: MajorMinorPatch
22
mode: ContinuousDelivery
3-
tag-prefix: '[vV]'
3+
tag-prefix: '[vV]|'
44
continuous-delivery-fallback-tag: ci
55
branches:
66
master:

GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void CanReadDefaultDocument()
120120
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch);
121121
config.Branches["develop"].Tag.ShouldBe("unstable");
122122
config.Branches["release[/-]"].Tag.ShouldBe("beta");
123-
config.TagPrefix.ShouldBe("[vV]");
123+
config.TagPrefix.ShouldBe("[vV]|");
124124
config.NextVersion.ShouldBe(null);
125125
}
126126

GitVersionCore.Tests/Fixtures/RepositoryFixtureBase.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,23 @@ protected RepositoryFixtureBase(Func<string, IRepository> repoBuilder, Config co
2525
public void AssertFullSemver(string fullSemver, IRepository repository = null, string commitId = null)
2626
{
2727
Trace.WriteLine("---------");
28+
29+
var variables = GetVersion(repository, commitId);
30+
variables.FullSemVer.ShouldBe(fullSemver);
31+
}
32+
33+
public VersionVariables GetVersion(IRepository repository = null, string commitId = null)
34+
{
2835
var gitVersionContext = new GitVersionContext(repository ?? Repository, configuration, IsForTrackedBranchOnly, commitId);
2936
var executeGitVersion = ExecuteGitVersion(gitVersionContext);
30-
var variables = VariableProvider.GetVariablesFor(executeGitVersion,
37+
var variables = VariableProvider.GetVariablesFor(executeGitVersion,
3138
gitVersionContext.Configuration.AssemblyVersioningScheme,
32-
gitVersionContext.Configuration.VersioningMode,
39+
gitVersionContext.Configuration.VersioningMode,
3340
gitVersionContext.Configuration.ContinuousDeploymentFallbackTag,
3441
gitVersionContext.IsCurrentCommitTagged);
3542
try
3643
{
37-
variables.FullSemVer.ShouldBe(fullSemver);
44+
return variables;
3845
}
3946
catch (Exception)
4047
{

GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@
145145
<Content Include="FodyWeavers.xml" />
146146
<Content Include="JsonVersionBuilderTests.Json.approved.txt" />
147147
</ItemGroup>
148-
<ItemGroup />
148+
<ItemGroup>
149+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
150+
</ItemGroup>
149151
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
150152
<PropertyGroup>
151153
<PostBuildEvent>

GitVersionCore.Tests/IntegrationTests/MasterScenarios.cs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,61 @@ public void CanSpecifyTagPrefixes()
145145

146146
fixture.AssertFullSemver("1.0.4+5");
147147
}
148-
}
148+
}
149149

150150
[Test]
151151
public void CanSpecifyTagPrefixesAsRegex()
152152
{
153-
using (var fixture = new EmptyRepositoryFixture(new Config { TagPrefix = "[version-|v]" }))
153+
using (var fixture = new EmptyRepositoryFixture(new Config { TagPrefix = "version-|[vV]" }))
154+
{
155+
string TaggedVersion = "v1.0.3";
156+
fixture.Repository.MakeATaggedCommit(TaggedVersion);
157+
fixture.Repository.MakeCommits(5);
158+
159+
fixture.AssertFullSemver("1.0.4+5");
160+
161+
TaggedVersion = "version-1.0.5";
162+
fixture.Repository.MakeATaggedCommit(TaggedVersion);
163+
fixture.Repository.MakeCommits(5);
164+
165+
fixture.AssertFullSemver("1.0.6+5");
166+
}
167+
}
168+
169+
[Test]
170+
public void CanTagPrefixStillBeOptional()
171+
{
172+
using (var fixture = new EmptyRepositoryFixture(new Config { TagPrefix = "[vV]|" })) //we use tag prefix to denote whether optional
154173
{
155-
const string TaggedVersion = "v1.0.3";
174+
string TaggedVersion = "v1.0.3";
156175
fixture.Repository.MakeATaggedCommit(TaggedVersion);
157176
fixture.Repository.MakeCommits(5);
158177

159178
fixture.AssertFullSemver("1.0.4+5");
179+
180+
TaggedVersion = "1.0.5";
181+
fixture.Repository.MakeATaggedCommit(TaggedVersion);
182+
fixture.Repository.MakeCommits(1);
183+
184+
fixture.AssertFullSemver("1.0.6+1");
185+
}
186+
}
187+
188+
[Test]
189+
public void AreTagsNotAdheringToTagPrefixIgnored()
190+
{
191+
using (var fixture = new EmptyRepositoryFixture(new Config { TagPrefix = "" }))
192+
{
193+
string TaggedVersion = "version-1.0.3";
194+
fixture.Repository.MakeATaggedCommit(TaggedVersion);
195+
fixture.Repository.MakeCommits(5);
196+
197+
fixture.AssertFullSemver("0.1.0+5"); //Fallback version + 5 commits since tag
198+
199+
TaggedVersion = "bad/1.0.3";
200+
fixture.Repository.MakeATaggedCommit(TaggedVersion);
201+
202+
fixture.AssertFullSemver("0.1.0+6"); //Fallback version + 6 commits since tag
160203
}
161204
}
162205
}

GitVersionCore.Tests/SemanticVersionTests.cs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,35 @@
66
public class SemanticVersionTests
77
{
88

9-
[TestCase("1.2.3", 1, 2, 3, null, null, null, null, null, null, null)]
10-
[TestCase("1.2", 1, 2, 0, null, null, null, null, null, null, "1.2.0")]
11-
[TestCase("1.2.3-beta", 1, 2, 3, "beta", null, null, null, null, null, null)]
12-
[TestCase("1.2.3-beta3", 1, 2, 3, "beta", 3, null, null, null, null, "1.2.3-beta.3")]
13-
[TestCase("1.2.3-beta.3", 1, 2, 3, "beta", 3, null, null, null, null, "1.2.3-beta.3")]
14-
[TestCase("1.2.3-beta-3", 1, 2, 3, "beta-3", null, null, null, null, null, "1.2.3-beta-3")]
15-
[TestCase("1.2.3-alpha", 1, 2, 3, "alpha", null, null, null, null, null, null)]
16-
[TestCase("1.2-alpha4", 1, 2, 0, "alpha", 4, null, null, null, null, "1.2.0-alpha.4")]
17-
[TestCase("1.2.3-rc", 1, 2, 3, "rc", null, null, null, null, null, null)]
18-
[TestCase("1.2.3-rc3", 1, 2, 3, "rc", 3, null, null, null, null, "1.2.3-rc.3")]
19-
[TestCase("1.2.3-RC3", 1, 2, 3, "RC", 3, null, null, null, null, "1.2.3-RC.3")]
20-
[TestCase("1.2.3-rc3.1", 1, 2, 3, "rc3", 1, null, null, null, null, "1.2.3-rc3.1")]
21-
[TestCase("01.02.03-rc03", 1, 2, 3, "rc", 3, null, null, null, null, "1.2.3-rc.3")]
22-
[TestCase("1.2.3-beta3f", 1, 2, 3, "beta3f", null, null, null, null, null, null)]
23-
[TestCase("1.2.3-notAStability1", 1, 2, 3, "notAStability", 1, null, null, null, null, "1.2.3-notAStability.1")]
24-
[TestCase("1.2.3.4", 1, 2, 3, null, null, 4, null, null, null, "1.2.3+4")]
25-
[TestCase("1.2.3+4", 1, 2, 3, null, null, 4, null, null, null, null)]
26-
[TestCase("1.2.3+4.Branch.Foo", 1, 2, 3, null, null, 4, "Foo", null, null, null)]
27-
[TestCase("1.2.3+randomMetaData", 1, 2, 3, null, null, null, null, null, "randomMetaData", null)]
28-
[TestCase("1.2.3-beta.1+4.Sha.12234.Othershiz", 1, 2, 3, "beta", 1, 4, null, "12234", "Othershiz", null)]
29-
public void ValidateVersionParsing(string versionString, int major, int minor, int patch, string tag, int? tagNumber, int? numberOfBuilds,
30-
string branchName, string sha, string otherMetaData, string fullFormattedVersionString)
9+
[TestCase("1.2.3", 1, 2, 3, null, null, null, null, null, null, null, null)]
10+
[TestCase("1.2", 1, 2, 0, null, null, null, null, null, null, "1.2.0", null)]
11+
[TestCase("1.2.3-beta", 1, 2, 3, "beta", null, null, null, null, null, null, null)]
12+
[TestCase("1.2.3-beta3", 1, 2, 3, "beta", 3, null, null, null, null, "1.2.3-beta.3", null)]
13+
[TestCase("1.2.3-beta.3", 1, 2, 3, "beta", 3, null, null, null, null, "1.2.3-beta.3", null)]
14+
[TestCase("1.2.3-beta-3", 1, 2, 3, "beta-3", null, null, null, null, null, "1.2.3-beta-3", null)]
15+
[TestCase("1.2.3-alpha", 1, 2, 3, "alpha", null, null, null, null, null, null, null)]
16+
[TestCase("1.2-alpha4", 1, 2, 0, "alpha", 4, null, null, null, null, "1.2.0-alpha.4", null)]
17+
[TestCase("1.2.3-rc", 1, 2, 3, "rc", null, null, null, null, null, null, null)]
18+
[TestCase("1.2.3-rc3", 1, 2, 3, "rc", 3, null, null, null, null, "1.2.3-rc.3", null)]
19+
[TestCase("1.2.3-RC3", 1, 2, 3, "RC", 3, null, null, null, null, "1.2.3-RC.3", null)]
20+
[TestCase("1.2.3-rc3.1", 1, 2, 3, "rc3", 1, null, null, null, null, "1.2.3-rc3.1", null)]
21+
[TestCase("01.02.03-rc03", 1, 2, 3, "rc", 3, null, null, null, null, "1.2.3-rc.3", null)]
22+
[TestCase("1.2.3-beta3f", 1, 2, 3, "beta3f", null, null, null, null, null, null, null)]
23+
[TestCase("1.2.3-notAStability1", 1, 2, 3, "notAStability", 1, null, null, null, null, "1.2.3-notAStability.1", null)]
24+
[TestCase("1.2.3.4", 1, 2, 3, null, null, 4, null, null, null, "1.2.3+4", null)]
25+
[TestCase("1.2.3+4", 1, 2, 3, null, null, 4, null, null, null, null, null)]
26+
[TestCase("1.2.3+4.Branch.Foo", 1, 2, 3, null, null, 4, "Foo", null, null, null, null)]
27+
[TestCase("1.2.3+randomMetaData", 1, 2, 3, null, null, null, null, null, "randomMetaData", null, null)]
28+
[TestCase("1.2.3-beta.1+4.Sha.12234.Othershiz", 1, 2, 3, "beta", 1, 4, null, "12234", "Othershiz", null, null)]
29+
[TestCase("1.2.3", 1, 2, 3, null, null, null, null, null, null, null, "v")]
30+
public void ValidateVersionParsing(
31+
string versionString, int major, int minor, int patch, string tag, int? tagNumber, int? numberOfBuilds,
32+
string branchName, string sha, string otherMetaData, string fullFormattedVersionString, string tagPrefixRegex)
3133
{
3234
fullFormattedVersionString = fullFormattedVersionString ?? versionString;
3335

3436
SemanticVersion version;
35-
Assert.IsTrue(SemanticVersion.TryParse(versionString, null, out version), "TryParse Result");
37+
SemanticVersion.TryParse(versionString, tagPrefixRegex, out version).ShouldBe(true, versionString);
3638
Assert.AreEqual(major, version.Major);
3739
Assert.AreEqual(minor, version.Minor);
3840
Assert.AreEqual(patch, version.Patch);

GitVersionCore/Configuration/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class Config
1111
public Config()
1212
{
1313
AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch;
14-
TagPrefix = "[vV]";
14+
TagPrefix = "[vV]|";
1515
VersioningMode = GitVersion.VersioningMode.ContinuousDelivery;
1616
ContinuousDeploymentFallbackTag = "ci";
1717

GitVersionCore/SemanticVersion.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class SemanticVersion : IFormattable, IComparable<SemanticVersion>
88
public static SemanticVersion Empty = new SemanticVersion();
99

1010
static Regex ParseSemVer = new Regex(
11-
@"(?<SemVer>(?<Major>\d+)(\.(?<Minor>\d+))(\.(?<Patch>\d+))?)(\.(?<FourthPart>\d+))?(-(?<Tag>[^\+]*))?(\+(?<BuildMetaData>.*))?",
11+
@"^(?<SemVer>(?<Major>\d+)(\.(?<Minor>\d+))(\.(?<Patch>\d+))?)(\.(?<FourthPart>\d+))?(-(?<Tag>[^\+]*))?(\+(?<BuildMetaData>.*))?$",
1212
RegexOptions.Compiled);
1313

1414
public int Major;
@@ -147,7 +147,14 @@ public static SemanticVersion Parse(string version, string tagPrefixRegex)
147147

148148
public static bool TryParse(string version, string tagPrefixRegex, out SemanticVersion semanticVersion)
149149
{
150-
var match = Regex.Match(version, string.Format("({0})?(?<version>.*)", tagPrefixRegex));
150+
var match = Regex.Match(version, string.Format("^({0})?(?<version>.*)$", tagPrefixRegex));
151+
152+
if (!match.Success)
153+
{
154+
semanticVersion = null;
155+
return false;
156+
}
157+
151158
version = match.Groups["version"].Value;
152159
var parsed = ParseSemVer.Match(version);
153160

GitVersionExe.Tests/GitVersionExe.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@
9898
<Compile Include="PullRequestInTeamCityTest.cs" />
9999
<Compile Include="AssemblyInfoFileUpdateTests.cs" />
100100
</ItemGroup>
101+
<ItemGroup>
102+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
103+
</ItemGroup>
101104
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
102105
<PropertyGroup>
103106
<PostBuildEvent>

0 commit comments

Comments
 (0)