Skip to content

Commit 1071e1c

Browse files
committed
Don't consider "tag-prefix" as optional if it's explicitly specified
To correctly calculate the next version with the prefix. For example, we develop the main product and some its plugin in the same repository and have the following git tags list: - 0.1.0 - 0.1.1 - 0.2.0 - 0.2.1 - plugin_0.1.0 - plugin_0.1.1 The expected next plugin version is `0.1.2` not `0.2.2` (`plugin_` prefix will be prepended before setting the tag).
1 parent 3e5d1e7 commit 1071e1c

File tree

10 files changed

+19
-18
lines changed

10 files changed

+19
-18
lines changed

src/GitVersion.Core.Tests/Configuration/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
assembly-versioning-scheme: MajorMinorPatch
22
assembly-file-versioning-scheme: MajorMinorPatch
33
mode: ContinuousDelivery
4-
tag-prefix: '[vV]'
4+
tag-prefix: '[vV]?'
55
continuous-delivery-fallback-tag: ci
66
major-version-bump-message: '\+semver:\s?(breaking|major)'
77
minor-version-bump-message: '\+semver:\s?(feature|minor)'

src/GitVersion.Core.Tests/Configuration/ConfigProviderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ public void ShouldUseDefaultTagPrefixWhenNotSetInConfigFile()
461461
SetupConfigFileContent(text);
462462
var config = this.configProvider.Provide(this.repoPath);
463463

464-
config.TagPrefix.ShouldBe("[vV]");
464+
config.TagPrefix.ShouldBe(Config.DefaultTagPrefix);
465465
}
466466

467467
[Test]
@@ -491,7 +491,7 @@ public void ShouldNotOverrideDefaultTagPrefixWhenNotSetInOverrideConfig()
491491
SetupConfigFileContent(text);
492492
var config = this.configProvider.Provide(this.repoPath, new Config { TagPrefix = null });
493493

494-
config.TagPrefix.ShouldBe("[vV]");
494+
config.TagPrefix.ShouldBe(Config.DefaultTagPrefix);
495495
}
496496

497497
[Test]

src/GitVersion.Core.Tests/Helpers/TestEffectiveConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public TestEffectiveConfiguration(
1313
string? assemblyFileVersioningFormat = null,
1414
string? assemblyInformationalFormat = null,
1515
VersioningMode versioningMode = VersioningMode.ContinuousDelivery,
16-
string tagPrefix = "v",
16+
string tagPrefix = "v?",
1717
string tag = "",
1818
string? nextVersion = null,
1919
string branchPrefixToTrim = "",

src/GitVersion.Core.Tests/Model/MergeMessageTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace GitVersion.Core.Tests;
88
[TestFixture]
99
public class MergeMessageTests : TestBase
1010
{
11-
private readonly Config config = new() { TagPrefix = "[vV]" };
11+
private readonly Config config = new() { TagPrefix = Config.DefaultTagPrefix };
1212

1313
[Test]
1414
public void NullMessageStringThrows() =>

src/GitVersion.Core.Tests/VersionCalculation/SemanticVersionTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public void ValidateVersionParsing(
6565
[TestCase("someText")]
6666
[TestCase("some-T-ext")]
6767
[TestCase("v.1.2.3", "v")]
68+
[TestCase("1.2.3", "v")]
6869
public void ValidateInvalidVersionParsing(string versionString, string? tagPrefixRegex = null) =>
6970
Assert.IsFalse(SemanticVersion.TryParse(versionString, tagPrefixRegex, out _), "TryParse Result");
7071

src/GitVersion.Core.Tests/VersionConverters/AssemblyInfoFileUpdaterTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void ShouldCreateAssemblyInfoFileWhenNotExistsAndEnsureAssemblyInfo(strin
4242
var workingDir = Path.GetTempPath();
4343
var assemblyInfoFile = "VersionAssemblyInfo." + fileExtension;
4444
var fullPath = PathHelper.Combine(workingDir, assemblyInfoFile);
45-
var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false);
45+
var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v?"), new TestEffectiveConfiguration(), false);
4646

4747
using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(this.log, this.fileSystem);
4848
assemblyInfoFileUpdater.Execute(variables, new AssemblyInfoContext(workingDir, true, assemblyInfoFile));
@@ -60,7 +60,7 @@ public void ShouldCreateAssemblyInfoFileAtPathWhenNotExistsAndEnsureAssemblyInfo
6060
var workingDir = Path.GetTempPath();
6161
var assemblyInfoFile = PathHelper.Combine("src", "Project", "Properties", $"VersionAssemblyInfo.{fileExtension}");
6262
var fullPath = PathHelper.Combine(workingDir, assemblyInfoFile);
63-
var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false);
63+
var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v?"), new TestEffectiveConfiguration(), false);
6464

6565
using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(this.log, this.fileSystem);
6666
assemblyInfoFileUpdater.Execute(variables, new AssemblyInfoContext(workingDir, true, assemblyInfoFile));
@@ -81,7 +81,7 @@ public void ShouldCreateAssemblyInfoFilesAtPathWhenNotExistsAndEnsureAssemblyInf
8181
"AssemblyInfo." + fileExtension,
8282
PathHelper.Combine("src", "Project", "Properties", "VersionAssemblyInfo." + fileExtension)
8383
};
84-
var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false);
84+
var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v?"), new TestEffectiveConfiguration(), false);
8585

8686
using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(this.log, this.fileSystem);
8787
assemblyInfoFileUpdater.Execute(variables, new AssemblyInfoContext(workingDir, true, assemblyInfoFiles.ToArray()));
@@ -101,7 +101,7 @@ public void ShouldNotCreateAssemblyInfoFileWhenNotExistsAndNotEnsureAssemblyInfo
101101
var workingDir = Path.GetTempPath();
102102
var assemblyInfoFile = "VersionAssemblyInfo." + fileExtension;
103103
var fullPath = PathHelper.Combine(workingDir, assemblyInfoFile);
104-
var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false);
104+
var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v?"), new TestEffectiveConfiguration(), false);
105105

106106
using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(this.log, this.fileSystem);
107107
assemblyInfoFileUpdater.Execute(variables, new AssemblyInfoContext(workingDir, false, assemblyInfoFile));
@@ -116,7 +116,7 @@ public void ShouldNotCreateAssemblyInfoFileForUnknownSourceCodeAndEnsureAssembly
116116
var workingDir = Path.GetTempPath();
117117
const string assemblyInfoFile = "VersionAssemblyInfo.js";
118118
var fullPath = PathHelper.Combine(workingDir, assemblyInfoFile);
119-
var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false);
119+
var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v?"), new TestEffectiveConfiguration(), false);
120120

121121
using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(this.log, this.fileSystem);
122122
assemblyInfoFileUpdater.Execute(variables, new AssemblyInfoContext(workingDir, true, assemblyInfoFile));
@@ -130,7 +130,7 @@ public void ShouldStartSearchFromWorkingDirectory()
130130
this.fileSystem = Substitute.For<IFileSystem>();
131131
var workingDir = Path.GetTempPath();
132132
var assemblyInfoFiles = Array.Empty<string>();
133-
var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false);
133+
var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v?"), new TestEffectiveConfiguration(), false);
134134

135135
using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(this.log, this.fileSystem);
136136
assemblyInfoFileUpdater.Execute(variables, new AssemblyInfoContext(workingDir, false, assemblyInfoFiles.ToArray()));

src/GitVersion.Core.Tests/VersionConverters/ProjectFileUpdaterTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public void CannotUpdateProjectFileWithoutAPropertyGroup(string xml)
154154
[Description(NoMonoDescription)]
155155
public void UpdateProjectXmlVersionElementWithStandardXmlInsertsElement(string xml)
156156
{
157-
var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("2.0.0", "v"), new TestEffectiveConfiguration(), false);
157+
var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("2.0.0", "v?"), new TestEffectiveConfiguration(), false);
158158
var xmlRoot = XElement.Parse(xml);
159159
variables.AssemblySemVer.ShouldNotBeNull();
160160
ProjectFileUpdater.UpdateProjectVersionElement(xmlRoot, ProjectFileUpdater.AssemblyVersionElement, variables.AssemblySemVer);
@@ -183,7 +183,7 @@ public void UpdateProjectXmlVersionElementWithStandardXmlInsertsElement(string x
183183
[Description(NoMonoDescription)]
184184
public void UpdateProjectXmlVersionElementWithStandardXmlModifiesElement(string xml)
185185
{
186-
var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("2.0.0", "v"), new TestEffectiveConfiguration(), false);
186+
var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("2.0.0", "v?"), new TestEffectiveConfiguration(), false);
187187
var xmlRoot = XElement.Parse(xml);
188188
variables.AssemblySemVer.ShouldNotBeNull();
189189
ProjectFileUpdater.UpdateProjectVersionElement(xmlRoot, ProjectFileUpdater.AssemblyVersionElement, variables.AssemblySemVer);
@@ -215,7 +215,7 @@ public void UpdateProjectXmlVersionElementWithStandardXmlModifiesElement(string
215215
[Description(NoMonoDescription)]
216216
public void UpdateProjectXmlVersionElementWithDuplicatePropertyGroupsModifiesLastElement(string xml)
217217
{
218-
var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("2.0.0", "v"), new TestEffectiveConfiguration(), false);
218+
var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("2.0.0", "v?"), new TestEffectiveConfiguration(), false);
219219
var xmlRoot = XElement.Parse(xml);
220220
variables.AssemblySemVer.ShouldNotBeNull();
221221
ProjectFileUpdater.UpdateProjectVersionElement(xmlRoot, ProjectFileUpdater.AssemblyVersionElement, variables.AssemblySemVer);
@@ -248,7 +248,7 @@ public void UpdateProjectXmlVersionElementWithDuplicatePropertyGroupsModifiesLas
248248
[Description(NoMonoDescription)]
249249
public void UpdateProjectXmlVersionElementWithMultipleVersionElementsLastOneIsModified(string xml)
250250
{
251-
var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("2.0.0", "v"), new TestEffectiveConfiguration(), false);
251+
var variables = this.variableProvider.GetVariablesFor(SemanticVersion.Parse("2.0.0", "v?"), new TestEffectiveConfiguration(), false);
252252
var xmlRoot = XElement.Parse(xml);
253253
variables.AssemblySemVer.ShouldNotBeNull();
254254
ProjectFileUpdater.UpdateProjectVersionElement(xmlRoot, ProjectFileUpdater.AssemblyVersionElement, variables.AssemblySemVer);

src/GitVersion.Core/Model/Configuration/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public override string ToString()
104104
return stringBuilder.ToString();
105105
}
106106

107-
public const string DefaultTagPrefix = "[vV]";
107+
public const string DefaultTagPrefix = "[vV]?";
108108
public const string ReleaseBranchRegex = "^releases?[/-]";
109109
public const string FeatureBranchRegex = "^features?[/-]";
110110
public const string PullRequestRegex = @"^(pull|pull\-requests|pr)[/-]";

src/GitVersion.Core/PublicAPI.Shipped.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const GitVersion.BuildAgents.SpaceAutomation.EnvironmentVariableName = "JB_SPACE
2828
const GitVersion.BuildAgents.TeamCity.EnvironmentVariableName = "TEAMCITY_VERSION" -> string!
2929
const GitVersion.BuildAgents.TravisCi.EnvironmentVariableName = "TRAVIS" -> string!
3030
const GitVersion.Configuration.ConfigFileLocator.DefaultFileName = "GitVersion.yml" -> string!
31-
const GitVersion.Model.Configuration.Config.DefaultTagPrefix = "[vV]" -> string!
31+
const GitVersion.Model.Configuration.Config.DefaultTagPrefix = "[vV]?" -> string!
3232
const GitVersion.Model.Configuration.Config.DevelopBranchKey = "develop" -> string!
3333
const GitVersion.Model.Configuration.Config.DevelopBranchRegex = "^dev(elop)?(ment)?$" -> string!
3434
const GitVersion.Model.Configuration.Config.FeatureBranchKey = "feature" -> string!

src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public static SemanticVersion Parse(string version, string? tagPrefixRegex)
138138

139139
public static bool TryParse(string version, string? tagPrefixRegex, [NotNullWhen(true)] out SemanticVersion? semanticVersion)
140140
{
141-
var match = Regex.Match(version, $"^({tagPrefixRegex})?(?<version>.*)$");
141+
var match = Regex.Match(version, $"^({tagPrefixRegex})(?<version>.*)$");
142142

143143
if (!match.Success)
144144
{

0 commit comments

Comments
 (0)