Skip to content

Commit 78104ee

Browse files
Move tag name option to release object
1 parent 0c947f2 commit 78104ee

File tree

4 files changed

+44
-44
lines changed

4 files changed

+44
-44
lines changed

src/NerdBank.GitVersioning/VersionOptions.cs

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ public class VersionOptions : IEquatable<VersionOptions>
4646
/// </summary>
4747
private const int DefaultSemVer1NumericIdentifierPadding = 4;
4848

49-
/// <summary>
50-
/// The default value for the <see cref="TagName"/> property.
51-
/// </summary>
52-
private const string DefaultTagName = "v{version}";
53-
5449
/// <summary>
5550
/// A value indicating whether mutations of this instance are not allowed.
5651
/// </summary>
@@ -114,12 +109,6 @@ public class VersionOptions : IEquatable<VersionOptions>
114109
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
115110
private CloudBuildOptions? cloudBuild;
116111

117-
/// <summary>
118-
/// Backing field for the <see cref="TagName"/> property.
119-
/// </summary>
120-
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
121-
private string? tagName;
122-
123112
/// <summary>
124113
/// Backing field for the <see cref="Release"/> property.
125114
/// </summary>
@@ -164,7 +153,6 @@ public VersionOptions(VersionOptions copyFrom)
164153
this.publicReleaseRefSpec = copyFrom.publicReleaseRefSpec?.ToList();
165154
this.cloudBuild = copyFrom.cloudBuild is object ? new CloudBuildOptions(copyFrom.cloudBuild) : null;
166155
this.release = copyFrom.release is object ? new ReleaseOptions(copyFrom.release) : null;
167-
this.tagName = copyFrom.tagName;
168156
this.pathFilters = copyFrom.pathFilters?.ToList();
169157
}
170158

@@ -484,22 +472,6 @@ public ReleaseOptions? Release
484472
[JsonIgnore]
485473
public ReleaseOptions ReleaseOrDefault => this.Release ?? ReleaseOptions.DefaultInstance;
486474

487-
/// <summary>
488-
/// Gets or sets the tag name template for tagging.
489-
/// </summary>
490-
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
491-
public string? TagName
492-
{
493-
get => this.tagName;
494-
set => this.SetIfNotReadOnly(ref this.tagName, value);
495-
}
496-
497-
/// <summary>
498-
/// Gets the tag name template for tagging.
499-
/// </summary>
500-
[JsonIgnore]
501-
public string? TagNameOrDefault => this.TagName ?? DefaultTagName;
502-
503475
/// <summary>
504476
/// Gets or sets a list of paths to use to filter commits when calculating version height.
505477
/// If a given commit does not affect any paths in this filter, it is ignored for version height calculations.
@@ -1470,7 +1442,7 @@ public int GetHashCode(CloudBuildNumberCommitIdOptions? obj)
14701442
}
14711443

14721444
/// <summary>
1473-
/// Encapsulates settings for the "prepare-release" command.
1445+
/// Encapsulates settings for the "prepare-release" and "tag" commands.
14741446
/// </summary>
14751447
public class ReleaseOptions : IEquatable<ReleaseOptions>
14761448
{
@@ -1480,6 +1452,7 @@ public class ReleaseOptions : IEquatable<ReleaseOptions>
14801452
internal static readonly ReleaseOptions DefaultInstance = new ReleaseOptions()
14811453
{
14821454
isFrozen = true,
1455+
tagName = "v{version}",
14831456
branchName = "v{version}",
14841457
versionIncrement = ReleaseVersionIncrement.Minor,
14851458
firstUnstableTag = "alpha",
@@ -1488,6 +1461,9 @@ public class ReleaseOptions : IEquatable<ReleaseOptions>
14881461
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
14891462
private bool isFrozen;
14901463

1464+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
1465+
private string? tagName;
1466+
14911467
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
14921468
private string? branchName;
14931469

@@ -1510,11 +1486,28 @@ public ReleaseOptions()
15101486
/// <param name="copyFrom">The existing instance to copy from.</param>
15111487
public ReleaseOptions(ReleaseOptions copyFrom)
15121488
{
1489+
this.tagName = copyFrom.tagName;
15131490
this.branchName = copyFrom.branchName;
15141491
this.versionIncrement = copyFrom.versionIncrement;
15151492
this.firstUnstableTag = copyFrom.firstUnstableTag;
15161493
}
15171494

1495+
/// <summary>
1496+
/// Gets or sets the tag name template for tagging.
1497+
/// </summary>
1498+
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
1499+
public string? TagName
1500+
{
1501+
get => this.tagName;
1502+
set => this.SetIfNotReadOnly(ref this.tagName, value);
1503+
}
1504+
1505+
/// <summary>
1506+
/// Gets the tag name template for tagging.
1507+
/// </summary>
1508+
[JsonIgnore]
1509+
public string TagNameOrDefault => this.TagName ?? DefaultInstance.TagName!;
1510+
15181511
/// <summary>
15191512
/// Gets or sets the branch name template for release branches.
15201513
/// </summary>
@@ -1526,7 +1519,7 @@ public string? BranchName
15261519
}
15271520

15281521
/// <summary>
1529-
/// Gets the set branch name template for release branches.
1522+
/// Gets the branch name template for release branches.
15301523
/// </summary>
15311524
[JsonIgnore]
15321525
public string BranchNameOrDefault => this.BranchName ?? DefaultInstance.BranchName!;
@@ -1621,7 +1614,8 @@ public bool Equals(ReleaseOptions? x, ReleaseOptions? y)
16211614
return false;
16221615
}
16231616

1624-
return StringComparer.Ordinal.Equals(x.BranchNameOrDefault, y.BranchNameOrDefault) &&
1617+
return StringComparer.Ordinal.Equals(x.TagNameOrDefault, y.TagNameOrDefault) &&
1618+
StringComparer.Ordinal.Equals(x.BranchNameOrDefault, y.BranchNameOrDefault) &&
16251619
x.VersionIncrementOrDefault == y.VersionIncrementOrDefault &&
16261620
StringComparer.Ordinal.Equals(x.FirstUnstableTagOrDefault, y.FirstUnstableTagOrDefault);
16271621
}
@@ -1636,7 +1630,8 @@ public int GetHashCode(ReleaseOptions? obj)
16361630

16371631
unchecked
16381632
{
1639-
int hash = StringComparer.Ordinal.GetHashCode(obj.BranchNameOrDefault) * 397;
1633+
int hash = StringComparer.Ordinal.GetHashCode(obj.TagNameOrDefault) * 397;
1634+
hash ^= StringComparer.Ordinal.GetHashCode(obj.BranchNameOrDefault);
16401635
hash ^= (int)obj.VersionIncrementOrDefault;
16411636
hash ^= StringComparer.Ordinal.GetHashCode(obj.FirstUnstableTagOrDefault);
16421637
return hash;

src/NerdBank.GitVersioning/VersionOptionsContractResolver.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerializ
126126
property.ShouldSerialize = instance => !((VersionOptions)instance).ReleaseOrDefault.IsDefault;
127127
}
128128

129+
if (property.DeclaringType == typeof(VersionOptions.ReleaseOptions) && member.Name == nameof(VersionOptions.ReleaseOptions.TagName))
130+
{
131+
property.ShouldSerialize = instance => ((VersionOptions.ReleaseOptions)instance).TagNameOrDefault != VersionOptions.ReleaseOptions.DefaultInstance.TagName;
132+
}
133+
129134
if (property.DeclaringType == typeof(VersionOptions.ReleaseOptions) && member.Name == nameof(VersionOptions.ReleaseOptions.BranchName))
130135
{
131136
property.ShouldSerialize = instance => ((VersionOptions.ReleaseOptions)instance).BranchNameOrDefault != VersionOptions.ReleaseOptions.DefaultInstance.BranchName;

src/NerdBank.GitVersioning/version.schema.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
},
120120
"publicReleaseRefSpec": {
121121
"type": "array",
122-
"description": "An array of regular expressions that may match a ref (branch or tag) that should be built with PublicRelease=true as the default value. The ref matched against is in its canonical form (e.g. refs/heads/master)",
122+
"description": "An array of regular expressions that may match a ref (branch or tag) that should be built with PublicRelease=true as the default value. The ref matched against is in its canonical form (e.g. refs/heads/master).",
123123
"items": {
124124
"type": "string",
125125
"format": "regex"
@@ -128,12 +128,12 @@
128128
},
129129
"cloudBuild": {
130130
"type": "object",
131-
"description": "Options that are applicable specifically to cloud builds (e.g. VSTS, AppVeyor, TeamCity)",
131+
"description": "Options that are applicable specifically to cloud builds (e.g. VSTS, AppVeyor, TeamCity).",
132132
"properties": {
133133
"setAllVariables": {
134134
"type": "boolean",
135135
"default": false,
136-
"description": "Elevates all build properties to cloud build variables prefaced with \"NBGV_\""
136+
"description": "Elevates all build properties to cloud build variables prefaced with \"NBGV_\"."
137137
},
138138
"setVersionVariables": {
139139
"type": "boolean",
@@ -172,13 +172,19 @@
172172
}
173173
},
174174
"release": {
175-
"description": "Settings for the prepare-release command",
175+
"description": "Settings for the prepare-release and tag commands.",
176176
"type": "object",
177177
"properties": {
178+
"tagName": {
179+
"description": "Defines the format of tag names. Format must include a placeholder '{version}' for the version.",
180+
"type": "string",
181+
"pattern": "\\{version\\}",
182+
"default": "v{version}"
183+
},
178184
"branchName": {
179185
"description": "Defines the format of release branch names. Format must include a placeholder '{version}' for the version.",
180186
"type": "string",
181-
"pattern": ".*\\{version\\}.*",
187+
"pattern": "\\{version\\}",
182188
"default": "v{version}"
183189
},
184190
"versionIncrement": {
@@ -195,12 +201,6 @@
195201
},
196202
"additionalProperties": false
197203
},
198-
"tagName": {
199-
"description": "Defines the format of tag names. Format must include a placeholder '{version}' for the version.",
200-
"type": "string",
201-
"pattern": ".*\\{version\\}.*",
202-
"default": "v{version}"
203-
},
204204
"pathFilters": {
205205
"type": "array",
206206
"description": "An array of pathspec-like strings that are used to filter commits when calculating the version height. A commit will not increment the version height if its changed files are not included by these filters.\nPaths are relative to this file. Paths relative to the root of the repository can be specified with the `:/` prefix.\nExclusions can be specified with a `:^` prefix for relative paths, or a `:^/` prefix for paths relative to the root of the repository.\nAfter a path matches any non-exclude filter, it will be run through all exclude filters. If it matches, the path is ignored.",

src/nbgv/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ private static Task<int> OnTagCommand(string project, string versionOrRef)
554554
return Task.FromResult((int)ExitCodes.NoVersionJsonFound);
555555
}
556556

557-
string tagNameFormat = versionOptions.TagNameOrDefault;
557+
string tagNameFormat = versionOptions.ReleaseOrDefault.TagNameOrDefault;
558558

559559
// ensure there is a '{version}' placeholder in the tag name
560560
if (string.IsNullOrEmpty(tagNameFormat) || !tagNameFormat.Contains("{version}"))

0 commit comments

Comments
 (0)