Skip to content

Commit b1bc4bc

Browse files
authored
Merge pull request #2014 from Skoucail/feature/issue-1520
Replace special chars in InformationalVersion with dashes
2 parents d42bbad + c44e411 commit b1bc4bc

4 files changed

+120
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"Major":1,
3+
"Minor":2,
4+
"Patch":3,
5+
"PreReleaseTag":"",
6+
"PreReleaseTagWithDash":"",
7+
"PreReleaseLabel":"",
8+
"PreReleaseNumber":"",
9+
"WeightedPreReleaseNumber":"",
10+
"BuildMetaData":5,
11+
"BuildMetaDataPadded":"0005",
12+
"FullBuildMetaData":"5.Branch.feature-123.Sha.commitSha",
13+
"MajorMinorPatch":"1.2.3",
14+
"SemVer":"1.2.3",
15+
"LegacySemVer":"1.2.3",
16+
"LegacySemVerPadded":"1.2.3",
17+
"AssemblySemVer":"1.2.3.0",
18+
"AssemblySemFileVer":"1.2.3.0",
19+
"FullSemVer":"1.2.3+5",
20+
"InformationalVersion":"1.2.3+5.Branch.feature-123.Sha.commitSha",
21+
"BranchName":"feature/123",
22+
"Sha":"commitSha",
23+
"ShortSha":"commitShortSha",
24+
"NuGetVersionV2":"1.2.3",
25+
"NuGetVersion":"1.2.3",
26+
"NuGetPreReleaseTagV2":"",
27+
"NuGetPreReleaseTag":"",
28+
"VersionSourceSha":"versionSourceSha",
29+
"CommitsSinceVersionSource":5,
30+
"CommitsSinceVersionSourcePadded":"0005",
31+
"CommitDate":"2014-03-06"
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"Major":1,
3+
"Minor":2,
4+
"Patch":3,
5+
"PreReleaseTag":"",
6+
"PreReleaseTagWithDash":"",
7+
"PreReleaseLabel":"",
8+
"PreReleaseNumber":"",
9+
"WeightedPreReleaseNumber":"",
10+
"BuildMetaData":5,
11+
"BuildMetaDataPadded":"0005",
12+
"FullBuildMetaData":"5.Branch.feature-123.Sha.commitSha",
13+
"MajorMinorPatch":"1.2.3",
14+
"SemVer":"1.2.3",
15+
"LegacySemVer":"1.2.3",
16+
"LegacySemVerPadded":"1.2.3",
17+
"AssemblySemVer":"1.2.3.0",
18+
"AssemblySemFileVer":"1.2.3.0",
19+
"FullSemVer":"1.2.3+5",
20+
"InformationalVersion":"1.2.3+5.Branch.feature-123.Sha.commitShortSha",
21+
"BranchName":"feature/123",
22+
"Sha":"commitSha",
23+
"ShortSha":"commitShortSha",
24+
"NuGetVersionV2":"1.2.3",
25+
"NuGetVersion":"1.2.3",
26+
"NuGetPreReleaseTagV2":"",
27+
"NuGetPreReleaseTag":"",
28+
"VersionSourceSha":"versionSourceSha",
29+
"CommitsSinceVersionSource":5,
30+
"CommitsSinceVersionSourcePadded":"0005",
31+
"CommitDate":"2014-03-06"
32+
}

src/GitVersionCore.Tests/VariableProviderTests.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,5 +229,59 @@ public void ProvidesVariablesInContinuousDeploymentModeWithTagSetToUseBranchName
229229

230230
vars.FullSemVer.ShouldBe("1.2.3-feature.5");
231231
}
232+
233+
[Test]
234+
[Category("NoMono")]
235+
[Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")]
236+
public void ProvidesVariablesInContinuousDeliveryModeForFeatureBranch()
237+
{
238+
var semVer = new SemanticVersion
239+
{
240+
Major = 1,
241+
Minor = 2,
242+
Patch = 3,
243+
BuildMetaData = "5.Branch.feature/123"
244+
};
245+
246+
semVer.BuildMetaData.Branch = "feature/123";
247+
semVer.BuildMetaData.VersionSourceSha = "versionSourceSha";
248+
semVer.BuildMetaData.Sha = "commitSha";
249+
semVer.BuildMetaData.ShortSha = "commitShortSha";
250+
semVer.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");
251+
252+
253+
var config = new TestEffectiveConfiguration();
254+
255+
var vars = variableProvider.GetVariablesFor(semVer, config, false);
256+
257+
JsonOutputFormatter.ToJson(vars).ShouldMatchApproved(c => c.SubFolder("Approved"));
258+
}
259+
260+
[Test]
261+
[Category("NoMono")]
262+
[Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")]
263+
public void ProvidesVariablesInContinuousDeliveryModeForFeatureBranchWithCustomAssemblyInformationalFormat()
264+
{
265+
var semVer = new SemanticVersion
266+
{
267+
Major = 1,
268+
Minor = 2,
269+
Patch = 3,
270+
BuildMetaData = "5.Branch.feature/123"
271+
};
272+
273+
semVer.BuildMetaData.Branch = "feature/123";
274+
semVer.BuildMetaData.VersionSourceSha = "versionSourceSha";
275+
semVer.BuildMetaData.Sha = "commitSha";
276+
semVer.BuildMetaData.ShortSha = "commitShortSha";
277+
semVer.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");
278+
279+
280+
var config = new TestEffectiveConfiguration(assemblyInformationalFormat: "{Major}.{Minor}.{Patch}+{CommitsSinceVersionSource}.Branch.{BranchName}.Sha.{ShortSha}");
281+
282+
var vars = variableProvider.GetVariablesFor(semVer, config, false);
283+
284+
JsonOutputFormatter.ToJson(vars).ShouldMatchApproved(c => c.SubFolder("Approved"));
285+
}
232286
}
233287
}

src/GitVersionCore/OutputVariables/VariableProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Text.RegularExpressions;
33
using GitVersion.Exceptions;
4+
using GitVersion.Extensions;
45
using GitVersion.VersionCalculation;
56
using GitVersion.VersioningModes;
67
using GitVersion.Configuration;
@@ -135,7 +136,7 @@ private static string CheckAndFormatString<T>(string formatString, T source, IEn
135136
{
136137
try
137138
{
138-
formattedString = formatString.FormatWith(source, environment);
139+
formattedString = formatString.FormatWith(source, environment).RegexReplace("[^0-9A-Za-z-.+]", "-");
139140
}
140141
catch (ArgumentException formex)
141142
{

0 commit comments

Comments
 (0)