Skip to content

Use the Inherit strategy by default #1085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ next-version: 1.0
assembly-versioning-scheme: MajorMinorPatch
assembly-informational-format: '{InformationalVersion}'
mode: ContinuousDelivery
increment: Inherit
continuous-delivery-fallback-tag: ci
tag-prefix: '[vV]'
major-version-bump-message: '\+semver:\s?(breaking|major)'
Expand Down Expand Up @@ -70,6 +71,11 @@ value of the `AssemblyInformationalVersion` attribute. Default set to
Sets the `mode` of how GitVersion should create a new version. Read more at
[versioning mode](/reference/versioning-mode.md).

### increment
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`.

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).

### continuous-delivery-fallback-tag
When using `mode: ContinuousDeployment`, the value specified in
`continuous-delivery-fallback-tag` will be used as the pre-release tag for
Expand Down Expand Up @@ -246,8 +252,7 @@ of `alpha.foo` with the value of `alpha.{BranchName}`.
**Note:** To clear a default use an empty string: `tag: ''`

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

### prevent-increment-of-merged-branch-version
When `release-2.0.0` is merged into master, we want master to build `2.0.0`. If
Expand Down
28 changes: 20 additions & 8 deletions docs/more-info/version-sources.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Version Sources
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.
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.

The logic of GitVersion is something like this:

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

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

Will increment: true

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

Will increment: false

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

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

### GitVersion.yml
If the `next-version` property is specified in the config file, it will be used as a version source.
Returns the value of the `next-version` property in the config file.

Will increment: false

### Develop branch
For the develop branch, i.e. marked with `is-develop: true`
- Returns the version number extracted from any child release-branches, i.e. those marked with `is-release-branch: true`
- Returns the version number of any tags on the master branch

Will increment: true

### Fallback
Returns the version number `0.1.0`.

Will increment: false

Expand Down
28 changes: 28 additions & 0 deletions src/GitVersionCore.Tests/GitVersionContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,34 @@ public void CanInheritVersioningMode(VersioningMode mode)
context.Configuration.VersioningMode.ShouldBe(mode);
}

[TestCase(IncrementStrategy.Inherit, IncrementStrategy.Patch)] // Since it inherits, the increment strategy of master is used => Patch
[TestCase(IncrementStrategy.Patch, null)]
[TestCase(IncrementStrategy.Major, null)]
[TestCase(IncrementStrategy.Minor, null)]
[TestCase(IncrementStrategy.None, null)]
public void CanInheritIncrement(IncrementStrategy increment, IncrementStrategy? alternateExpected)
{
// Dummy branch name to make sure that no default config exists.
const string dummyBranchName = "dummy";

var config = new Config
{
Increment = increment
};
ConfigurationProvider.ApplyDefaultsTo(config);

using (var fixture = new EmptyRepositoryFixture())
{
fixture.MakeACommit();
fixture.BranchTo(dummyBranchName);
fixture.MakeACommit();

var context = new GitVersionContext(fixture.Repository, fixture.Repository.Branches[dummyBranchName], config);
context.Configuration.Increment.ShouldBe(alternateExpected ?? increment);
}

}

[Test]
public void UsesBranchSpecificConfigOverTopLevelDefaults()
{
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersionCore.Tests/GitVersionCore.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
<Compile Include="VersionCalculation\Strategies\ConfigNextVersionBaseVersionStrategyTests.cs" />
<Compile Include="GitVersionContextBuilder.cs" />
<Compile Include="VersionCalculation\Strategies\MergeMessageBaseVersionStrategyTests.cs" />
<Compile Include="VersionCalculation\Strategies\VersionInBranchBaseVersionStrategyTests.cs" />
<Compile Include="VersionCalculation\Strategies\VersionInBranchNameBaseVersionStrategyTests.cs" />
<Compile Include="VersionCalculation\TestBaseVersionCalculator.cs" />
<Compile Include="VersionCalculation\TestMetaDataCalculator.cs" />
<Compile Include="VersionFilters\MinDateVersionFilterTests.cs" />
Expand Down
237 changes: 236 additions & 1 deletion src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using GitTools.Testing;
using GitVersion;
using GitVersionCore.Tests;
Expand Down Expand Up @@ -223,7 +224,7 @@ public void BranchCreatedAfterFinishReleaseShouldInheritAndIncrementFromLastMast
fixture.Checkout("develop");
fixture.Repository.MergeNoFF("release/0.2.0");
fixture.Repository.Branches.Remove("release/2.0.0");

fixture.Repository.MakeACommit();

//validate develop branch version after merging release 0.2.0 to master and develop (finish release)
Expand All @@ -237,4 +238,238 @@ public void BranchCreatedAfterFinishReleaseShouldInheritAndIncrementFromLastMast
fixture.AssertFullSemver("0.3.0-TEST-1.1+2");
}
}

[Test]
public void ShouldPickUpVersionFromDevelopAfterReleaseBranchCreated()
{
using (var fixture = new EmptyRepositoryFixture())
{
// Create develop and release branches
fixture.MakeACommit();
fixture.BranchTo("develop");
fixture.MakeACommit();
fixture.BranchTo("release/1.0");
fixture.MakeACommit();
fixture.Checkout("develop");
fixture.MakeACommit();
fixture.AssertFullSemver("1.1.0-alpha.1");

// create a feature branch from develop and verify the version
fixture.BranchTo("feature/test");
fixture.AssertFullSemver("1.1.0-test.1+1");
}
}

[Test]
public void ShouldPickUpVersionFromDevelopAfterReleaseBranchMergedBack()
{
using (var fixture = new EmptyRepositoryFixture())
{
// Create develop and release branches
fixture.MakeACommit();
fixture.BranchTo("develop");
fixture.MakeACommit();
fixture.BranchTo("release/1.0");
fixture.MakeACommit();

// merge release into develop
fixture.Checkout("develop");
fixture.MergeNoFF("release/1.0");
fixture.AssertFullSemver("1.1.0-alpha.2");

// create a feature branch from develop and verify the version
fixture.BranchTo("feature/test");
fixture.AssertFullSemver("1.1.0-test.1+2");
}
}

public class WhenMasterMarkedAsIsDevelop
{
[Test]
public void ShouldPickUpVersionFromMasterAfterReleaseBranchCreated()
{
var config = new Config
{
Branches = new Dictionary<string, BranchConfig>
{
{
"master", new BranchConfig()
{
IsDevelop = true,
Regex = "master"
}
}
}
};

using (var fixture = new EmptyRepositoryFixture())
{
// Create release branch
fixture.MakeACommit();
fixture.BranchTo("release/1.0");
fixture.MakeACommit();
fixture.Checkout("master");
fixture.MakeACommit();
fixture.AssertFullSemver(config, "1.0.1+1");

// create a feature branch from master and verify the version
fixture.BranchTo("feature/test");
fixture.AssertFullSemver(config, "1.0.1-test.1+1");
}
}

[Test]
public void ShouldPickUpVersionFromMasterAfterReleaseBranchMergedBack()
{
var config = new Config
{
Branches = new Dictionary<string, BranchConfig>
{
{
"master", new BranchConfig()
{
IsDevelop = true,
Regex = "master"
}
}
}
};

using (var fixture = new EmptyRepositoryFixture())
{
// Create release branch
fixture.MakeACommit();
fixture.BranchTo("release/1.0");
fixture.MakeACommit();

// merge release into master
fixture.Checkout("master");
fixture.MergeNoFF("release/1.0");
fixture.AssertFullSemver(config, "1.0.1+2");

// create a feature branch from master and verify the version
fixture.BranchTo("feature/test");
fixture.AssertFullSemver(config, "1.0.1-test.1+2");
}
}
}

public class WhenFeatureBranchHasNoConfig
{
[Test]
public void ShouldPickUpVersionFromMasterAfterReleaseBranchCreated()
{
using (var fixture = new EmptyRepositoryFixture())
{
// Create develop and release branches
fixture.MakeACommit();
fixture.BranchTo("develop");
fixture.MakeACommit();
fixture.BranchTo("release/1.0");
fixture.MakeACommit();
fixture.Checkout("develop");
fixture.MakeACommit();
fixture.AssertFullSemver("1.1.0-alpha.1");

// create a misnamed feature branch (i.e. it uses the default config) from develop and verify the version
fixture.BranchTo("misnamed");
fixture.AssertFullSemver("1.1.0-misnamed.1+1");
}
}

[Test]
public void ShouldPickUpVersionFromDevelopAfterReleaseBranchMergedBack()
{
using (var fixture = new EmptyRepositoryFixture())
{
// Create develop and release branches
fixture.MakeACommit();
fixture.BranchTo("develop");
fixture.MakeACommit();
fixture.BranchTo("release/1.0");
fixture.MakeACommit();

// merge release into develop
fixture.Checkout("develop");
fixture.MergeNoFF("release/1.0");
fixture.AssertFullSemver("1.1.0-alpha.2");

// create a misnamed feature branch (i.e. it uses the default config) from develop and verify the version
fixture.BranchTo("misnamed");
fixture.AssertFullSemver("1.1.0-misnamed.1+2");
}
}

// ReSharper disable once MemberHidesStaticFromOuterClass
public class WhenMasterMarkedAsIsDevelop
{
[Test]
public void ShouldPickUpVersionFromMasterAfterReleaseBranchCreated()
{
var config = new Config
{
Branches = new Dictionary<string, BranchConfig>
{
{
"master", new BranchConfig()
{
IsDevelop = true,
Regex = "master"
}
}
}
};

using (var fixture = new EmptyRepositoryFixture())
{
// Create release branch
fixture.MakeACommit();
fixture.BranchTo("release/1.0");
fixture.MakeACommit();
fixture.Checkout("master");
fixture.MakeACommit();
fixture.AssertFullSemver(config, "1.0.1+1");

// create a misnamed feature branch (i.e. it uses the default config) from master and verify the version
fixture.BranchTo("misnamed");
fixture.AssertFullSemver(config, "1.0.1-misnamed.1+1");
}
}

[Test]
public void ShouldPickUpVersionFromMasterAfterReleaseBranchMergedBack()
{
var config = new Config
{
Branches = new Dictionary<string, BranchConfig>
{
{
"master", new BranchConfig()
{
IsDevelop = true,
Regex = "master"
}
}
}
};

using (var fixture = new EmptyRepositoryFixture())
{
// Create release branch
fixture.MakeACommit();
fixture.BranchTo("release/1.0");
fixture.MakeACommit();

// merge release into master
fixture.Checkout("master");
fixture.MergeNoFF("release/1.0");
fixture.AssertFullSemver(config, "1.0.1+2");

// create a misnamed feature branch (i.e. it uses the default config) from master and verify the version
fixture.BranchTo("misnamed");
fixture.AssertFullSemver(config, "1.0.1-misnamed.1+2");
}
}
}
}
}
Loading