Skip to content

Commit 92388ad

Browse files
authored
Merge pull request #3190 from HHobeck/feature/3101
Change the logic inheriting BranchConfiguration from parent branch if the IncrementStrategy is set to Inherit
2 parents 816d7e4 + 1397f03 commit 92388ad

File tree

63 files changed

+2821
-1400
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2821
-1400
lines changed

BREAKING_CHANGES.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
## Unreleased
22

33
* When using a commit message that matches **both** `*-version-bump-message` and `no-bump-message`, there is no increment for that commit. In other words, `no-bump-message` now takes precedence over `*-version-bump-message`.
4+
* The fallback version strategy now returns `0.0.0` and is flagged with `ShouldIncrement` equal to `true`. This yields the version `0.1.0` on the `develop` branch (`IncrementStrategy.Minor` by default) and `0.0.1` on the `main` branch (`IncremetnStrategy.Patch` by default).
5+
* The current branch (child) inherits its configuration from the source (parent) branch if the `increment` strategy is set to `Inherit`. This makes branch configuration recursive, simpler, more intuitive, more flexible, and more robust.
6+
* Instead of having a single effective configuration, we now have one effective configuration per branch where the increment strategy is not set to `inherit`.
7+
* The new implementation of the branch configuration inheritance affects per default only the pull-requests, hotfix and feature branches. In this case the next version will be generated like the child branch is not existing and the commits have been made on the source branch.
8+
* The following example illustrates this behavior. On the feature branch the semantic version `1.1.0-just-a-test.1+2` will now be generated instead of version `1.0.0-just-a-test.1+3` previously:
9+
```
10+
* 1f1cfb4 52 minutes ago (HEAD -> feature/just-a-test)
11+
* 1f9654d 54 minutes ago (release/1.1.0)
12+
* be72411 56 minutes ago (develop)
13+
* 14800ff 58 minutes ago (tag: 1.0.0, main)
14+
```
415
516
## v5.0.0
617

docs/input/docs/learn/how-it-works.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ Currently we have the following strategies:
4747
GitVersion.yaml file
4848
* `MergeMessageBaseVersionStrategy` - Finds version numbers from merge messages
4949
(e.g., `Merge 'release/3.0.0' into 'main'` will return `3.0.0`)
50-
* `FallbackBaseVersionStrategy` - Always returns 0.1.0 for new repositories
50+
* `FallbackBaseVersionStrategy` - Always returns 0.0.0 and will be used for
51+
calculating the next version which is dependent on the increment strategy of
52+
the effected branch (e.g. on main the next version is 0.0.1 or on develop it is 0.1.0)
5153

5254
Each strategy needs to return an instance of `BaseVersion` which has the
5355
following properties:

docs/input/docs/reference/configuration.md

+4-19
Original file line numberDiff line numberDiff line change
@@ -329,39 +329,24 @@ branches:
329329
feature:
330330
regex: ^features?[/-]
331331
mode: ContinuousDelivery
332-
tag: useBranchName
332+
tag: '{BranchName}'
333333
increment: Inherit
334-
prevent-increment-of-merged-branch-version: false
335-
track-merge-target: false
336334
source-branches: [ 'develop', 'main', 'release', 'feature', 'support', 'hotfix' ]
337-
tracks-release-branches: false
338-
is-release-branch: false
339-
is-mainline: false
340-
pre-release-weight: 30000
335+
pre-release-weight: 30000
341336
pull-request:
342337
regex: ^(pull|pull\-requests|pr)[/-]
343338
mode: ContinuousDelivery
344339
tag: PullRequest
345340
increment: Inherit
346-
prevent-increment-of-merged-branch-version: false
347341
tag-number-pattern: '[/-](?<number>\d+)[-/]'
348-
track-merge-target: false
349342
source-branches: [ 'develop', 'main', 'release', 'feature', 'support', 'hotfix' ]
350-
tracks-release-branches: false
351-
is-release-branch: false
352-
is-mainline: false
353343
pre-release-weight: 30000
354344
hotfix:
355345
regex: ^hotfix(es)?[/-]
356346
mode: ContinuousDelivery
357347
tag: beta
358-
increment: Patch
359-
prevent-increment-of-merged-branch-version: false
360-
track-merge-target: false
361-
source-branches: [ 'develop', 'main', 'support' ]
362-
tracks-release-branches: false
363-
is-release-branch: false
364-
is-mainline: false
348+
increment: Inherit
349+
source-branches: [ 'release', 'main', 'support', 'hotfix' ]
365350
pre-release-weight: 30000
366351
support:
367352
regex: ^support[/-]

src/GitVersion.App.Tests/JsonOutputOnBuildServerTest.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public void BeingOnBuildServerWithOutputJsonDoesNotFail()
3737
var result = GitVersionHelper.ExecuteIn(fixture.LocalRepositoryFixture.RepositoryPath, arguments: " /output json /output buildserver", environments: env);
3838

3939
result.ExitCode.ShouldBe(0);
40-
const string version = "0.1.0+4";
41-
result.Output.ShouldContain($"##teamcity[buildNumber '{version}']");
40+
const string expectedVersion = "0.0.1+5";
41+
result.Output.ShouldContain($"##teamcity[buildNumber '{expectedVersion}']");
4242
result.OutputVariables.ShouldNotBeNull();
43-
result.OutputVariables.FullSemVer.ShouldBeEquivalentTo(version);
43+
result.OutputVariables.FullSemVer.ShouldBeEquivalentTo(expectedVersion);
4444
}
4545

4646
[TestCase("", "GitVersion.json")]
@@ -56,16 +56,16 @@ public void BeingOnBuildServerWithOutputJsonAndOutputFileDoesNotFail(string outp
5656
var result = GitVersionHelper.ExecuteIn(fixture.LocalRepositoryFixture.RepositoryPath, arguments: $" /output json /output buildserver /output file /outputfile {outputFile}", environments: env);
5757

5858
result.ExitCode.ShouldBe(0);
59-
const string version = "0.1.0+4";
60-
result.Output.ShouldContain($"##teamcity[buildNumber '{version}']");
59+
const string expectedVersion = "0.0.1+5";
60+
result.Output.ShouldContain($"##teamcity[buildNumber '{expectedVersion}']");
6161
result.OutputVariables.ShouldNotBeNull();
62-
result.OutputVariables.FullSemVer.ShouldBeEquivalentTo(version);
62+
result.OutputVariables.FullSemVer.ShouldBeEquivalentTo(expectedVersion);
6363

6464
var filePath = PathHelper.Combine(fixture.LocalRepositoryFixture.RepositoryPath, fileName);
6565
var json = File.ReadAllText(filePath);
6666

6767
var outputVariables = VersionVariables.FromJson(json);
6868
outputVariables.ShouldNotBeNull();
69-
outputVariables.FullSemVer.ShouldBeEquivalentTo(version);
69+
outputVariables.FullSemVer.ShouldBeEquivalentTo(expectedVersion);
7070
}
7171
}

src/GitVersion.Core.Tests/Configuration/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt

+1-6
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,13 @@ branches:
8282
hotfix:
8383
mode: ContinuousDelivery
8484
tag: beta
85-
increment: Patch
86-
prevent-increment-of-merged-branch-version: false
87-
track-merge-target: false
85+
increment: Inherit
8886
regex: ^hotfix(es)?[/-]
8987
source-branches:
9088
- release
9189
- main
9290
- support
9391
- hotfix
94-
tracks-release-branches: false
95-
is-release-branch: false
96-
is-mainline: false
9792
pre-release-weight: 30000
9893
support:
9994
mode: ContinuousDelivery

src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public void CacheFileExistsOnDisk()
150150
var gitVersionCalculator = GetGitVersionCalculator(gitVersionOptions, this.log);
151151

152152
var versionVariables = gitVersionCalculator.CalculateVersionVariables();
153-
versionVariables.AssemblySemVer.ShouldBe("0.1.0.0");
153+
versionVariables.AssemblySemVer.ShouldBe("0.0.1.0");
154154

155155
this.fileSystem.WriteAllText(versionVariables.FileName, versionCacheFileContent);
156156
versionVariables = gitVersionCalculator.CalculateVersionVariables();
@@ -197,7 +197,7 @@ public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDyn
197197
var gitVersionCalculator = GetGitVersionCalculator(gitVersionOptions, this.log);
198198

199199
var versionVariables = gitVersionCalculator.CalculateVersionVariables();
200-
versionVariables.AssemblySemVer.ShouldBe("0.1.0.0");
200+
versionVariables.AssemblySemVer.ShouldBe("0.0.1.0");
201201

202202
this.fileSystem.WriteAllText(versionVariables.FileName, versionCacheFileContent);
203203

@@ -211,7 +211,7 @@ public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDyn
211211
gitVersionCalculator = GetGitVersionCalculator(gitVersionOptions);
212212
versionVariables = gitVersionCalculator.CalculateVersionVariables();
213213

214-
versionVariables.AssemblySemVer.ShouldBe("0.1.0.0");
214+
versionVariables.AssemblySemVer.ShouldBe("0.0.1.0");
215215

216216
var cachedDirectoryTimestampAfter = this.fileSystem.GetLastDirectoryWrite(cacheDirectory);
217217
cachedDirectoryTimestampAfter.ShouldBe(cacheDirectoryTimestamp, "Cache was updated when override config was set");
@@ -279,7 +279,7 @@ public void ConfigChangeInvalidatesCache()
279279
var gitVersionCalculator = GetGitVersionCalculator(gitVersionOptions);
280280
var versionVariables = gitVersionCalculator.CalculateVersionVariables();
281281

282-
versionVariables.AssemblySemVer.ShouldBe("0.1.0.0");
282+
versionVariables.AssemblySemVer.ShouldBe("0.0.1.0");
283283
versionVariables.FileName.ShouldNotBeNullOrEmpty();
284284

285285
this.fileSystem.WriteAllText(versionVariables.FileName, versionCacheFileContent);
@@ -336,7 +336,7 @@ public void NoCacheBypassesCache()
336336

337337
var versionVariables = gitVersionCalculator.CalculateVersionVariables();
338338

339-
versionVariables.AssemblySemVer.ShouldBe("0.1.0.0");
339+
versionVariables.AssemblySemVer.ShouldBe("0.0.1.0");
340340
versionVariables.FileName.ShouldNotBeNullOrEmpty();
341341

342342
this.fileSystem.WriteAllText(versionVariables.FileName, versionCacheFileContent);
@@ -345,7 +345,7 @@ public void NoCacheBypassesCache()
345345

346346
gitVersionOptions.Settings.NoCache = true;
347347
versionVariables = gitVersionCalculator.CalculateVersionVariables();
348-
versionVariables.AssemblySemVer.ShouldBe("0.1.0.0");
348+
versionVariables.AssemblySemVer.ShouldBe("0.0.1.0");
349349
}
350350

351351
[Test]

src/GitVersion.Core.Tests/Core/RepositoryStoreTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void FindsCorrectMergeBaseForForwardMerge()
6868

6969
var developMergeBase = gitRepoMetadataProvider.FindMergeBase(develop, release);
7070

71-
fixtureRepository.DumpGraph(Console.WriteLine);
71+
fixtureRepository.DumpGraph();
7272

7373
releaseBranchMergeBase.ShouldBe(expectedReleaseMergeBase);
7474
developMergeBase.ShouldBe(expectedDevelopMergeBase);
@@ -124,7 +124,7 @@ public void FindsCorrectMergeBaseForForwardMergeMovesOn()
124124

125125
var developMergeBase = gitRepoMetadataProvider.FindMergeBase(develop, release);
126126

127-
fixtureRepository.DumpGraph(Console.WriteLine);
127+
fixtureRepository.DumpGraph();
128128

129129
releaseBranchMergeBase.ShouldBe(expectedReleaseMergeBase);
130130
developMergeBase.ShouldBe(expectedDevelopMergeBase);
@@ -199,7 +199,7 @@ public void FindsCorrectMergeBaseForMultipleForwardMerges()
199199

200200
var developMergeBase = gitRepoMetadataProvider.FindMergeBase(develop, release);
201201

202-
fixtureRepository.DumpGraph(Console.WriteLine);
202+
fixtureRepository.DumpGraph();
203203

204204
releaseBranchMergeBase.ShouldBe(expectedReleaseMergeBase);
205205
developMergeBase.ShouldBe(expectedDevelopMergeBase);

src/GitVersion.Core.Tests/Extensions/GitToolsTestingExtensions.cs

-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ public static void WriteVersionVariables(this RepositoryFixtureBase fixture, str
106106

107107
public static void AssertFullSemver(this RepositoryFixtureBase fixture, string fullSemver, Config? configuration = null, IRepository? repository = null, string? commitId = null, bool onlyTrackedBranches = true, string? targetBranch = null)
108108
{
109-
configuration ??= new Config();
110-
configuration = new ConfigurationBuilder().Add(configuration).Build();
111109
Console.WriteLine("---------");
112110

113111
try

src/GitVersion.Core.Tests/Helpers/TestConfigurationBuilder.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public sealed class TestConfigurationBuilder
88
{
99
public static TestConfigurationBuilder New => new();
1010

11-
private string? nextVerson;
11+
private string? nextVersion;
1212
private VersioningMode? versioningMode;
1313
private readonly Dictionary<string, VersioningMode?> versioningModeDictionary = new();
1414
private bool withoutAnyTrackMergeTargets;
@@ -28,7 +28,7 @@ private TestConfigurationBuilder()
2828

2929
public TestConfigurationBuilder WithNextVersion(string? value)
3030
{
31-
nextVerson = value;
31+
nextVersion = value;
3232
return this;
3333
}
3434

@@ -109,7 +109,7 @@ public Config Build()
109109
{
110110
Config configuration = new()
111111
{
112-
NextVersion = nextVerson,
112+
NextVersion = nextVersion,
113113
VersioningMode = versioningMode
114114
};
115115

0 commit comments

Comments
 (0)