Skip to content

Commit 38cdf21

Browse files
author
Chris Leigh
committed
Issue: GitTools#495, PR GitTools#496 - attempting to clarify what was intended with default TagPrefix of "[vV]|"
1 parent 2379c9d commit 38cdf21

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

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(SemanticVersion.DefaultTagPrefix);
124124
config.NextVersion.ShouldBe(null);
125125
}
126126

GitVersionCore.Tests/SemanticVersionTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ public class SemanticVersionTests
2626
[TestCase("1.2.3+4.Branch.Foo", 1, 2, 3, null, null, 4, "Foo", null, null, null, null)]
2727
[TestCase("1.2.3+randomMetaData", 1, 2, 3, null, null, null, null, null, "randomMetaData", null, null)]
2828
[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")]
29+
[TestCase("1.2.3", 1, 2, 3, null, null, null, null, null, null, null, SemanticVersion.DefaultTagPrefix)]
30+
[TestCase("v1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", SemanticVersion.DefaultTagPrefix)]
31+
[TestCase("V1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", SemanticVersion.DefaultTagPrefix)]
32+
[TestCase("version1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", "version")]
3033
public void ValidateVersionParsing(
3134
string versionString, int major, int minor, int patch, string tag, int? tagNumber, int? numberOfBuilds,
3235
string branchName, string sha, string otherMetaData, string fullFormattedVersionString, string tagPrefixRegex)

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 = SemanticVersion.DefaultTagPrefix;
1515
VersioningMode = GitVersion.VersioningMode.ContinuousDelivery;
1616
ContinuousDeploymentFallbackTag = "ci";
1717

GitVersionCore/SemanticVersion.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace GitVersion
66
public class SemanticVersion : IFormattable, IComparable<SemanticVersion>
77
{
88
public static SemanticVersion Empty = new SemanticVersion();
9+
public const string DefaultTagPrefix = "[vV]|"; // "|" makes the tag optional such that 1.2.3, v1.2.3, and 1.2.3 are all parse-able
910

1011
static Regex ParseSemVer = new Regex(
1112
@"^(?<SemVer>(?<Major>\d+)(\.(?<Minor>\d+))(\.(?<Patch>\d+))?)(\.(?<FourthPart>\d+))?(-(?<Tag>[^\+]*))?(\+(?<BuildMetaData>.*))?$",
@@ -136,7 +137,7 @@ public override int GetHashCode()
136137
return v1.CompareTo(v2) < 0;
137138
}
138139

139-
public static SemanticVersion Parse(string version, string tagPrefixRegex)
140+
public static SemanticVersion Parse(string version, string tagPrefixRegex = DefaultTagPrefix)
140141
{
141142
SemanticVersion semanticVersion;
142143
if (!TryParse(version, tagPrefixRegex, out semanticVersion))
@@ -145,9 +146,14 @@ public static SemanticVersion Parse(string version, string tagPrefixRegex)
145146
return semanticVersion;
146147
}
147148

149+
public static bool TryParse(string version, out SemanticVersion semanticVersion)
150+
{
151+
return TryParse(version, DefaultTagPrefix, out semanticVersion);
152+
}
153+
148154
public static bool TryParse(string version, string tagPrefixRegex, out SemanticVersion semanticVersion)
149155
{
150-
var match = Regex.Match(version, string.Format("^({0})?(?<version>.*)$", tagPrefixRegex));
156+
var match = Regex.Match(version, string.Format("^({0})(?<version>.*)$", tagPrefixRegex));
151157

152158
if (!match.Success)
153159
{

GitVersionExe.Tests/AssemblyInfoFileUpdateTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public void ShouldStartSearchFromWorkingDirectory()
1313
{
1414
var fileSystem = Substitute.For<IFileSystem>();
1515
const string workingDir = "C:\\Testing";
16-
var variables = VariableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), AssemblyVersioningScheme.MajorMinorPatch, VersioningMode.ContinuousDelivery, "ci", false);
16+
var variables = VariableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0"), AssemblyVersioningScheme.MajorMinorPatch, VersioningMode.ContinuousDelivery, "ci", false);
1717
using (new AssemblyInfoFileUpdate(new Arguments { UpdateAssemblyInfo = true }, workingDir, variables, fileSystem))
1818
{
1919
fileSystem.Received().DirectoryGetFiles(Arg.Is(workingDir), Arg.Any<string>(), Arg.Any<SearchOption>());

0 commit comments

Comments
 (0)