Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void AllowHavingMainInsteadOfMaster()
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("main"));
fixture.Repository.Branches.Remove(fixture.Repository.Branches["master"]);

fixture.AssertFullSemver("0.1.0+0", config);
fixture.AssertFullSemver("0.1.0-1+0", config);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ public void CanTakeVersionFromReleasesBranch()
fixture.AssertFullSemver("2.0.0-beta.1+2");
}

[Test]
public void CanTakePreReleaseVersionFromReleasesBranchWithNumericPreReleaseTag()
{
using var fixture = new EmptyRepositoryFixture();
fixture.Repository.MakeCommits(5);
fixture.Repository.CreateBranch("releases/2.0.0");
fixture.Checkout("releases/2.0.0");
fixture.Repository.ApplyTag("v2.0.0-1");

var variables = fixture.GetVersion();
Assert.AreEqual("2.0.0-1", variables.FullSemVer);
}

[Test]
public void ReleaseBranchWithNextVersionSetInConfig()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class SemanticVersionTests : TestBase
[TestCase("1.2-alpha4", 1, 2, 0, "alpha", 4, null, null, null, null, "1.2.0-alpha.4", null)]
[TestCase("1.2.3-rc", 1, 2, 3, "rc", null, null, null, null, null, null, null)]
[TestCase("1.2.3-rc3", 1, 2, 3, "rc", 3, null, null, null, null, "1.2.3-rc.3", null)]
[TestCase("1.2.3-3", 1, 2, 3, "", 3, null, null, null, null, "1.2.3-3", null)]
[TestCase("1.2.3-RC3", 1, 2, 3, "RC", 3, null, null, null, null, "1.2.3-RC.3", null)]
[TestCase("1.2.3-rc3.1", 1, 2, 3, "rc3", 1, null, null, null, null, "1.2.3-rc3.1", null)]
[TestCase("01.02.03-rc03", 1, 2, 3, "rc", 3, null, null, null, null, "1.2.3-rc.3", null)]
Expand Down Expand Up @@ -119,6 +120,21 @@ public void ToStringSTests()
}
};
Assert.AreEqual("1.2.3-beta.4", fullSemVer.ToString("s"));
var fullSemVerNoPreReleaseName = new SemanticVersion
{
Major = 1,
Minor = 2,
Patch = 3,
PreReleaseTag = new SemanticVersionPreReleaseTag("", 4),
BuildMetaData = new SemanticVersionBuildMetaData
{
Sha = "theSha",
Branch = "TheBranch",
CommitsSinceTag = 5,
OtherMetaData = "TheOtherMetaData"
}
};
Assert.AreEqual("1.2.3-4", fullSemVerNoPreReleaseName.ToString("s"));
}
[Test]
public void ToStringLTests()
Expand Down Expand Up @@ -183,6 +199,21 @@ public void ToStringTests()
}
};
Assert.AreEqual("1.2.3-beta.4", fullSemVer.ToString());
var fullSemVerNoPreReleaseName = new SemanticVersion
{
Major = 1,
Minor = 2,
Patch = 3,
PreReleaseTag = new SemanticVersionPreReleaseTag("", 4),
BuildMetaData = new SemanticVersionBuildMetaData
{
Sha = "theSha",
Branch = "TheBranch",
CommitsSinceTag = 5,
OtherMetaData = "TheOtherMetaData"
}
};
Assert.AreEqual("1.2.3-4", fullSemVerNoPreReleaseName.ToString());
}
[Test]
public void ToStringFTests()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ public SemanticVersionPreReleaseTag(SemanticVersionPreReleaseTag preReleaseTag)
{
Name = preReleaseTag.Name;
Number = preReleaseTag.Number;
PromotedFromCommits = preReleaseTag.PromotedFromCommits;
}

public string Name { get; set; }
public int? Number { get; set; }
public bool PromotedFromCommits { get; set; }

public override bool Equals(object obj)
{
Expand Down Expand Up @@ -168,15 +170,15 @@ public string ToString(string format, IFormatProvider formatProvider = null)

return format switch
{
"t" => (Number.HasValue ? $"{Name}.{Number}" : Name),
"t" => (Number.HasValue ? string.IsNullOrEmpty(Name) ? $"{Number}" : $"{Name}.{Number}" : Name),
"l" => (Number.HasValue ? FormatLegacy(GetLegacyName(), Number.Value.ToString()) : FormatLegacy(GetLegacyName())),
_ => throw new ArgumentException("Unknown format", nameof(format))
};
}

private string FormatLegacy(string tag, string number = "")
{
var tagEndsWithANumber = char.IsNumber(tag.Last());
var tagEndsWithANumber = char.IsNumber(tag.LastOrDefault());
if (tagEndsWithANumber && number.Length > 0)
number = "-" + number;

Expand All @@ -188,13 +190,17 @@ private string FormatLegacy(string tag, string number = "")

private string GetLegacyName()
{
if (string.IsNullOrEmpty(Name))
{
return string.Empty;
}
var firstPart = Name.Split('_')[0];
return firstPart.Replace(".", string.Empty);
}

public bool HasTag()
{
return !string.IsNullOrEmpty(Name);
return !string.IsNullOrEmpty(Name) || (Number.HasValue && !PromotedFromCommits);
}
}
}
1 change: 1 addition & 0 deletions src/GitVersionCore/VersionCalculation/VariableProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ private static void PromoteNumberOfCommitsToTagNumber(SemanticVersion semanticVe
else
{
semanticVersion.PreReleaseTag.Number = semanticVersion.BuildMetaData.CommitsSinceTag;
semanticVersion.PreReleaseTag.PromotedFromCommits = true;
}
semanticVersion.BuildMetaData.CommitsSinceVersionSource = semanticVersion.BuildMetaData.CommitsSinceTag.Value;
semanticVersion.BuildMetaData.CommitsSinceTag = null; // why is this set to null ?
Expand Down