Skip to content

Commit a37b160

Browse files
authored
Merge pull request #355 from AArnott/fix302
Add g back as a prefix to semver2 versions
2 parents 405a49c + 5f5ca2e commit a37b160

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,8 +1013,7 @@ private void AssertStandardProperties(VersionOptions versionOptions, BuildResult
10131013

10141014
string GetPkgVersionSuffix(bool useSemVer2)
10151015
{
1016-
string semVer1CommitPrefix = useSemVer2 ? string.Empty : "g";
1017-
string pkgVersionSuffix = buildResult.PublicRelease ? string.Empty : $"-{semVer1CommitPrefix}{commitIdShort}";
1016+
string pkgVersionSuffix = buildResult.PublicRelease ? string.Empty : $"-g{commitIdShort}";
10181017
if (useSemVer2)
10191018
{
10201019
pkgVersionSuffix += expectedBuildMetadataWithoutCommitId;

src/NerdBank.GitVersioning.Tests/VersionOracleTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public void SemVerStableNonPublicVersion()
174174
var oracle = VersionOracle.Create(this.RepoPath);
175175
oracle.PublicRelease = false;
176176
Assert.Matches(@"^2.3.1-[^g]{10}$", oracle.SemVer1);
177-
Assert.Matches(@"^2.3.1-[^g]{10}$", oracle.SemVer2);
177+
Assert.Matches(@"^2.3.1-g[a-f0-9]{10}$", oracle.SemVer2);
178178
Assert.Matches(@"^2.3.1-g[a-f0-9]{10}$", oracle.NuGetPackageVersion);
179179
Assert.Matches(@"^2.3.1-g[a-f0-9]{10}$", oracle.ChocolateyPackageVersion);
180180
}
@@ -192,7 +192,7 @@ public void SemVerStableNonPublicVersionShortened()
192192
var oracle = VersionOracle.Create(this.RepoPath);
193193
oracle.PublicRelease = false;
194194
Assert.Matches(@"^2.3.1-[^g]{7}$", oracle.SemVer1);
195-
Assert.Matches(@"^2.3.1-[^g]{7}$", oracle.SemVer2);
195+
Assert.Matches(@"^2.3.1-g[a-f0-9]{7}$", oracle.SemVer2);
196196
Assert.Matches(@"^2.3.1-g[a-f0-9]{7}$", oracle.NuGetPackageVersion);
197197
Assert.Matches(@"^2.3.1-g[a-f0-9]{7}$", oracle.ChocolateyPackageVersion);
198198
}
@@ -275,7 +275,7 @@ public void CanSetSemVer2ForNuGetPackageVersionNonPublicRelease()
275275
this.InitializeSourceControl();
276276
var oracle = VersionOracle.Create(this.RepoPath);
277277
oracle.PublicRelease = false;
278-
Assert.Equal($"7.8.9-foo.25.{this.CommitIdShort}", oracle.NuGetPackageVersion);
278+
Assert.Equal($"7.8.9-foo.25.g{this.CommitIdShort}", oracle.NuGetPackageVersion);
279279
}
280280

281281
[Fact]

src/NerdBank.GitVersioning/VersionOracle.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,14 @@ public IDictionary<string, string> CloudBuildVersionVars
424424

425425
private string PrereleaseVersionSemVer1 => SemanticVersionExtensions.MakePrereleaseSemVer1Compliant(this.PrereleaseVersion, this.SemVer1NumericIdentifierPadding);
426426

427-
private string GitCommitIdShortForNonPublicPrereleaseTag => (string.IsNullOrEmpty(this.PrereleaseVersion) ? "-" : ".") + this.GitCommitIdShort;
427+
/// <summary>
428+
/// Gets the -gc0ffee or .gc0ffee suffix for the version.
429+
/// </summary>
430+
/// <remarks>
431+
/// The `g` prefix to the commit ID is to remain SemVer2 compliant particularly when the partial commit ID we use is made up entirely of numerals.
432+
/// SemVer2 forbids numerals to begin with leading zeros, but a git commit just might, so we begin with `g` always to avoid failures when the commit ID happens to be problematic.
433+
/// </remarks>
434+
private string GitCommitIdShortForNonPublicPrereleaseTag => (string.IsNullOrEmpty(this.PrereleaseVersion) ? "-" : ".") + "g" + this.GitCommitIdShort;
428435

429436
private VersionOptions.CloudBuildNumberOptions CloudBuildNumberOptions { get; }
430437

0 commit comments

Comments
 (0)