Skip to content

Commit 77008fa

Browse files
committed
Added GitHubFlow support branch test and fixed issue with / as separator in branch name
1 parent c3bd698 commit 77008fa

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

GitVersionCore.Tests/IntegrationTests/GitFlow/SupportBranchScenarios.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void SupportIsCalculatedCorrectly()
4242
// Create 1.2.1 hotfix
4343
fixture.Repository.CreateBranch("hotfix/1.2.1").Checkout();
4444
fixture.Repository.MakeACommit();
45-
fixture.AssertFullSemver("1.2.1-beta.1+3");
45+
fixture.AssertFullSemver("1.2.1-beta.1+3"); // TODO This should be +1
4646
fixture.Repository.Checkout("support/1.0.0");
4747
fixture.Repository.MergeNoFF("hotfix/1.2.1");
4848
fixture.AssertFullSemver("1.2.1");
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
namespace GitVersionCore.Tests.IntegrationTests.GitHubFlow
2+
{
3+
using GitVersion;
4+
using LibGit2Sharp;
5+
using NUnit.Framework;
6+
7+
[TestFixture]
8+
public class SupportBranchScenarios
9+
{
10+
[Test]
11+
public void SupportIsCalculatedCorrectly()
12+
{
13+
using (var fixture = new EmptyRepositoryFixture(new Config()))
14+
{
15+
// Start at 1.0.0
16+
fixture.Repository.MakeACommit();
17+
fixture.Repository.ApplyTag("1.1.0");
18+
19+
// Create 2.0.0 release
20+
fixture.Repository.CreateBranch("release-2.0.0").Checkout();
21+
fixture.Repository.MakeCommits(2);
22+
23+
// Merge into develop and master
24+
fixture.Repository.Checkout("master");
25+
fixture.Repository.MergeNoFF("release-2.0.0");
26+
fixture.Repository.ApplyTag("2.0.0");
27+
fixture.AssertFullSemver("2.0.0+0");
28+
29+
// Now lets support 1.x release
30+
fixture.Repository.Checkout("1.1.0");
31+
fixture.Repository.CreateBranch("support/1.0.0").Checkout();
32+
fixture.AssertFullSemver("1.1.0+0");
33+
34+
// Create release branch from support branch
35+
fixture.Repository.CreateBranch("release/1.2.0").Checkout();
36+
fixture.Repository.MakeACommit();
37+
fixture.AssertFullSemver("1.2.0-beta.1+1");
38+
39+
// Create 1.2.0 release
40+
fixture.Repository.Checkout("support/1.0.0");
41+
fixture.Repository.MergeNoFF("release/1.2.0");
42+
fixture.AssertFullSemver("1.2.0+2");
43+
fixture.Repository.ApplyTag("1.2.0");
44+
45+
// Create 1.2.1 hotfix
46+
fixture.Repository.CreateBranch("hotfix/1.2.1").Checkout();
47+
fixture.Repository.MakeACommit();
48+
fixture.AssertFullSemver("1.2.1+1");
49+
fixture.Repository.Checkout("support/1.0.0");
50+
fixture.Repository.MergeNoFF("hotfix/1.2.1");
51+
fixture.AssertFullSemver("1.2.1+2");
52+
}
53+
}
54+
}
55+
}

GitVersionCore/GitHubFlow/OtherBranchVersionFinder.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public bool FindVersion(GitVersionContext context, out SemanticVersion semanticV
3939

4040
SemanticVersionPreReleaseTag CreateDefaultPreReleaseTag(GitVersionContext context, string versionString)
4141
{
42-
return context.CurrentBranch.Name.Replace("-" + versionString, string.Empty) + ".1";
42+
return context.CurrentBranch.Name
43+
.Replace("-" + versionString, string.Empty)
44+
.Replace("/" + versionString, string.Empty) + ".1";
4345
}
4446

4547
static string GetUnknownBranchSuffix(Branch branch)

0 commit comments

Comments
 (0)