Skip to content

Commit 8a00164

Browse files
committed
Introduced source-branches config option
This allows GitVersion to know what branches it should take into account for calculating merge base. This locks it down a little more, but is an easier to explain behavior than commit counting randomly resetting because GitVersion cannot effectively figure out which branch the current branch was branched off.
1 parent a99f256 commit 8a00164

12 files changed

+122
-30
lines changed

docs/configuration.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,41 @@ values, but here they are if you need to:
243243
### regex
244244
This is the regex which is used to match the current branch to the correct branch configuration.
245245

246+
### source-branches
247+
Because git is a directed graph GitVersion sometimes cannot tell which branch the current branch was branched from.
248+
249+
Take this graph
250+
251+
```
252+
* feature/foo
253+
* | release/1.0.0
254+
|/
255+
*
256+
*
257+
* (master)
258+
```
259+
260+
By looking at this graph, you cannot tell which of these scenarios happened
261+
262+
1. feature/foo branches off release/1.0.0
263+
- Branch release/1.0.0 from master
264+
- Branch feature/foo from release/1.0.0
265+
- Add a commit to both release/1.0.0 and feature/foo
266+
- release/1.0.0 is the base for feature/foo
267+
268+
2. release/1.0.0 branches off feature/foo
269+
- Branch feature/foo from master
270+
- Branch release/1.0.0 from feature/foo
271+
- Add a commit to both release/1.0.0 and feature/foo
272+
- feature/foo is the base for release/1.0.0
273+
274+
To resolve this issue we give GitVersion a hint to how we normally do our branching, feature branches have a value of:
275+
276+
`sourceBranches: ['master', 'develop', 'feature', 'hotfix', 'support']`
277+
278+
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.
279+
280+
246281
### branches
247282
The header for all the individual branch configuration.
248283

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

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,27 @@ build-metadata-padding: 4
1212
commits-since-version-source-padding: 4
1313
commit-message-incrementing: Enabled
1414
branches:
15+
develop:
16+
mode: ContinuousDeployment
17+
tag: alpha
18+
increment: Minor
19+
prevent-increment-of-merged-branch-version: false
20+
track-merge-target: true
21+
regex: dev(elop)?(ment)?$
22+
source-branches: []
23+
tracks-release-branches: true
24+
is-release-branch: false
25+
is-mainline: false
1526
master:
1627
mode: ContinuousDelivery
1728
tag: ''
1829
increment: Patch
1930
prevent-increment-of-merged-branch-version: true
2031
track-merge-target: false
2132
regex: master
33+
source-branches:
34+
- develop
35+
- release
2236
tracks-release-branches: false
2337
is-release-branch: false
2438
is-mainline: true
@@ -29,6 +43,9 @@ branches:
2943
prevent-increment-of-merged-branch-version: true
3044
track-merge-target: false
3145
regex: releases?[/-]
46+
source-branches:
47+
- develop
48+
- master
3249
tracks-release-branches: false
3350
is-release-branch: true
3451
is-mainline: false
@@ -39,6 +56,13 @@ branches:
3956
prevent-increment-of-merged-branch-version: false
4057
track-merge-target: false
4158
regex: features?[/-]
59+
source-branches:
60+
- develop
61+
- master
62+
- release
63+
- feature
64+
- support
65+
- hotfix
4266
tracks-release-branches: false
4367
is-release-branch: false
4468
is-mainline: false
@@ -50,6 +74,13 @@ branches:
5074
tag-number-pattern: '[/-](?<number>\d+)'
5175
track-merge-target: false
5276
regex: (pull|pull\-requests|pr)[/-]
77+
source-branches:
78+
- develop
79+
- master
80+
- release
81+
- feature
82+
- support
83+
- hotfix
5384
tracks-release-branches: false
5485
is-release-branch: false
5586
is-mainline: false
@@ -60,6 +91,9 @@ branches:
6091
prevent-increment-of-merged-branch-version: false
6192
track-merge-target: false
6293
regex: hotfix(es)?[/-]
94+
source-branches:
95+
- develop
96+
- master
6397
tracks-release-branches: false
6498
is-release-branch: false
6599
is-mainline: false
@@ -70,18 +104,10 @@ branches:
70104
prevent-increment-of-merged-branch-version: true
71105
track-merge-target: false
72106
regex: support[/-]
107+
source-branches:
108+
- master
73109
tracks-release-branches: false
74110
is-release-branch: false
75111
is-mainline: true
76-
develop:
77-
mode: ContinuousDeployment
78-
tag: alpha
79-
increment: Minor
80-
prevent-increment-of-merged-branch-version: false
81-
track-merge-target: true
82-
regex: dev(elop)?(ment)?$
83-
tracks-release-branches: true
84-
is-release-branch: false
85-
is-mainline: false
86112
ignore:
87113
sha: []

src/GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ public void CanProvideConfigForNewBranch()
111111
branches:
112112
bug:
113113
regex: 'bug[/-]'
114-
tag: bugfix";
114+
tag: bugfix
115+
source-branches: []";
115116
SetupConfigFileContent(text);
116117
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
117118

src/GitVersionCore.Tests/GitVersionContextTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ public void UsesFirstBranchConfigWhenMultipleMatch()
9898
VersioningMode = VersioningMode.ContinuousDelivery,
9999
Branches =
100100
{
101-
{ "release/latest", new BranchConfig { Increment = IncrementStrategy.None, Regex = "release/latest" } },
102-
{ "release", new BranchConfig { Increment = IncrementStrategy.Patch, Regex = "releases?[/-]" } }
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] } }
103103
}
104104
}.ApplyDefaults();
105105

src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public void CanChangeDevelopTagViaConfig()
6464
{
6565
"develop", new BranchConfig
6666
{
67-
Tag = "alpha"
67+
Tag = "alpha",
68+
SourceBranches = new string[0]
6869
}
6970
}
7071
}

src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public void BranchCreatedAfterFastForwardMergeShouldInheritCorrectly()
4242
{
4343
Branches =
4444
{
45-
{ "unstable", new BranchConfig { Increment = IncrementStrategy.Minor, Regex = "unstable"} }
45+
{ "unstable", new BranchConfig {
46+
Increment = IncrementStrategy.Minor, Regex = "unstable", SourceBranches = new string[0]
47+
} }
4648
}
4749
};
4850

src/GitVersionCore.Tests/IntegrationTests/OtherScenarios.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public void AllowHavingMainInsteadOfMaster()
5656
Tag = "useBranchName",
5757
Increment = IncrementStrategy.Patch,
5858
PreventIncrementOfMergedBranchVersion = true,
59-
TrackMergeTarget = false
59+
TrackMergeTarget = false,
60+
SourceBranches = new string[0]
6061
});
6162

6263
using (var fixture = new EmptyRepositoryFixture())

src/GitVersionCore.Tests/IntegrationTests/VersionBumpingScenarios.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ public void AppliedPrereleaseTagCausesBump()
1313
{
1414
Branches =
1515
{
16-
{ "master", new BranchConfig { Tag = "pre" } }
16+
{
17+
"master", new BranchConfig
18+
{
19+
Tag = "pre",
20+
SourceBranches = new string[0]
21+
}
22+
}
1723
}
1824
};
1925
using (var fixture = new EmptyRepositoryFixture())

src/GitVersionCore.Tests/VersionCalculation/NextVersionCalculatorTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public void PreReleaseTagCanUseBranchName()
6767
"custom", new BranchConfig
6868
{
6969
Regex = "custom/",
70-
Tag = "useBranchName"
70+
Tag = "useBranchName",
71+
SourceBranches = new string[0]
7172
}
7273
}
7374
}
@@ -97,7 +98,8 @@ public void PreReleaseTagCanUseBranchNameVariable()
9798
"custom", new BranchConfig
9899
{
99100
Regex = "custom/",
100-
Tag = "alpha.{BranchName}"
101+
Tag = "alpha.{BranchName}",
102+
SourceBranches = new string[0]
101103
}
102104
}
103105
}

src/GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static BranchConfig GetBranchConfiguration(GitVersionContext context, Bra
2222
targetBranch.FriendlyName));
2323

2424
matchingBranches = new BranchConfig { Name = string.Empty };
25-
ConfigurationProvider.ApplyBranchDefaults(context.FullConfiguration, matchingBranches, "");
25+
ConfigurationProvider.ApplyBranchDefaults(context.FullConfiguration, matchingBranches, "", new string[0]);
2626
}
2727

2828
return matchingBranches.Increment == IncrementStrategy.Inherit ?

0 commit comments

Comments
 (0)