Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better feature branch support #189

Merged
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
4 changes: 2 additions & 2 deletions AcceptanceTests/GitFlow/MetaDataByCommitFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public void CanCorrectlyDetectCommitCountsAndReleaseDataWhenThatApplies()
EnsureMetaDataMatch(f, "hotfix-1.3.1", "1.3.1-beta.1+1", r => (Commit)r.Tags["1.3.0"].Target);

ResetToK(f.Repository);
EnsureMetaDataMatch(f, "feature", "1.4.0-unstable.0+2");
EnsureMetaDataMatch(f, "feature", "1.4.0-feature+2");

ResetToJ(f.Repository);
EnsureMetaDataMatch(f, "feature", "1.4.0-unstable.0+1");
EnsureMetaDataMatch(f, "feature", "1.4.0-feature+1");

ResetToI(f.Repository);
EnsureMetaDataMatch(f, "develop", "1.4.0.2-unstable");
Expand Down
2 changes: 1 addition & 1 deletion GitVersionCore/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void AppendLineFormat(this StringBuilder stringBuilder, string for

public static string TrimStart(this string value, string toTrim)
{
if (!value.StartsWith(toTrim))
if (!value.StartsWith(toTrim, StringComparison.InvariantCultureIgnoreCase))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think fody does this already?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup

Sent from my iPhone

On 07 Jun 2014, at 13:18, Jake Ginnivan notifications@github.com wrote:

In GitVersionCore/ExtensionMethods.cs:

@@ -29,7 +29,7 @@ public static void AppendLineFormat(this StringBuilder stringBuilder, string for

     public static string TrimStart(this string value, string toTrim)
     {
  •        if (!value.StartsWith(toTrim))
    
  •        if (!value.StartsWith(toTrim, StringComparison.InvariantCultureIgnoreCase))
    
    I think fody does this already?


Reply to this email directly or view it on GitHub.

{
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ protected SemanticVersion FindVersion(
var numberOfCommitsOnBranchSinceCommit = NumberOfCommitsOnBranchSinceCommit(context, ancestor);
var sha = context.CurrentBranch.Tip.Sha;
var releaseDate = ReleaseDateFinder.Execute(context.Repository, sha, 0);
var preReleaseTag = context.CurrentBranch.Name
.TrimStart(branchType.ToString() + '-')
.TrimStart(branchType.ToString() + '/');
var semanticVersion = new SemanticVersion
{
Major = versionFromMaster.Major,
Minor = versionFromMaster.Minor + 1,
Patch = 0,
PreReleaseTag = "unstable0",
PreReleaseTag = preReleaseTag,
BuildMetaData = new SemanticVersionBuildMetaData(
numberOfCommitsOnBranchSinceCommit,
context.CurrentBranch.Name, releaseDate)
Expand Down
21 changes: 19 additions & 2 deletions GitVersionCore/SemanticVersionPreReleaseTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,31 @@ public string ToString(string format, IFormatProvider formatProvider = null)
case "t":
return Number.HasValue ? string.Format("{0}.{1}", Name, Number) : Name;
case "l":
return Number.HasValue ? string.Format("{0}{1}", Name, Number) : Name;
return Number.HasValue ? FormatLegacy(GetLegacyName(), Number.ToString()) : FormatLegacy(GetLegacyName());
case "lp":
return Number.HasValue ? string.Format("{0}{1}", Name, Number.Value.ToString("D4")) : Name;
return Number.HasValue ? FormatLegacy(GetLegacyName(), Number.Value.ToString("D4")) : FormatLegacy(GetLegacyName());
default:
throw new ArgumentException("Unknown format", "format");
}
}

string FormatLegacy(string tag, string number = null)
{
var tagLength = tag.Length;
var numberLength = number == null ? 0 : number.Length;

if (tagLength + numberLength > 20)
return string.Format("{0}{1}", tag.Substring(0, 20 - numberLength), number);

return string.Format("{0}{1}", tag, number);
}

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

public bool HasTag()
{
return !string.IsNullOrEmpty(Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"Minor": 1,
"Patch": 0,
"PreReleaseTag": {
"Name": "unstable",
"Number": 0
"Name": "featureWithOneCommit",
"Number": null
},
"BuildMetaData": {
"CommitsSinceTag": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"Minor": 1,
"Patch": 0,
"PreReleaseTag": {
"Name": "unstable",
"Number": 0
"Name": "featureWithOneCommit",
"Number": null
},
"BuildMetaData": {
"CommitsSinceTag": 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"Minor": 1,
"Patch": 0,
"PreReleaseTag": {
"Name": "unstable",
"Number": 0
"Name": "featureWithOneCommit",
"Number": null
},
"BuildMetaData": {
"CommitsSinceTag": 2,
Expand Down
25 changes: 25 additions & 0 deletions Tests/GitFlow/GitFlowVersionFinderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,31 @@ public void AFeatureBranchDoesNotRequireASpecificPrefix()
}
}

[Test]
public void AFeatureBranchPrefixIsNotIncludedInTag()
{
var repoPath = Clone(ASBMTestRepoWorkingDirPath);
using (var repo = new Repository(repoPath))
{
repo.Branches["develop"].ForceCheckout();

const string branchName = "feature/ABC-1234_SomeDescription";
repo.Branches.Add(branchName, repo.Head.Tip).ForceCheckout();

AddOneCommitToHead(repo, "code");

var finder = new GitVersionFinder();

var versionAndBranch = finder.FindVersion(new GitVersionContext
{
Repository = repo,
CurrentBranch = repo.Head,
});

ObjectApprover.VerifyWithJson(versionAndBranch, Scrubbers.GuidAndDateScrubber);
}
}

[Test]
public void AReleaseBranchIsRequiredToBranchOffOfDevelopBranch()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"Minor": 1,
"Patch": 0,
"PreReleaseTag": {
"Name": "unstable",
"Number": 0
"Name": "every-feature-is-welcome",
"Number": null
},
"BuildMetaData": {
"CommitsSinceTag": 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"Major": 1,
"Minor": 1,
"Patch": 0,
"PreReleaseTag": {
"Name": "ABC-1234_SomeDescription",
"Number": null
},
"BuildMetaData": {
"CommitsSinceTag": 1,
"Branch": "feature/ABC-1234_SomeDescription",
"ReleaseDate": {
"OriginalDate": "<date replaced>",
"OriginalCommitSha": "000000000000000000000000000000000000000",
"Date": "<date replaced>",
"CommitSha": "000000000000000000000000000000000000000"
},
"Sha": "000000000000000000000000000000000000000",
"OtherMetaData": null
}
}
10 changes: 10 additions & 0 deletions Tests/SemanticVersionTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using GitVersion;
using NUnit.Framework;
using Shouldly;

[TestFixture]
public class SemanticVersionTests
Expand Down Expand Up @@ -51,5 +52,14 @@ public void ValidateInvalidVersionParsing(string versionString)
Assert.IsFalse(SemanticVersion.TryParse(versionString, out version), "TryParse Result");
}

[Test]
public void LegacySemVerTest()
{
new SemanticVersionPreReleaseTag("TKT-2134_JiraDescription", null).ToString("l").ShouldBe("TKT2134");
new SemanticVersionPreReleaseTag("AReallyReallyReallyLongBranchName", null).ToString("l").ShouldBe("AReallyReallyReallyL");
new SemanticVersionPreReleaseTag("TKT-2134_JiraDescription", 1).ToString("lp").ShouldBe("TKT21340001");
new SemanticVersionPreReleaseTag("AReallyReallyReallyLongBranchName", 1).ToString("lp").ShouldBe("AReallyReallyRea0001");
}


}