Skip to content

Commit 28d1fd5

Browse files
committed
Made sure it's still easy to add new branches to configuration.
1 parent 8a00164 commit 28d1fd5

16 files changed

+167
-42
lines changed

docs/configuration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ To resolve this issue we give GitVersion a hint to how we normally do our branch
277277

278278
This means that we will never bother to evaluate pull requests as merge base options, being explicit like this helps GitVersion be much faster too.
279279

280+
### is-source-branch-for
281+
The reverse of the above setting. This property was introduced to keep it easy to extend GitVersion's config.
282+
283+
When you add a new branch type this allows you to specify both source-branches for the new branch, and also add the new branch to existing branch configurations. For example if you create a new branch called `unstable` you could set a value of `['release', 'master', 'feature']` etc.
280284

281285
### branches
282286
The header for all the individual branch configuration.

src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ branches:
4646
source-branches:
4747
- develop
4848
- master
49+
- support
50+
- release
4951
tracks-release-branches: false
5052
is-release-branch: true
5153
is-mainline: false
@@ -94,6 +96,7 @@ branches:
9496
source-branches:
9597
- develop
9698
- master
99+
- support
97100
tracks-release-branches: false
98101
is-release-branch: false
99102
is-mainline: false

src/GitVersionCore.Tests/GitRepoMetadataProviderTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public void FindsCorrectMergeBaseForForwardMerge()
5252

5353
var develop = fixture.Repository.FindBranch("develop");
5454
var release = fixture.Repository.FindBranch("release-2.0.0");
55-
var releaseBranchMergeBase = new GitRepoMetadataProvider(fixture.Repository)
55+
var releaseBranchMergeBase = new GitRepoMetadataProvider(fixture.Repository, new Config())
5656
.FindMergeBase(release, develop);
5757

58-
var developMergeBase = new GitRepoMetadataProvider(fixture.Repository)
58+
var developMergeBase = new GitRepoMetadataProvider(fixture.Repository, new Config())
5959
.FindMergeBase(develop, release);
6060

6161
fixture.Repository.DumpGraph(Console.WriteLine);
@@ -109,10 +109,10 @@ public void FindsCorrectMergeBaseForForwardMergeMovesOn()
109109

110110
var develop = fixture.Repository.FindBranch("develop");
111111
var release = fixture.Repository.FindBranch("release-2.0.0");
112-
var releaseBranchMergeBase = new GitRepoMetadataProvider(fixture.Repository)
112+
var releaseBranchMergeBase = new GitRepoMetadataProvider(fixture.Repository, new Config())
113113
.FindMergeBase(release, develop);
114114

115-
var developMergeBase = new GitRepoMetadataProvider(fixture.Repository)
115+
var developMergeBase = new GitRepoMetadataProvider(fixture.Repository, new Config())
116116
.FindMergeBase(develop, release);
117117

118118
fixture.Repository.DumpGraph(Console.WriteLine);
@@ -184,10 +184,10 @@ public void FindsCorrectMergeBaseForMultipleForwardMerges()
184184

185185
var develop = fixture.Repository.FindBranch("develop");
186186
var release = fixture.Repository.FindBranch("release-2.0.0");
187-
var releaseBranchMergeBase = new GitRepoMetadataProvider(fixture.Repository)
187+
var releaseBranchMergeBase = new GitRepoMetadataProvider(fixture.Repository, new Config())
188188
.FindMergeBase(release, develop);
189189

190-
var developMergeBase = new GitRepoMetadataProvider(fixture.Repository)
190+
var developMergeBase = new GitRepoMetadataProvider(fixture.Repository, new Config())
191191
.FindMergeBase(develop, release);
192192

193193
fixture.Repository.DumpGraph(Console.WriteLine);

src/GitVersionCore.Tests/GitVersionContextTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using LibGit2Sharp;
66
using NUnit.Framework;
77
using Shouldly;
8+
using System.Collections.Generic;
89

910
public class GitVersionContextTests
1011
{
@@ -98,8 +99,8 @@ public void UsesFirstBranchConfigWhenMultipleMatch()
9899
VersioningMode = VersioningMode.ContinuousDelivery,
99100
Branches =
100101
{
101-
{ "release/latest", new BranchConfig { Increment = IncrementStrategy.None, Regex = "release/latest", SourceBranches = new string[0] } },
102-
{ "release", new BranchConfig { Increment = IncrementStrategy.Patch, Regex = "releases?[/-]", SourceBranches = new string[0] } }
102+
{ "release/latest", new BranchConfig { Increment = IncrementStrategy.None, Regex = "release/latest", SourceBranches = new List<string>() } },
103+
{ "release", new BranchConfig { Increment = IncrementStrategy.Patch, Regex = "releases?[/-]", SourceBranches = new List<string>() } }
103104
}
104105
}.ApplyDefaults();
105106

src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using GitVersionCore.Tests;
44
using LibGit2Sharp;
55
using NUnit.Framework;
6+
using System.Collections.Generic;
67

78
[TestFixture]
89
public class DevelopScenarios
@@ -65,7 +66,7 @@ public void CanChangeDevelopTagViaConfig()
6566
"develop", new BranchConfig
6667
{
6768
Tag = "alpha",
68-
SourceBranches = new string[0]
69+
SourceBranches = new List<string>()
6970
}
7071
}
7172
}

src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,16 @@ public void BranchCreatedAfterFastForwardMergeShouldInheritCorrectly()
4242
{
4343
Branches =
4444
{
45-
{ "unstable", new BranchConfig {
46-
Increment = IncrementStrategy.Minor, Regex = "unstable", SourceBranches = new string[0]
47-
} }
45+
{
46+
"unstable",
47+
new BranchConfig
48+
{
49+
Increment = IncrementStrategy.Minor,
50+
Regex = "unstable",
51+
SourceBranches = new List<string>(),
52+
IsSourceBranchFor = new [] { "feature" }
53+
}
54+
}
4855
}
4956
};
5057

src/GitVersionCore.Tests/IntegrationTests/OtherScenarios.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using GitVersion;
66
using LibGit2Sharp;
77
using NUnit.Framework;
8+
using System.Collections.Generic;
89

910
[TestFixture]
1011
public class OtherScenarios
@@ -57,7 +58,7 @@ public void AllowHavingMainInsteadOfMaster()
5758
Increment = IncrementStrategy.Patch,
5859
PreventIncrementOfMergedBranchVersion = true,
5960
TrackMergeTarget = false,
60-
SourceBranches = new string[0]
61+
SourceBranches = new List<string>()
6162
});
6263

6364
using (var fixture = new EmptyRepositoryFixture())

src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ public void CommitOnDevelop_AfterReleaseBranchMergeToDevelop_ShouldNotResetCount
418418
fixture.AssertFullSemver(config, "2.0.0-beta.5");
419419
}
420420
}
421-
421+
422422
public void ReleaseBranchShouldUseBranchNameVersionDespiteBumpInPreviousCommit()
423423
{
424424
using (var fixture = new EmptyRepositoryFixture())
@@ -463,4 +463,53 @@ public void ReleaseBranchedAtCommitWithSemverMessageShouldUseBranchNameVersion()
463463
fixture.AssertFullSemver("2.0.0-beta.1+1");
464464
}
465465
}
466+
467+
[Test]
468+
public void FeatureFromReleaseBranch_ShouldNotResetCount()
469+
{
470+
var config = new Config
471+
{
472+
VersioningMode = VersioningMode.ContinuousDeployment
473+
};
474+
475+
using (var fixture = new EmptyRepositoryFixture())
476+
{
477+
fixture.Repository.MakeACommit("initial");
478+
fixture.Repository.CreateBranch("develop");
479+
Commands.Checkout(fixture.Repository, "develop");
480+
fixture.Repository.CreateBranch("release-2.0.0");
481+
Commands.Checkout(fixture.Repository, "release-2.0.0");
482+
fixture.AssertFullSemver(config, "2.0.0-beta.0");
483+
484+
// Make some commits on release
485+
fixture.Repository.MakeCommits(10);
486+
fixture.AssertFullSemver(config, "2.0.0-beta.10");
487+
488+
// Create feature from release
489+
fixture.BranchTo("feature/xxx");
490+
fixture.Repository.MakeACommit("feature 1");
491+
fixture.Repository.MakeACommit("feature 2");
492+
493+
// Check version on release
494+
Commands.Checkout(fixture.Repository, "release-2.0.0");
495+
fixture.AssertFullSemver(config, "2.0.0-beta.10");
496+
fixture.Repository.MakeACommit("release 11");
497+
fixture.AssertFullSemver(config, "2.0.0-beta.11");
498+
499+
// Make new commit on feature
500+
Commands.Checkout(fixture.Repository, "feature/xxx");
501+
fixture.Repository.MakeACommit("feature 3");
502+
503+
// Checkout to release (no new commits)
504+
Commands.Checkout(fixture.Repository, "release-2.0.0");
505+
fixture.AssertFullSemver(config, "2.0.0-beta.11");
506+
507+
// Merge feature to release
508+
fixture.Repository.MergeNoFF("feature/xxx", Generate.SignatureNow());
509+
fixture.AssertFullSemver(config, "2.0.0-beta.15");
510+
511+
fixture.Repository.MakeACommit("release 13 - after feature merge");
512+
fixture.AssertFullSemver(config, "2.0.0-beta.16");
513+
}
514+
}
466515
}

src/GitVersionCore.Tests/IntegrationTests/VersionBumpingScenarios.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using GitVersion;
33
using GitVersionCore.Tests;
44
using NUnit.Framework;
5+
using System.Collections.Generic;
56

67
[TestFixture]
78
public class VersionBumpingScenarios
@@ -17,7 +18,7 @@ public void AppliedPrereleaseTagCausesBump()
1718
"master", new BranchConfig
1819
{
1920
Tag = "pre",
20-
SourceBranches = new string[0]
21+
SourceBranches = new List<string>()
2122
}
2223
}
2324
}

src/GitVersionCore.Tests/VersionCalculation/NextVersionCalculatorTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void PreReleaseTagCanUseBranchName()
6868
{
6969
Regex = "custom/",
7070
Tag = "useBranchName",
71-
SourceBranches = new string[0]
71+
SourceBranches = new List<string>()
7272
}
7373
}
7474
}
@@ -99,7 +99,7 @@ public void PreReleaseTagCanUseBranchNameVariable()
9999
{
100100
Regex = "custom/",
101101
Tag = "alpha.{BranchName}",
102-
SourceBranches = new string[0]
102+
SourceBranches = new List<string>()
103103
}
104104
}
105105
}

0 commit comments

Comments
 (0)