Skip to content

Commit 61efda5

Browse files
authored
Merge pull request #1103 from JakeGinnivan/default-inherit
Default inherit
2 parents 11891f3 + ad3590d commit 61efda5

26 files changed

+609
-167
lines changed

docs/configuration.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ next-version: 1.0
3232
assembly-versioning-scheme: MajorMinorPatch
3333
assembly-informational-format: '{InformationalVersion}'
3434
mode: ContinuousDelivery
35+
increment: Inherit
3536
continuous-delivery-fallback-tag: ci
3637
tag-prefix: '[vV]'
3738
major-version-bump-message: '\+semver:\s?(breaking|major)'
@@ -70,6 +71,11 @@ value of the `AssemblyInformationalVersion` attribute. Default set to
7071
Sets the `mode` of how GitVersion should create a new version. Read more at
7172
[versioning mode](/reference/versioning-mode.md).
7273

74+
### increment
75+
The part of the SemVer to increment when GitVersion detects it needs to be increased, such as for commits after a tag: `Major`, `Minor`, `Patch`, `None`.
76+
77+
The special value `Inherit` means that GitVersion should find the parent branch (i.e. the branch where the current branch was branched from), and use its values for [increment](#increment), [prevent-increment-of-merged-branch-version](#prevent-increment-of-merged-branch-version) and [is-develop](#is-develop).
78+
7379
### continuous-delivery-fallback-tag
7480
When using `mode: ContinuousDeployment`, the value specified in
7581
`continuous-delivery-fallback-tag` will be used as the pre-release tag for
@@ -246,8 +252,7 @@ of `alpha.foo` with the value of `alpha.{BranchName}`.
246252
**Note:** To clear a default use an empty string: `tag: ''`
247253

248254
### increment
249-
The part of the SemVer to increment when GitVersion detects it needs to be (i.e
250-
commit after a tag)
255+
Same as for the [global configuration, explained above](#increment).
251256

252257
### prevent-increment-of-merged-branch-version
253258
When `release-2.0.0` is merged into master, we want master to build `2.0.0`. If

docs/more-info/version-sources.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Version Sources
2-
GitVersion has a two step process for calculating the version number, the first is to calculate the base version which is used to then calculate what the next version should be.
2+
GitVersion has a two step process for calculating the version number. First it calculates the base version, which is then used to calculate what the next version should be.
33

44
The logic of GitVersion is something like this:
55

@@ -8,26 +8,38 @@ The logic of GitVersion is something like this:
88
- No: continue
99
- Calculate the base version (highest version from all the sources)
1010
- Increment version if needed based on branch config
11-
- Calculate the build metadata (everything after the +) and append to the calcuated version
11+
- Calculate the build metadata (everything after the +) and append to the calculated version
1212

1313
## Version Sources
14-
### Highest Accessible Tag
15-
GitVersion will find all tags on the current branch and return the highest one.
14+
### Tag name
15+
Returns the version numbers extracted from the current branch's tags.
1616

1717
Will increment: true
1818

1919
### Version in branch name
20-
If the branch has a version in it, then that version will be returned.
20+
Returns the version number from the branch's name.
2121

2222
Will increment: false
2323

2424
### Merge message
25-
If a branch with a version number in it is merged into the current branch, that version number will be used.
25+
Returns the version number of any branch (with a version number in its name) merged into the current branch.
2626

27-
Will increment: false
27+
Will increment: depends on the value of `prevent-increment-of-merged-branch-version`
2828

2929
### GitVersion.yml
30-
If the `next-version` property is specified in the config file, it will be used as a version source.
30+
Returns the value of the `next-version` property in the config file.
31+
32+
Will increment: false
33+
34+
### Develop branch
35+
For the develop branch, i.e. marked with `is-develop: true`
36+
- Returns the version number extracted from any child release-branches, i.e. those marked with `is-release-branch: true`
37+
- Returns the version number of any tags on the master branch
38+
39+
Will increment: true
40+
41+
### Fallback
42+
Returns the version number `0.1.0`.
3143

3244
Will increment: false
3345

src/GitVersionCore.Tests/GitVersionContextTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,34 @@ public void CanInheritVersioningMode(VersioningMode mode)
3131
context.Configuration.VersioningMode.ShouldBe(mode);
3232
}
3333

34+
[TestCase(IncrementStrategy.Inherit, IncrementStrategy.Patch)] // Since it inherits, the increment strategy of master is used => Patch
35+
[TestCase(IncrementStrategy.Patch, null)]
36+
[TestCase(IncrementStrategy.Major, null)]
37+
[TestCase(IncrementStrategy.Minor, null)]
38+
[TestCase(IncrementStrategy.None, null)]
39+
public void CanInheritIncrement(IncrementStrategy increment, IncrementStrategy? alternateExpected)
40+
{
41+
// Dummy branch name to make sure that no default config exists.
42+
const string dummyBranchName = "dummy";
43+
44+
var config = new Config
45+
{
46+
Increment = increment
47+
};
48+
ConfigurationProvider.ApplyDefaultsTo(config);
49+
50+
using (var fixture = new EmptyRepositoryFixture())
51+
{
52+
fixture.MakeACommit();
53+
fixture.BranchTo(dummyBranchName);
54+
fixture.MakeACommit();
55+
56+
var context = new GitVersionContext(fixture.Repository, fixture.Repository.Branches[dummyBranchName], config);
57+
context.Configuration.Increment.ShouldBe(alternateExpected ?? increment);
58+
}
59+
60+
}
61+
3462
[Test]
3563
public void UsesBranchSpecificConfigOverTopLevelDefaults()
3664
{

src/GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@
173173
<Compile Include="VersionCalculation\Strategies\ConfigNextVersionBaseVersionStrategyTests.cs" />
174174
<Compile Include="GitVersionContextBuilder.cs" />
175175
<Compile Include="VersionCalculation\Strategies\MergeMessageBaseVersionStrategyTests.cs" />
176-
<Compile Include="VersionCalculation\Strategies\VersionInBranchBaseVersionStrategyTests.cs" />
176+
<Compile Include="VersionCalculation\Strategies\VersionInBranchNameBaseVersionStrategyTests.cs" />
177177
<Compile Include="VersionCalculation\TestBaseVersionCalculator.cs" />
178178
<Compile Include="VersionCalculation\TestMetaDataCalculator.cs" />
179179
<Compile Include="VersionFilters\MinDateVersionFilterTests.cs" />

src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs

Lines changed: 235 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
using System.Collections.Generic;
12
using GitTools.Testing;
23
using GitVersion;
34
using GitVersionCore.Tests;
45
using LibGit2Sharp;
56
using NUnit.Framework;
6-
using System.Collections.Generic;
77

88
[TestFixture]
99
public class FeatureBranchScenarios
@@ -239,6 +239,240 @@ public void BranchCreatedAfterFinishReleaseShouldInheritAndIncrementFromLastMast
239239
}
240240
}
241241

242+
[Test]
243+
public void ShouldPickUpVersionFromDevelopAfterReleaseBranchCreated()
244+
{
245+
using (var fixture = new EmptyRepositoryFixture())
246+
{
247+
// Create develop and release branches
248+
fixture.MakeACommit();
249+
fixture.BranchTo("develop");
250+
fixture.MakeACommit();
251+
fixture.BranchTo("release/1.0");
252+
fixture.MakeACommit();
253+
fixture.Checkout("develop");
254+
fixture.MakeACommit();
255+
fixture.AssertFullSemver("1.1.0-alpha.1");
256+
257+
// create a feature branch from develop and verify the version
258+
fixture.BranchTo("feature/test");
259+
fixture.AssertFullSemver("1.1.0-test.1+1");
260+
}
261+
}
262+
263+
[Test]
264+
public void ShouldPickUpVersionFromDevelopAfterReleaseBranchMergedBack()
265+
{
266+
using (var fixture = new EmptyRepositoryFixture())
267+
{
268+
// Create develop and release branches
269+
fixture.MakeACommit();
270+
fixture.BranchTo("develop");
271+
fixture.MakeACommit();
272+
fixture.BranchTo("release/1.0");
273+
fixture.MakeACommit();
274+
275+
// merge release into develop
276+
fixture.Checkout("develop");
277+
fixture.MergeNoFF("release/1.0");
278+
fixture.AssertFullSemver("1.1.0-alpha.2");
279+
280+
// create a feature branch from develop and verify the version
281+
fixture.BranchTo("feature/test");
282+
fixture.AssertFullSemver("1.1.0-test.1+2");
283+
}
284+
}
285+
286+
public class WhenMasterMarkedAsIsDevelop
287+
{
288+
[Test]
289+
public void ShouldPickUpVersionFromMasterAfterReleaseBranchCreated()
290+
{
291+
var config = new Config
292+
{
293+
Branches = new Dictionary<string, BranchConfig>
294+
{
295+
{
296+
"master", new BranchConfig()
297+
{
298+
TracksReleaseBranches = true,
299+
Regex = "master"
300+
}
301+
}
302+
}
303+
};
304+
305+
using (var fixture = new EmptyRepositoryFixture())
306+
{
307+
// Create release branch
308+
fixture.MakeACommit();
309+
fixture.BranchTo("release/1.0");
310+
fixture.MakeACommit();
311+
fixture.Checkout("master");
312+
fixture.MakeACommit();
313+
fixture.AssertFullSemver(config, "1.0.1+1");
314+
315+
// create a feature branch from master and verify the version
316+
fixture.BranchTo("feature/test");
317+
fixture.AssertFullSemver(config, "1.0.1-test.1+1");
318+
}
319+
}
320+
321+
[Test]
322+
public void ShouldPickUpVersionFromMasterAfterReleaseBranchMergedBack()
323+
{
324+
var config = new Config
325+
{
326+
Branches = new Dictionary<string, BranchConfig>
327+
{
328+
{
329+
"master", new BranchConfig()
330+
{
331+
TracksReleaseBranches = true,
332+
Regex = "master"
333+
}
334+
}
335+
}
336+
};
337+
338+
using (var fixture = new EmptyRepositoryFixture())
339+
{
340+
// Create release branch
341+
fixture.MakeACommit();
342+
fixture.BranchTo("release/1.0");
343+
fixture.MakeACommit();
344+
345+
// merge release into master
346+
fixture.Checkout("master");
347+
fixture.MergeNoFF("release/1.0");
348+
fixture.AssertFullSemver(config, "1.0.1+2");
349+
350+
// create a feature branch from master and verify the version
351+
fixture.BranchTo("feature/test");
352+
fixture.AssertFullSemver(config, "1.0.1-test.1+2");
353+
}
354+
}
355+
}
356+
357+
public class WhenFeatureBranchHasNoConfig
358+
{
359+
[Test]
360+
public void ShouldPickUpVersionFromMasterAfterReleaseBranchCreated()
361+
{
362+
using (var fixture = new EmptyRepositoryFixture())
363+
{
364+
// Create develop and release branches
365+
fixture.MakeACommit();
366+
fixture.BranchTo("develop");
367+
fixture.MakeACommit();
368+
fixture.BranchTo("release/1.0");
369+
fixture.MakeACommit();
370+
fixture.Checkout("develop");
371+
fixture.MakeACommit();
372+
fixture.AssertFullSemver("1.1.0-alpha.1");
373+
374+
// create a misnamed feature branch (i.e. it uses the default config) from develop and verify the version
375+
fixture.BranchTo("misnamed");
376+
fixture.AssertFullSemver("1.1.0-misnamed.1+1");
377+
}
378+
}
379+
380+
[Test]
381+
public void ShouldPickUpVersionFromDevelopAfterReleaseBranchMergedBack()
382+
{
383+
using (var fixture = new EmptyRepositoryFixture())
384+
{
385+
// Create develop and release branches
386+
fixture.MakeACommit();
387+
fixture.BranchTo("develop");
388+
fixture.MakeACommit();
389+
fixture.BranchTo("release/1.0");
390+
fixture.MakeACommit();
391+
392+
// merge release into develop
393+
fixture.Checkout("develop");
394+
fixture.MergeNoFF("release/1.0");
395+
fixture.AssertFullSemver("1.1.0-alpha.2");
396+
397+
// create a misnamed feature branch (i.e. it uses the default config) from develop and verify the version
398+
fixture.BranchTo("misnamed");
399+
fixture.AssertFullSemver("1.1.0-misnamed.1+2");
400+
}
401+
}
402+
403+
// ReSharper disable once MemberHidesStaticFromOuterClass
404+
public class WhenMasterMarkedAsIsDevelop
405+
{
406+
[Test]
407+
public void ShouldPickUpVersionFromMasterAfterReleaseBranchCreated()
408+
{
409+
var config = new Config
410+
{
411+
Branches = new Dictionary<string, BranchConfig>
412+
{
413+
{
414+
"master", new BranchConfig()
415+
{
416+
TracksReleaseBranches = true,
417+
Regex = "master"
418+
}
419+
}
420+
}
421+
};
422+
423+
using (var fixture = new EmptyRepositoryFixture())
424+
{
425+
// Create release branch
426+
fixture.MakeACommit();
427+
fixture.BranchTo("release/1.0");
428+
fixture.MakeACommit();
429+
fixture.Checkout("master");
430+
fixture.MakeACommit();
431+
fixture.AssertFullSemver(config, "1.0.1+1");
432+
433+
// create a misnamed feature branch (i.e. it uses the default config) from master and verify the version
434+
fixture.BranchTo("misnamed");
435+
fixture.AssertFullSemver(config, "1.0.1-misnamed.1+1");
436+
}
437+
}
438+
439+
[Test]
440+
public void ShouldPickUpVersionFromMasterAfterReleaseBranchMergedBack()
441+
{
442+
var config = new Config
443+
{
444+
Branches = new Dictionary<string, BranchConfig>
445+
{
446+
{
447+
"master", new BranchConfig()
448+
{
449+
TracksReleaseBranches = true,
450+
Regex = "master"
451+
}
452+
}
453+
}
454+
};
455+
456+
using (var fixture = new EmptyRepositoryFixture())
457+
{
458+
// Create release branch
459+
fixture.MakeACommit();
460+
fixture.BranchTo("release/1.0");
461+
fixture.MakeACommit();
462+
463+
// merge release into master
464+
fixture.Checkout("master");
465+
fixture.MergeNoFF("release/1.0");
466+
fixture.AssertFullSemver(config, "1.0.1+2");
467+
468+
// create a misnamed feature branch (i.e. it uses the default config) from master and verify the version
469+
fixture.BranchTo("misnamed");
470+
fixture.AssertFullSemver(config, "1.0.1-misnamed.1+2");
471+
}
472+
}
473+
}
474+
}
475+
242476
[Test]
243477
public void PickUpVersionFromMasterMarkedWithIsTracksReleaseBranches()
244478
{

0 commit comments

Comments
 (0)