Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vchirikov committed Mar 8, 2020
1 parent 0c2c442 commit 3cbd500
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/NerdBank.GitVersioning.Tests/VersionOracleTests.cs
Expand Up @@ -323,8 +323,7 @@ public void CanSetGitCommitIdPrefixNonPublicRelease()
{
SemVer = 2,
},
GitCommitIdPrefix = "git"

GitCommitIdPrefix = "git",
};
this.WriteVersionFile(workingCopyVersion);
this.InitializeSourceControl();
Expand Down
23 changes: 22 additions & 1 deletion src/NerdBank.GitVersioning/VersionOptions.cs
Expand Up @@ -15,6 +15,9 @@
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class VersionOptions : IEquatable<VersionOptions>
{
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string gitCommitIdPrefix;

/// <summary>
/// Default value for <see cref="VersionPrecision"/>.
/// </summary>
Expand Down Expand Up @@ -60,13 +63,31 @@ public class VersionOptions : IEquatable<VersionOptions>
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public AssemblyVersionOptions AssemblyVersion { get; set; }


/// <summary>
/// Gets or sets the prefix for git commit id in version.
/// Because of semver rules the prefix must lead with a [A-z_] character (not a number) and it cannot be the empty string.
/// If <c>null</c> 'g' will be used.
/// </summary>
/// <value>A prefix for git commit id.</value>
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string GitCommitIdPrefix { get; set; }
public string GitCommitIdPrefix
{
get => gitCommitIdPrefix;
set
{
if (string.IsNullOrWhiteSpace(value))
{
throw new ArgumentNullException(nameof(value), $"{nameof(this.GitCommitIdPrefix)} can't be empty");
}
char first = value[0];
if (first < 'A' || (first > 'Z' && first < 'a' && first != '_') || first > 'z')
{
throw new ArgumentException(nameof(value), $"{nameof(this.GitCommitIdPrefix)} must lead with a [A-z_] character (not a number)");
}
this.gitCommitIdPrefix = value;
}
}

/// <summary>
/// Gets the version to use particularly for the <see cref="AssemblyVersionAttribute"/>
Expand Down
5 changes: 3 additions & 2 deletions src/NerdBank.GitVersioning/VersionOracle.cs
Expand Up @@ -418,7 +418,7 @@ public IEnumerable<string> BuildMetadataWithCommitId
this.PublicRelease ? string.Empty : $"-{this.GitCommitIdShort}";

/// <summary>
/// Gets a SemVer 1.0 compliant string that represents this version, including the -{GitCommitIdPrefix}COMMITID suffix
/// Gets a SemVer 1.0 compliant string that represents this version, including the -gCOMMITID suffix
/// when <see cref="PublicRelease"/> is <c>false</c>.
/// </summary>
private string NuGetSemVer1 =>
Expand All @@ -438,7 +438,8 @@ public IEnumerable<string> BuildMetadataWithCommitId
private string PrereleaseVersionSemVer1 => SemanticVersionExtensions.MakePrereleaseSemVer1Compliant(this.PrereleaseVersion, this.SemVer1NumericIdentifierPadding);

/// <summary>
/// Gets the -{<seealso cref="VersionOptions.GitCommitIdPrefix"/>}c0ffee or .<seealso cref="VersionOptions.GitCommitIdPrefix"/>c0ffee suffix for the version.
/// Gets the -gc0ffee or .gc0ffee suffix for the version.
/// The g in the prefix might be changed if <see cref="VersionOptions.GitCommitIdPrefix"/> is set.
/// </summary>
/// <remarks>
/// The prefix to the commit ID is to remain SemVer2 compliant particularly when the partial commit ID we use is made up entirely of numerals.
Expand Down
2 changes: 1 addition & 1 deletion src/NerdBank.GitVersioning/version.schema.json
Expand Up @@ -81,7 +81,7 @@
},
"gitCommitIdPrefix": {
"type": "string",
"description": "The git commit prefix (e.g. 'g') in prerelease versions",
"description": "The git commit prefix (e.g. 'g') in non-public release versions.",
"pattern": "^[^0-9][\\da-z\\-_\\.]*$",
"default": "g"
},
Expand Down

0 comments on commit 3cbd500

Please sign in to comment.