diff --git a/docs/configuration.md b/docs/configuration.md
index e841f5a5a9..ed0ee07702 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -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)'
@@ -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
@@ -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
diff --git a/docs/more-info/version-sources.md b/docs/more-info/version-sources.md
index 06e243223f..d402303944 100644
--- a/docs/more-info/version-sources.md
+++ b/docs/more-info/version-sources.md
@@ -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:
@@ -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
diff --git a/src/GitVersionCore.Tests/GitVersionContextTests.cs b/src/GitVersionCore.Tests/GitVersionContextTests.cs
index 396a7ea95a..d91910af75 100644
--- a/src/GitVersionCore.Tests/GitVersionContextTests.cs
+++ b/src/GitVersionCore.Tests/GitVersionContextTests.cs
@@ -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()
{
diff --git a/src/GitVersionCore.Tests/GitVersionCore.Tests.csproj b/src/GitVersionCore.Tests/GitVersionCore.Tests.csproj
index 01852f82fa..df63914c1d 100644
--- a/src/GitVersionCore.Tests/GitVersionCore.Tests.csproj
+++ b/src/GitVersionCore.Tests/GitVersionCore.Tests.csproj
@@ -173,7 +173,7 @@
-
+
diff --git a/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs
index fc7fd16861..554caccca5 100644
--- a/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs
+++ b/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs
@@ -1,3 +1,4 @@
+using System.Collections.Generic;
using GitTools.Testing;
using GitVersion;
using GitVersionCore.Tests;
@@ -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)
@@ -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
+ {
+ {
+ "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
+ {
+ {
+ "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
+ {
+ {
+ "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
+ {
+ {
+ "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");
+ }
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/GitVersionCore.Tests/VersionCalculation/NextVersionCalculatorTests.cs b/src/GitVersionCore.Tests/VersionCalculation/NextVersionCalculatorTests.cs
index ba8f0b2feb..6bb4a5553d 100644
--- a/src/GitVersionCore.Tests/VersionCalculation/NextVersionCalculatorTests.cs
+++ b/src/GitVersionCore.Tests/VersionCalculation/NextVersionCalculatorTests.cs
@@ -58,47 +58,61 @@ public void AppliesBranchPreReleaseTag()
[Test]
public void PreReleaseTagCanUseBranchName()
{
- var baseCalculator = new TestBaseVersionCalculator(false, new SemanticVersion(1), new MockCommit());
- var semanticVersionBuildMetaData = new SemanticVersionBuildMetaData(2, "develop", "b1a34e", DateTimeOffset.Now);
- var sut = new NextVersionCalculator(baseCalculator, new TestMetaDataCalculator(semanticVersionBuildMetaData));
- var config = new Config();
- config.Branches.Add("custom", new BranchConfig
+ var config = new Config
{
- Regex = "custom/",
- Tag = "useBranchName"
- });
- var context = new GitVersionContextBuilder()
- .WithConfig(config)
- .WithDevelopBranch()
- .AddBranch("custom/foo")
- .Build();
+ NextVersion = "1.0.0",
+ Branches = new Dictionary
+ {
+ {
+ "custom", new BranchConfig
+ {
+ Regex = "custom/",
+ Tag = "useBranchName"
+ }
+ }
+ }
+ };
- var version = sut.FindVersion(context);
+ using (var fixture = new EmptyRepositoryFixture())
+ {
+ fixture.MakeACommit();
+ fixture.BranchTo("develop");
+ fixture.MakeACommit();
+ fixture.BranchTo("custom/foo");
+ fixture.MakeACommit();
- version.ToString("f").ShouldBe("1.0.0-foo.1+2");
+ fixture.AssertFullSemver(config, "1.0.0-foo.1+2");
+ }
}
[Test]
public void PreReleaseTagCanUseBranchNameVariable()
{
- var baseCalculator = new TestBaseVersionCalculator(false, new SemanticVersion(1), new MockCommit());
- var semanticVersionBuildMetaData = new SemanticVersionBuildMetaData(2, "develop", "b1a34e", DateTimeOffset.Now);
- var sut = new NextVersionCalculator(baseCalculator, new TestMetaDataCalculator(semanticVersionBuildMetaData));
- var config = new Config();
- config.Branches.Add("custom", new BranchConfig
+ var config = new Config
{
- Regex = "custom/",
- Tag = "alpha.{BranchName}"
- });
- var context = new GitVersionContextBuilder()
- .WithConfig(config)
- .WithDevelopBranch()
- .AddBranch("custom/foo")
- .Build();
+ NextVersion = "1.0.0",
+ Branches = new Dictionary
+ {
+ {
+ "custom", new BranchConfig
+ {
+ Regex = "custom/",
+ Tag = "alpha.{BranchName}"
+ }
+ }
+ }
+ };
- var version = sut.FindVersion(context);
+ using (var fixture = new EmptyRepositoryFixture())
+ {
+ fixture.MakeACommit();
+ fixture.BranchTo("develop");
+ fixture.MakeACommit();
+ fixture.BranchTo("custom/foo");
+ fixture.MakeACommit();
- version.ToString("f").ShouldBe("1.0.0-alpha.foo.1+2");
+ fixture.AssertFullSemver(config, "1.0.0-alpha.foo.1+2");
+ }
}
[Test]
diff --git a/src/GitVersionCore.Tests/VersionCalculation/Strategies/VersionInBranchBaseVersionStrategyTests.cs b/src/GitVersionCore.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs
similarity index 90%
rename from src/GitVersionCore.Tests/VersionCalculation/Strategies/VersionInBranchBaseVersionStrategyTests.cs
rename to src/GitVersionCore.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs
index 55530b8894..01afaa0ea8 100644
--- a/src/GitVersionCore.Tests/VersionCalculation/Strategies/VersionInBranchBaseVersionStrategyTests.cs
+++ b/src/GitVersionCore.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs
@@ -9,7 +9,7 @@
using Shouldly;
[TestFixture]
- public class VersionInBranchBaseVersionStrategyTests
+ public class VersionInBranchNameBaseVersionStrategyTests
{
[Test]
[TestCase("release-2.0.0", "2.0.0")]
@@ -23,7 +23,7 @@ public void CanTakeVersionFromBranchName(string branchName, string expectedBaseV
{
fixture.Repository.MakeACommit();
var branch = fixture.Repository.CreateBranch(branchName);
- var sut = new VersionInBranchBaseVersionStrategy();
+ var sut = new VersionInBranchNameBaseVersionStrategy();
var gitVersionContext = new GitVersionContext(fixture.Repository, branch, new Config().ApplyDefaults());
var baseVersion = sut.GetVersions(gitVersionContext).SingleOrDefault();
diff --git a/src/GitVersionCore/BranchCommit.cs b/src/GitVersionCore/BranchCommit.cs
new file mode 100644
index 0000000000..1a2eb652a5
--- /dev/null
+++ b/src/GitVersionCore/BranchCommit.cs
@@ -0,0 +1,51 @@
+namespace GitVersion
+{
+ using LibGit2Sharp;
+
+ ///
+ /// A commit, together with the branch to which the commit belongs.
+ ///
+ public struct BranchCommit
+ {
+ public static readonly BranchCommit Empty = new BranchCommit();
+
+ public BranchCommit(Commit commit, Branch branch) : this()
+ {
+ Branch = branch;
+ Commit = commit;
+ }
+
+ public Branch Branch { get; private set; }
+ public Commit Commit { get; private set; }
+
+ public bool Equals(BranchCommit other)
+ {
+ return Equals(Branch, other.Branch) && Equals(Commit, other.Commit);
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj))
+ return false;
+ return obj is BranchCommit && Equals((BranchCommit)obj);
+ }
+
+ public override int GetHashCode()
+ {
+ unchecked
+ {
+ return ((Branch != null ? Branch.GetHashCode() : 0) * 397) ^ (Commit != null ? Commit.GetHashCode() : 0);
+ }
+ }
+
+ public static bool operator ==(BranchCommit left, BranchCommit right)
+ {
+ return left.Equals(right);
+ }
+
+ public static bool operator !=(BranchCommit left, BranchCommit right)
+ {
+ return !left.Equals(right);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/GitVersionCore/BranchConfigurationCalculator.cs b/src/GitVersionCore/BranchConfigurationCalculator.cs
index f8a10ba196..e46823d798 100644
--- a/src/GitVersionCore/BranchConfigurationCalculator.cs
+++ b/src/GitVersionCore/BranchConfigurationCalculator.cs
@@ -11,54 +11,55 @@ namespace GitVersion
public class BranchConfigurationCalculator
{
- public static KeyValuePair GetBranchConfiguration(Commit currentCommit, IRepository repository, bool onlyEvaluateTrackedBranches, Config config, Branch currentBranch, IList excludedInheritBranches = null)
+ ///
+ /// Gets the for the current commit.
+ ///
+ public static BranchConfig GetBranchConfiguration(Commit currentCommit, IRepository repository, bool onlyEvaluateTrackedBranches, Config config, Branch currentBranch, IList excludedInheritBranches = null)
{
- var matchingBranches = LookupBranchConfiguration(config, currentBranch);
+ var matchingBranches = LookupBranchConfiguration(config, currentBranch).ToArray();
- if (matchingBranches.Length == 0)
+ if (matchingBranches.Length > 1)
{
- Logger.WriteInfo(string.Format(
- "No branch configuration found for branch {0}, falling back to default configuration",
- currentBranch.FriendlyName));
-
- var branchConfig = new BranchConfig();
- ConfigurationProvider.ApplyBranchDefaults(config, branchConfig, "");
- return new KeyValuePair(string.Empty, branchConfig);
+ const string format = "Multiple branch configurations match the current branch branchName of '{0}'. Matching configurations: '{1}'";
+ throw new Exception(string.Format(format, currentBranch.FriendlyName, string.Join(", ", matchingBranches.Select(b => b.Name))));
}
+
+ BranchConfig branchConfiguration;
if (matchingBranches.Length == 1)
{
- var keyValuePair = matchingBranches[0];
- var branchConfiguration = keyValuePair.Value;
-
- if (branchConfiguration.Increment == IncrementStrategy.Inherit)
- {
- return InheritBranchConfiguration(onlyEvaluateTrackedBranches, repository, currentCommit, currentBranch, keyValuePair, branchConfiguration, config, excludedInheritBranches);
- }
+ branchConfiguration = matchingBranches[0];
+ }
+ else
+ {
+ Logger.WriteInfo(string.Format(
+ "No branch configuration found for branch {0}, falling back to default configuration",
+ currentBranch.FriendlyName));
- return keyValuePair;
+ branchConfiguration = new BranchConfig { Name = string.Empty };
+ ConfigurationProvider.ApplyBranchDefaults(config, branchConfiguration, "");
}
- const string format = "Multiple branch configurations match the current branch branchName of '{0}'. Matching configurations: '{1}'";
- throw new Exception(string.Format(format, currentBranch.FriendlyName, string.Join(", ", matchingBranches.Select(b => b.Key))));
+ return branchConfiguration.Increment == IncrementStrategy.Inherit ?
+ InheritBranchConfiguration(onlyEvaluateTrackedBranches, repository, currentCommit, currentBranch, branchConfiguration, config, excludedInheritBranches) :
+ branchConfiguration;
}
- static KeyValuePair[] LookupBranchConfiguration([NotNull] Config config, [NotNull] Branch currentBranch)
+ static IEnumerable LookupBranchConfiguration([NotNull] Config config, [NotNull] Branch currentBranch)
{
if (config == null)
{
throw new ArgumentNullException("config");
}
-
+
if (currentBranch == null)
{
throw new ArgumentNullException("currentBranch");
}
- return config.Branches.Where(b => Regex.IsMatch(currentBranch.FriendlyName, "^" + b.Value.Regex, RegexOptions.IgnoreCase)).ToArray();
+ return config.Branches.Where(b => Regex.IsMatch(currentBranch.FriendlyName, "^" + b.Value.Regex, RegexOptions.IgnoreCase)).Select(kvp => kvp.Value);
}
-
- static KeyValuePair InheritBranchConfiguration(bool onlyEvaluateTrackedBranches, IRepository repository, Commit currentCommit, Branch currentBranch, KeyValuePair keyValuePair, BranchConfig branchConfiguration, Config config, IList excludedInheritBranches)
+ static BranchConfig InheritBranchConfiguration(bool onlyEvaluateTrackedBranches, IRepository repository, Commit currentCommit, Branch currentBranch, BranchConfig branchConfiguration, Config config, IList excludedInheritBranches)
{
using (Logger.IndentLog("Attempting to inherit branch configuration from parent branch"))
{
@@ -74,11 +75,11 @@ static KeyValuePair InheritBranchConfiguration(bool onlyEv
{
excludedInheritBranches = repository.Branches.Where(b =>
{
- var branchConfig = LookupBranchConfiguration(config, b);
+ var branchConfig = LookupBranchConfiguration(config, b).ToArray();
// NOTE: if length is 0 we couldn't find the configuration for the branch e.g. "origin/master"
// NOTE: if the length is greater than 1 we cannot decide which merge strategy to pick
- return (branchConfig.Length != 1) || (branchConfig.Length == 1 && branchConfig[0].Value.Increment == IncrementStrategy.Inherit);
+ return (branchConfig.Length != 1) || (branchConfig.Length == 1 && branchConfig[0].Increment == IncrementStrategy.Inherit);
}).ToList();
}
excludedBranches.ToList().ForEach(excludedInheritBranches.Add);
@@ -86,7 +87,7 @@ static KeyValuePair InheritBranchConfiguration(bool onlyEv
var branchPoint = currentBranch.FindCommitBranchWasBranchedFrom(repository, excludedInheritBranches.ToArray());
List possibleParents;
- if (branchPoint == null)
+ if (branchPoint == BranchCommit.Empty)
{
possibleParents = currentCommit.GetBranchesContainingCommit(repository, branchesToEvaluate, true)
// It fails to inherit Increment branch configuration if more than 1 parent;
@@ -96,7 +97,7 @@ static KeyValuePair InheritBranchConfiguration(bool onlyEv
}
else
{
- var branches = branchPoint.GetBranchesContainingCommit(repository, branchesToEvaluate, true).ToList();
+ var branches = branchPoint.Commit.GetBranchesContainingCommit(repository, branchesToEvaluate, true).ToList();
if (branches.Count > 1)
{
var currentTipBranches = currentCommit.GetBranchesContainingCommit(repository, branchesToEvaluate, true).ToList();
@@ -112,16 +113,14 @@ static KeyValuePair InheritBranchConfiguration(bool onlyEv
if (possibleParents.Count == 1)
{
- var branchConfig = GetBranchConfiguration(currentCommit, repository, onlyEvaluateTrackedBranches, config, possibleParents[0], excludedInheritBranches).Value;
- return new KeyValuePair(
- keyValuePair.Key,
- new BranchConfig(branchConfiguration)
- {
- Increment = branchConfig.Increment,
- PreventIncrementOfMergedBranchVersion = branchConfig.PreventIncrementOfMergedBranchVersion,
- // If we are inheriting from develop then we should behave like develop
- IsDevelop = branchConfig.IsDevelop
- });
+ var branchConfig = GetBranchConfiguration(currentCommit, repository, onlyEvaluateTrackedBranches, config, possibleParents[0], excludedInheritBranches);
+ return new BranchConfig(branchConfiguration)
+ {
+ Increment = branchConfig.Increment,
+ PreventIncrementOfMergedBranchVersion = branchConfig.PreventIncrementOfMergedBranchVersion,
+ // If we are inheriting from develop then we should behave like develop
+ IsDevelop = branchConfig.IsDevelop
+ };
}
// If we fail to inherit it is probably because the branch has been merged and we can't do much. So we will fall back to develop's config
@@ -144,16 +143,14 @@ static KeyValuePair InheritBranchConfiguration(bool onlyEv
var branchName = chosenBranch.FriendlyName;
Logger.WriteWarning(errorMessage + Environment.NewLine + Environment.NewLine + "Falling back to " + branchName + " branch config");
- var inheritingBranchConfig = GetBranchConfiguration(currentCommit, repository, onlyEvaluateTrackedBranches, config, chosenBranch).Value;
- return new KeyValuePair(
- keyValuePair.Key,
- new BranchConfig(branchConfiguration)
- {
- Increment = inheritingBranchConfig.Increment,
- PreventIncrementOfMergedBranchVersion = inheritingBranchConfig.PreventIncrementOfMergedBranchVersion,
- // If we are inheriting from develop then we should behave like develop
- IsDevelop = inheritingBranchConfig.IsDevelop
- });
+ var inheritingBranchConfig = GetBranchConfiguration(currentCommit, repository, onlyEvaluateTrackedBranches, config, chosenBranch);
+ return new BranchConfig(branchConfiguration)
+ {
+ Increment = inheritingBranchConfig.Increment,
+ PreventIncrementOfMergedBranchVersion = inheritingBranchConfig.PreventIncrementOfMergedBranchVersion,
+ // If we are inheriting from develop then we should behave like develop
+ IsDevelop = inheritingBranchConfig.IsDevelop
+ };
}
}
diff --git a/src/GitVersionCore/Configuration/BranchConfig.cs b/src/GitVersionCore/Configuration/BranchConfig.cs
index b3abee74df..f6916eef9e 100644
--- a/src/GitVersionCore/Configuration/BranchConfig.cs
+++ b/src/GitVersionCore/Configuration/BranchConfig.cs
@@ -8,9 +8,11 @@ public BranchConfig()
{
}
+ ///
+ /// Creates a clone of the given .
+ ///
public BranchConfig(BranchConfig branchConfiguration)
{
- Regex = branchConfiguration.Regex;
VersioningMode = branchConfiguration.VersioningMode;
Tag = branchConfiguration.Tag;
Increment = branchConfiguration.Increment;
@@ -18,9 +20,11 @@ public BranchConfig(BranchConfig branchConfiguration)
TagNumberPattern = branchConfiguration.TagNumberPattern;
TrackMergeTarget = branchConfiguration.TrackMergeTarget;
CommitMessageIncrementing = branchConfiguration.CommitMessageIncrementing;
+ Regex = branchConfiguration.Regex;
IsDevelop = branchConfiguration.IsDevelop;
IsReleaseBranch = branchConfiguration.IsReleaseBranch;
IsMainline = branchConfiguration.IsMainline;
+ Name = branchConfiguration.Name;
}
[YamlMember(Alias = "mode")]
@@ -43,7 +47,7 @@ public BranchConfig(BranchConfig branchConfiguration)
[YamlMember(Alias = "track-merge-target")]
public bool? TrackMergeTarget { get; set; }
-
+
[YamlMember(Alias = "commit-message-incrementing")]
public CommitMessageIncrementMode? CommitMessageIncrementing { get; set; }
@@ -58,5 +62,11 @@ public BranchConfig(BranchConfig branchConfiguration)
[YamlMember(Alias = "is-mainline")]
public bool? IsMainline { get; set; }
+
+ ///
+ /// The name given to this configuration in the config file.
+ ///
+ [YamlIgnore]
+ public string Name { get; set; }
}
}
diff --git a/src/GitVersionCore/Configuration/Config.cs b/src/GitVersionCore/Configuration/Config.cs
index f6e04af6e4..b0ec9b9612 100644
--- a/src/GitVersionCore/Configuration/Config.cs
+++ b/src/GitVersionCore/Configuration/Config.cs
@@ -79,7 +79,7 @@ public Dictionary Branches
value.ToList().ForEach(_ =>
{
if (!branches.ContainsKey(_.Key))
- branches.Add(_.Key, new BranchConfig());
+ branches.Add(_.Key, new BranchConfig {Name = _.Key});
branches[_.Key] = MergeObjects(branches[_.Key], _.Value);
});
@@ -99,5 +99,8 @@ T MergeObjects(T target, T source)
[YamlMember(Alias = "ignore")]
public IgnoreConfig Ignore { get; set; }
+
+ [YamlMember(Alias = "increment")]
+ public IncrementStrategy? Increment { get; set; }
}
}
\ No newline at end of file
diff --git a/src/GitVersionCore/Configuration/ConfigurationProvider.cs b/src/GitVersionCore/Configuration/ConfigurationProvider.cs
index 59b9969419..e297ccd925 100644
--- a/src/GitVersionCore/Configuration/ConfigurationProvider.cs
+++ b/src/GitVersionCore/Configuration/ConfigurationProvider.cs
@@ -29,6 +29,8 @@ public class ConfigurationProvider
public const string SupportBranchKey = "support";
public const string DevelopBranchKey = "develop";
+ private const IncrementStrategy DefaultIncrementStrategy = IncrementStrategy.Inherit;
+
public static Config Provide(GitPreparer gitPreparer, IFileSystem fileSystem, bool applyDefaults = true, Config overrideConfig = null)
{
var workingDirectory = gitPreparer.WorkingDirectory;
@@ -98,24 +100,44 @@ public static void ApplyDefaultsTo(Config config)
var configBranches = config.Branches.ToList();
- ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, MasterBranchKey),
+ ApplyBranchDefaults(config,
+ GetOrCreateBranchDefaults(config, MasterBranchKey),
MasterBranchRegex,
defaultTag: string.Empty,
defaultPreventIncrement: true,
+ defaultIncrementStrategy: IncrementStrategy.Patch,
isMainline: true);
- ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, ReleaseBranchKey), ReleaseBranchRegex, defaultTag: "beta", defaultPreventIncrement: true, isReleaseBranch: true);
- ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, FeatureBranchKey), FeatureBranchRegex, defaultIncrementStrategy: IncrementStrategy.Inherit);
- ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, PullRequestBranchKey), PullRequestRegex,
+ ApplyBranchDefaults(config,
+ GetOrCreateBranchDefaults(config, ReleaseBranchKey),
+ ReleaseBranchRegex,
+ defaultTag: "beta",
+ defaultPreventIncrement: true,
+ defaultIncrementStrategy: IncrementStrategy.Patch,
+ isReleaseBranch: true);
+ ApplyBranchDefaults(config,
+ GetOrCreateBranchDefaults(config, FeatureBranchKey),
+ FeatureBranchRegex,
+ defaultIncrementStrategy: IncrementStrategy.Inherit);
+ ApplyBranchDefaults(config,
+ GetOrCreateBranchDefaults(config, PullRequestBranchKey),
+ PullRequestRegex,
defaultTag: "PullRequest",
defaultTagNumberPattern: @"[/-](?\d+)[-/]",
defaultIncrementStrategy: IncrementStrategy.Inherit);
- ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, HotfixBranchKey), HotfixBranchRegex, defaultTag: "beta");
- ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, SupportBranchKey),
+ ApplyBranchDefaults(config,
+ GetOrCreateBranchDefaults(config, HotfixBranchKey),
+ HotfixBranchRegex,
+ defaultTag: "beta",
+ defaultIncrementStrategy: IncrementStrategy.Patch);
+ ApplyBranchDefaults(config,
+ GetOrCreateBranchDefaults(config, SupportBranchKey),
SupportBranchRegex,
defaultTag: string.Empty,
defaultPreventIncrement: true,
+ defaultIncrementStrategy: IncrementStrategy.Patch,
isMainline: true);
- ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, DevelopBranchKey),
+ ApplyBranchDefaults(config,
+ GetOrCreateBranchDefaults(config, DevelopBranchKey),
DevelopBranchRegex,
defaultTag: "alpha",
defaultIncrementStrategy: IncrementStrategy.Minor,
@@ -123,8 +145,8 @@ public static void ApplyDefaultsTo(Config config)
defaultTrackMergeTarget: true,
isDevelop: true);
- // Any user defined branches should have other values defaulted after known branches filled in
- // This allows users to override one value of
+ // Any user defined branches should have other values defaulted after known branches filled in.
+ // This allows users to override any of the value.
foreach (var branchConfig in configBranches)
{
var regex = branchConfig.Value.Regex;
@@ -146,7 +168,7 @@ static BranchConfig GetOrCreateBranchDefaults(Config config, string branchKey)
{
if (!config.Branches.ContainsKey(branchKey))
{
- var branchConfig = new BranchConfig();
+ var branchConfig = new BranchConfig {Name = branchKey};
config.Branches.Add(branchKey, branchConfig);
return branchConfig;
}
@@ -158,7 +180,7 @@ public static void ApplyBranchDefaults(Config config,
BranchConfig branchConfig,
string branchRegex,
string defaultTag = "useBranchName",
- IncrementStrategy defaultIncrementStrategy = IncrementStrategy.Patch,
+ IncrementStrategy? defaultIncrementStrategy = null, // Looked up from main config
bool defaultPreventIncrement = false,
VersioningMode? defaultVersioningMode = null, // Looked up from main config
bool defaultTrackMergeTarget = false,
@@ -170,7 +192,7 @@ public static void ApplyBranchDefaults(Config config,
branchConfig.Regex = string.IsNullOrEmpty(branchConfig.Regex) ? branchRegex : branchConfig.Regex;
branchConfig.Tag = branchConfig.Tag ?? defaultTag;
branchConfig.TagNumberPattern = branchConfig.TagNumberPattern ?? defaultTagNumberPattern;
- branchConfig.Increment = branchConfig.Increment ?? defaultIncrementStrategy;
+ branchConfig.Increment = branchConfig.Increment ?? defaultIncrementStrategy ?? config.Increment ?? DefaultIncrementStrategy;
branchConfig.PreventIncrementOfMergedBranchVersion = branchConfig.PreventIncrementOfMergedBranchVersion ?? defaultPreventIncrement;
branchConfig.TrackMergeTarget = branchConfig.TrackMergeTarget ?? defaultTrackMergeTarget;
branchConfig.VersioningMode = branchConfig.VersioningMode ?? defaultVersioningMode ?? config.VersioningMode;
diff --git a/src/GitVersionCore/Configuration/IncrementStrategy.cs b/src/GitVersionCore/Configuration/IncrementStrategy.cs
index 17a420899c..2d4e677a89 100644
--- a/src/GitVersionCore/Configuration/IncrementStrategy.cs
+++ b/src/GitVersionCore/Configuration/IncrementStrategy.cs
@@ -9,7 +9,8 @@ public enum IncrementStrategy
Minor,
Patch,
///
- /// Uses the increment strategy from the branch the current branch was branched from
+ /// Uses the , and
+ /// of the "parent" branch (i.e. the branch where the current branch was branched from).
///
Inherit
}
diff --git a/src/GitVersionCore/Configuration/Init/SetConfig/ConfigureBranches.cs b/src/GitVersionCore/Configuration/Init/SetConfig/ConfigureBranches.cs
index 57ad92ac88..5a7061299d 100644
--- a/src/GitVersionCore/Configuration/Init/SetConfig/ConfigureBranches.cs
+++ b/src/GitVersionCore/Configuration/Init/SetConfig/ConfigureBranches.cs
@@ -29,7 +29,7 @@ protected override StepResult HandleResult(string result, Queue
+
@@ -144,7 +145,7 @@
-
+
diff --git a/src/GitVersionCore/IncrementStrategyFinder.cs b/src/GitVersionCore/IncrementStrategyFinder.cs
index 73723862a3..e40f9976e6 100644
--- a/src/GitVersionCore/IncrementStrategyFinder.cs
+++ b/src/GitVersionCore/IncrementStrategyFinder.cs
@@ -38,7 +38,7 @@ public static class IncrementStrategyFinder
commitMessageIncrement = VersionField.Minor;
}
- // don't increment for less than the branch config increment, if the absense of commit messages would have
+ // don't increment for less than the branch config increment, if the absence of commit messages would have
// still resulted in an increment of configuration.Increment
if (baseVersion.ShouldIncrement && commitMessageIncrement < defaultIncrement)
{
@@ -54,7 +54,7 @@ public static class IncrementStrategyFinder
{
return null;
}
-
+
var commits = GetIntermediateCommits(context.Repository, baseVersion.BaseVersionSource, context.CurrentCommit);
if (context.Configuration.CommitMessageIncrementing == CommitMessageIncrementMode.MergeMessageOnly)
diff --git a/src/GitVersionCore/LibGitExtensions.cs b/src/GitVersionCore/LibGitExtensions.cs
index 810d68e31d..130cc91c76 100644
--- a/src/GitVersionCore/LibGitExtensions.cs
+++ b/src/GitVersionCore/LibGitExtensions.cs
@@ -32,8 +32,11 @@ public static IEnumerable GetVersionTagsOnBranch(this Branch br
}));
}
-
- public static Commit FindCommitBranchWasBranchedFrom([NotNull] this Branch branch, IRepository repository, params Branch[] excludedBranches)
+ ///
+ /// Find the commit where the given branch was branched from another branch.
+ /// If there are multiple such commits and branches, returns the newest commit.
+ ///
+ public static BranchCommit FindCommitBranchWasBranchedFrom([NotNull] this Branch branch, IRepository repository, params Branch[] excludedBranches)
{
const string missingTipFormat = "{0} has no tip. Please see http://example.com/docs for information on how to fix this.";
@@ -42,46 +45,39 @@ public static Commit FindCommitBranchWasBranchedFrom([NotNull] this Branch branc
throw new ArgumentNullException("branch");
}
- using (Logger.IndentLog("Finding branch source"))
+ using (Logger.IndentLog(string.Format("Finding branch source of '{0}'", branch.FriendlyName)))
{
if (branch.Tip == null)
{
Logger.WriteWarning(string.Format(missingTipFormat, branch.FriendlyName));
- return null;
+ return BranchCommit.Empty;
}
var otherBranches = repository.Branches
- .Except(excludedBranches)
- .Where(b => IsSameBranch(branch, b))
- .ToList();
+ .ExcludingBranches(excludedBranches)
+ .Where(b => !IsSameBranch(branch, b));
var mergeBases = otherBranches.Select(otherBranch =>
{
if (otherBranch.Tip == null)
{
Logger.WriteWarning(string.Format(missingTipFormat, otherBranch.FriendlyName));
- return null;
+ return BranchCommit.Empty;
}
var findMergeBase = FindMergeBase(branch, otherBranch, repository);
- return new
- {
- mergeBaseCommit = findMergeBase,
- branch = otherBranch
- };
- }).Where(b => b.mergeBaseCommit != null).OrderByDescending(b => b.mergeBaseCommit.Committer.When).ToList();
+ return new BranchCommit(findMergeBase,otherBranch);
+ }).Where(b => b.Commit != null).OrderByDescending(b => b.Commit.Committer.When);
- var firstOrDefault = mergeBases.FirstOrDefault();
- if (firstOrDefault != null)
- {
- return firstOrDefault.mergeBaseCommit;
- }
- return null;
+ return mergeBases.FirstOrDefault();
}
}
+ ///
+ /// Find the merge base of the two branches, i.e. the best common ancestor of the two branches' tips.
+ ///
public static Commit FindMergeBase(this Branch branch, Branch otherBranch, IRepository repository)
{
- using (Logger.IndentLog(string.Format("Finding merge base between '{0}' and {1}.", branch.FriendlyName, otherBranch.FriendlyName)))
+ using (Logger.IndentLog(string.Format("Finding merge base between '{0}' and '{1}'.", branch.FriendlyName, otherBranch.FriendlyName)))
{
// Otherbranch tip is a forward merge
var commitToFindCommonBase = otherBranch.Tip;
@@ -96,15 +92,15 @@ public static Commit FindMergeBase(this Branch branch, Branch otherBranch, IRepo
{
Logger.WriteInfo(string.Format("Found merge base of {0}", findMergeBase.Sha));
// We do not want to include merge base commits which got forward merged into the other branch
- bool mergeBaseWasFowardMerge;
+ bool mergeBaseWasForwardMerge;
do
{
// Now make sure that the merge base is not a forward merge
- mergeBaseWasFowardMerge = otherBranch.Commits
+ mergeBaseWasForwardMerge = otherBranch.Commits
.SkipWhile(c => c != commitToFindCommonBase)
.TakeWhile(c => c != findMergeBase)
.Any(c => c.Parents.Contains(findMergeBase));
- if (mergeBaseWasFowardMerge)
+ if (mergeBaseWasForwardMerge)
{
var second = commitToFindCommonBase.Parents.First();
var mergeBase = repository.ObjectDatabase.FindMergeBase(commit, second);
@@ -115,17 +111,34 @@ public static Commit FindMergeBase(this Branch branch, Branch otherBranch, IRepo
findMergeBase = mergeBase;
Logger.WriteInfo(string.Format("Merge base was due to a forward merge, next merge base is {0}", findMergeBase));
}
- } while (mergeBaseWasFowardMerge);
+ } while (mergeBaseWasForwardMerge);
}
return findMergeBase;
}
}
- static bool IsSameBranch(Branch branch, Branch b)
+ ///
+ /// Checks if the two branch objects refer to the same branch (have the same friendly name).
+ ///
+ public static bool IsSameBranch(Branch branch, Branch otherBranch)
+ {
+ // For each branch, fixup the friendly name if the branch is remote.
+ var otherBranchFriendlyName = otherBranch.IsRemote ?
+ otherBranch.FriendlyName.Substring(otherBranch.FriendlyName.IndexOf("/", StringComparison.Ordinal) + 1) :
+ otherBranch.FriendlyName;
+ var branchFriendlyName = branch.IsRemote ?
+ branch.FriendlyName.Substring(branch.FriendlyName.IndexOf("/", StringComparison.Ordinal) + 1) :
+ branch.FriendlyName;
+
+ return otherBranchFriendlyName == branchFriendlyName;
+ }
+
+ ///
+ /// Exclude the given branches (by value equality according to friendly name).
+ ///
+ public static IEnumerable ExcludingBranches([NotNull] this IEnumerable branches, [NotNull] IEnumerable branchesToExclude)
{
- return (b.IsRemote ?
- b.FriendlyName.Substring(b.FriendlyName.IndexOf("/", StringComparison.Ordinal) + 1) :
- b.FriendlyName) != branch.FriendlyName;
+ return branches.Where(b => branchesToExclude.All(bte => !IsSameBranch(b, bte)));
}
public static IEnumerable GetBranchesContainingCommit([NotNull] this Commit commit, IRepository repository, IList branches, bool onlyTrackedBranches)
diff --git a/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/ConfigNextVersionBaseVersionStrategy.cs b/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/ConfigNextVersionBaseVersionStrategy.cs
index d3332dfa65..d69cf450c4 100644
--- a/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/ConfigNextVersionBaseVersionStrategy.cs
+++ b/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/ConfigNextVersionBaseVersionStrategy.cs
@@ -2,6 +2,11 @@
{
using System.Collections.Generic;
+ ///
+ /// Version is from NextVersion (the configuration value), unless the current commit is tagged.
+ /// BaseVersionSource is null.
+ /// Does not increment.
+ ///
public class ConfigNextVersionBaseVersionStrategy : BaseVersionStrategy
{
public override IEnumerable GetVersions(GitVersionContext context)
diff --git a/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/MergeMessageBaseVersionStrategy.cs b/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/MergeMessageBaseVersionStrategy.cs
index 458cdd94de..27a53b3191 100644
--- a/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/MergeMessageBaseVersionStrategy.cs
+++ b/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/MergeMessageBaseVersionStrategy.cs
@@ -6,6 +6,11 @@
using System.Text.RegularExpressions;
using LibGit2Sharp;
+ ///
+ /// Version is extracted from older commits's merge messages.
+ /// BaseVersionSource is the commit where the message was found.
+ /// Increments if PreventIncrementForMergedBranchVersion (from the branch config) is false.
+ ///
public class MergeMessageBaseVersionStrategy : BaseVersionStrategy
{
public override IEnumerable GetVersions(GitVersionContext context)
diff --git a/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs b/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs
index 480cd9c308..4955be0203 100644
--- a/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs
+++ b/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs
@@ -5,6 +5,11 @@
using System.Linq;
using LibGit2Sharp;
+ ///
+ /// Version is extracted from all tags on the branch which are valid, and not newer than the current commit.
+ /// BaseVersionSource is the tag's commit.
+ /// Increments if the tag is not the current commit.
+ ///
public class TaggedCommitVersionStrategy : BaseVersionStrategy
{
public override IEnumerable GetVersions(GitVersionContext context)
diff --git a/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/VersionInBranchBaseVersionStrategy.cs b/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/VersionInBranchNameBaseVersionStrategy.cs
similarity index 84%
rename from src/GitVersionCore/VersionCalculation/BaseVersionCalculators/VersionInBranchBaseVersionStrategy.cs
rename to src/GitVersionCore/VersionCalculation/BaseVersionCalculators/VersionInBranchNameBaseVersionStrategy.cs
index 09afaef1a9..89a6ff7cf8 100644
--- a/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/VersionInBranchBaseVersionStrategy.cs
+++ b/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/VersionInBranchNameBaseVersionStrategy.cs
@@ -4,7 +4,12 @@
using System.Collections.Generic;
using LibGit2Sharp;
- public class VersionInBranchBaseVersionStrategy : BaseVersionStrategy
+ ///
+ /// Version is extracted from the name of the branch.
+ /// BaseVersionSource is the commit where the branch was branched from its parent.
+ /// Does not increment.
+ ///
+ public class VersionInBranchNameBaseVersionStrategy : BaseVersionStrategy
{
public override IEnumerable GetVersions(GitVersionContext context)
{
@@ -22,7 +27,7 @@ public IEnumerable GetVersions(GitVersionContext context, string ta
{
var commitBranchWasBranchedFrom = currentBranch.FindCommitBranchWasBranchedFrom(repository);
var branchNameOverride = branchName.RegexReplace("[-/]" + versionInBranch.Item1, string.Empty);
- yield return new BaseVersion(context, "Version in branch name", false, versionInBranch.Item2, commitBranchWasBranchedFrom, branchNameOverride);
+ yield return new BaseVersion(context, "Version in branch name", false, versionInBranch.Item2, commitBranchWasBranchedFrom.Commit, branchNameOverride);
}
}
diff --git a/src/GitVersionCore/VersionCalculation/BaseVersionStrategy.cs b/src/GitVersionCore/VersionCalculation/BaseVersionStrategy.cs
index a30ccd8c32..67fe87d552 100644
--- a/src/GitVersionCore/VersionCalculation/BaseVersionStrategy.cs
+++ b/src/GitVersionCore/VersionCalculation/BaseVersionStrategy.cs
@@ -5,6 +5,15 @@
public abstract class BaseVersionStrategy
{
+ ///
+ /// Calculates the values for the given .
+ ///
+ ///
+ /// The context for calculating the .
+ ///
+ ///
+ /// An of the base version values found by the strategy.
+ ///
public abstract IEnumerable GetVersions(GitVersionContext context);
}
}
\ No newline at end of file
diff --git a/src/GitVersionCore/VersionCalculation/DevelopVersionStrategy.cs b/src/GitVersionCore/VersionCalculation/DevelopVersionStrategy.cs
index 0c8415c725..7bc7c4ef4a 100644
--- a/src/GitVersionCore/VersionCalculation/DevelopVersionStrategy.cs
+++ b/src/GitVersionCore/VersionCalculation/DevelopVersionStrategy.cs
@@ -8,11 +8,24 @@ namespace GitVersion.VersionCalculation
using LibGit2Sharp;
///
- /// Inherit version from release branch and tags on master
+ /// Active only when the branch is marked as IsDevelop.
+ /// Two different algorithms (results are merged):
+ ///
+ /// Using :
+ /// Version is that of any child branches marked with IsReleaseBranch (except if they have no commits of their own).
+ /// BaseVersionSource is the commit where the child branch was created.
+ /// Always increments.
+ ///
+ ///
+ /// Using :
+ /// Version is extracted from all tags on the master branch which are valid.
+ /// BaseVersionSource is the tag's commit (same as base strategy).
+ /// Increments if the tag is not the current commit (same as base strategy).
+ ///
///
public class DevelopVersionStrategy : BaseVersionStrategy
{
- VersionInBranchBaseVersionStrategy releaseVersionStrategy = new VersionInBranchBaseVersionStrategy();
+ VersionInBranchNameBaseVersionStrategy releaseVersionStrategy = new VersionInBranchNameBaseVersionStrategy();
TaggedCommitVersionStrategy taggedCommitVersionStrategy = new TaggedCommitVersionStrategy();
public override IEnumerable GetVersions(GitVersionContext context)
@@ -70,9 +83,13 @@ IEnumerable GetReleaseVersion(GitVersionContext context, Branch rel
var tagPrefixRegex = context.Configuration.GitTagPrefix;
var repository = context.Repository;
+ // Find the commit where the child branch was created.
var baseSource = releaseBranch.FindMergeBase(context.CurrentBranch, repository);
if (baseSource == context.CurrentCommit)
+ {
+ // Ignore the branch if it has no commits.
return new BaseVersion[0];
+ }
return releaseVersionStrategy
.GetVersions(context, tagPrefixRegex, releaseBranch, repository)
diff --git a/src/GitVersionCore/VersionCalculation/FallbackBaseVersionStrategy.cs b/src/GitVersionCore/VersionCalculation/FallbackBaseVersionStrategy.cs
index 1ee6fa2299..85a2c966f1 100644
--- a/src/GitVersionCore/VersionCalculation/FallbackBaseVersionStrategy.cs
+++ b/src/GitVersionCore/VersionCalculation/FallbackBaseVersionStrategy.cs
@@ -5,6 +5,11 @@
using BaseVersionCalculators;
using LibGit2Sharp;
+ ///
+ /// Version is 0.1.0.
+ /// BaseVersionSource is the "root" commit reachable from the current commit.
+ /// Does not increment.
+ ///
public class FallbackBaseVersionStrategy : BaseVersionStrategy
{
public override IEnumerable GetVersions(GitVersionContext context)
diff --git a/src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs b/src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs
index f60d72c5f4..bc99ac837d 100644
--- a/src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs
+++ b/src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs
@@ -21,7 +21,7 @@ public NextVersionCalculator(IBaseVersionCalculator baseVersionCalculator = null
new ConfigNextVersionBaseVersionStrategy(),
new TaggedCommitVersionStrategy(),
new MergeMessageBaseVersionStrategy(),
- new VersionInBranchBaseVersionStrategy(),
+ new VersionInBranchNameBaseVersionStrategy(),
new DevelopVersionStrategy());
}