diff --git a/GitVersionCore.Tests/GitVersionCore.Tests.csproj b/GitVersionCore.Tests/GitVersionCore.Tests.csproj
index 8befb0d430..3c426280a1 100644
--- a/GitVersionCore.Tests/GitVersionCore.Tests.csproj
+++ b/GitVersionCore.Tests/GitVersionCore.Tests.csproj
@@ -77,6 +77,7 @@
+
diff --git a/GitVersionCore.Tests/IntegrationTests/GitFlow/DevelopScenarios.cs b/GitVersionCore.Tests/IntegrationTests/GitFlow/DevelopScenarios.cs
index b082dd493e..b86c33d6cc 100644
--- a/GitVersionCore.Tests/IntegrationTests/GitFlow/DevelopScenarios.cs
+++ b/GitVersionCore.Tests/IntegrationTests/GitFlow/DevelopScenarios.cs
@@ -12,77 +12,78 @@ public void WhenDevelopBranchedFromTaggedCommitOnMasterVersionDoesNotChange()
{
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.CreateBranch("develop").Checkout();
- // TODO Should actually be 1.0.0+0
- fixture.AssertFullSemver("1.1.0-unstable.0+0");
+ fixture.AssertFullSemver("1.0.0+0");
}
}
[Test]
- public void WhenDevelopBranchedFromMaster_MinorIsIncreased()
+ public void CanChangeDevelopTagViaConfig()
{
- using (var fixture = new EmptyRepositoryFixture(new Config()))
+ var config = new Config();
+ config.Branches["develop"].Tag = "alpha";
+ using (var fixture = new EmptyRepositoryFixture(config))
{
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.CreateBranch("develop").Checkout();
fixture.Repository.MakeACommit();
- fixture.AssertFullSemver("1.1.0-unstable.1+1");
+ fixture.AssertFullSemver("1.1.0-alpha.1+1");
}
}
[Test]
- public void MergingReleaseBranchBackIntoDevelopWithoutMergingToMaster_DoesNotBumpDevelopVersion()
+ public void CanClearDevelopTagViaConfig()
{
- using (var fixture = new EmptyRepositoryFixture(new Config()))
+ var config = new Config();
+ config.Branches["develop"].Tag = "";
+ using (var fixture = new EmptyRepositoryFixture(config))
{
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.CreateBranch("develop").Checkout();
fixture.Repository.MakeACommit();
- fixture.Repository.CreateBranch("release-2.0.0").Checkout();
- fixture.AssertFullSemver("2.0.0-beta.1+0");
- fixture.Repository.Checkout("develop");
- fixture.AssertFullSemver("1.1.0-unstable.1+1");
- fixture.Repository.MergeNoFF("release-2.0.0", Constants.SignatureNow());
- fixture.AssertFullSemver("1.1.0-unstable.1+1");
+ fixture.AssertFullSemver("1.1.0+1");
}
}
-
+
[Test]
- public void CanChangeDevelopTagViaConfig()
+ public void WhenDevelopBranchedFromMaster_MinorIsIncreased()
{
- var config = new Config();
- config.Branches["develop"].Tag = "alpha";
- using (var fixture = new EmptyRepositoryFixture(config))
+ using (var fixture = new EmptyRepositoryFixture(new Config()))
{
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.CreateBranch("develop").Checkout();
- fixture.AssertFullSemver("1.1.0-alpha.0+0");
+ fixture.Repository.MakeACommit();
+ fixture.AssertFullSemver("1.1.0-unstable.1+1");
}
}
[Test]
- public void CanHandleContinuousDelivery()
+ public void MergingReleaseBranchBackIntoDevelopWithoutMergingToMaster_DoesNotBumpDevelopVersion()
{
- var config = new Config();
- config.Branches["develop"].VersioningMode = VersioningMode.ContinuousDelivery;
- using (var fixture = new EmptyRepositoryFixture(config))
+ using (var fixture = new EmptyRepositoryFixture(new Config()))
{
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.CreateBranch("develop").Checkout();
- fixture.Repository.MakeATaggedCommit("1.1.0-alpha7");
- fixture.AssertFullSemver("1.1.0-alpha.7+1");
+ fixture.Repository.MakeACommit();
+ fixture.Repository.CreateBranch("release-2.0.0").Checkout();
+ fixture.AssertFullSemver("2.0.0-beta.1+0");
+ fixture.Repository.Checkout("develop");
+ fixture.AssertFullSemver("1.1.0-unstable.1+1");
+ fixture.Repository.MergeNoFF("release-2.0.0", Constants.SignatureNow());
+ fixture.AssertFullSemver("1.1.0-unstable.1+1");
}
}
-
+
[Test]
- public void CanClearDevelopTagViaConfig()
+ public void CanHandleContinuousDelivery()
{
var config = new Config();
- config.Branches["develop"].Tag = "";
+ config.Branches["develop"].VersioningMode = VersioningMode.ContinuousDelivery;
using (var fixture = new EmptyRepositoryFixture(config))
{
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.CreateBranch("develop").Checkout();
- fixture.AssertFullSemver("1.1.0+0");
+ fixture.Repository.MakeATaggedCommit("1.1.0-alpha7");
+ fixture.AssertFullSemver("1.1.0-alpha.7+0");
}
}
diff --git a/GitVersionCore.Tests/IntegrationTests/GitFlow/GitFlowFeatureBranchTests.cs b/GitVersionCore.Tests/IntegrationTests/GitFlow/GitFlowFeatureBranchTests.cs
index 4790aa96e0..ac13fa8d9a 100644
--- a/GitVersionCore.Tests/IntegrationTests/GitFlow/GitFlowFeatureBranchTests.cs
+++ b/GitVersionCore.Tests/IntegrationTests/GitFlow/GitFlowFeatureBranchTests.cs
@@ -17,7 +17,7 @@ public void ShouldNotUseNumberInFeatureBranchAsPreReleaseNumber()
fixture.Repository.Checkout("feature/JIRA-123");
fixture.Repository.MakeCommits(5);
- fixture.AssertFullSemver("1.1.0-JIRA-123+5");
+ fixture.AssertFullSemver("1.1.0-JIRA-123.1+5");
}
}
}
\ No newline at end of file
diff --git a/GitVersionCore.Tests/IntegrationTests/GitFlow/PatchScenarios.cs b/GitVersionCore.Tests/IntegrationTests/GitFlow/PatchScenarios.cs
index a2146c5c21..cf6189d8c1 100644
--- a/GitVersionCore.Tests/IntegrationTests/GitFlow/PatchScenarios.cs
+++ b/GitVersionCore.Tests/IntegrationTests/GitFlow/PatchScenarios.cs
@@ -13,13 +13,13 @@ public void PatchLatestReleaseExample()
// create hotfix
fixture.Repository.CreateBranch("hotfix-1.2.1").Checkout();
- fixture.AssertFullSemver("1.2.1-beta.1+1");
+ fixture.AssertFullSemver("1.2.1-beta.1+0");
fixture.Repository.MakeACommit();
- fixture.AssertFullSemver("1.2.1-beta.1+2");
+ fixture.AssertFullSemver("1.2.1-beta.1+1");
fixture.Repository.ApplyTag("1.2.1-beta.1");
- fixture.AssertFullSemver("1.2.1-beta.1+2");
+ fixture.AssertFullSemver("1.2.1-beta.1+0");
fixture.Repository.MakeACommit();
- fixture.AssertFullSemver("1.2.1-beta.2+3");
+ fixture.AssertFullSemver("1.2.1-beta.2+1");
// Merge hotfix branch to master
fixture.Repository.Checkout("master");
diff --git a/GitVersionCore.Tests/IntegrationTests/GitFlow/ReleaseBranchTests.cs b/GitVersionCore.Tests/IntegrationTests/GitFlow/ReleaseBranchTests.cs
index c10f9dc3a7..dd7812fa08 100644
--- a/GitVersionCore.Tests/IntegrationTests/GitFlow/ReleaseBranchTests.cs
+++ b/GitVersionCore.Tests/IntegrationTests/GitFlow/ReleaseBranchTests.cs
@@ -16,7 +16,9 @@ public void CanTakeVersionFromReleaseBranch()
fixture.Repository.CreateBranch("release-2.0.0");
fixture.Repository.Checkout("release-2.0.0");
- fixture.AssertFullSemver("2.0.0-beta.1+5");
+ fixture.AssertFullSemver("2.0.0-beta.1+0");
+ fixture.Repository.MakeCommits(2);
+ fixture.AssertFullSemver("2.0.0-beta.1+2");
}
}
@@ -33,26 +35,9 @@ public void CanTakeVersionFromReleaseBranchWithTagOverriden()
fixture.Repository.CreateBranch("release-2.0.0");
fixture.Repository.Checkout("release-2.0.0");
- fixture.AssertFullSemver("2.0.0-rc.1+5");
- }
- }
-
- [Test]
- public void CanHandleContinuousDeployment()
- {
- var config = new Config
- {
- VersioningMode = VersioningMode.ContinuousDeployment
- };
- using (var fixture = new EmptyRepositoryFixture(config))
- {
- fixture.Repository.MakeATaggedCommit("1.0.3");
- fixture.Repository.CreateBranch("develop");
- fixture.Repository.MakeCommits(5);
- fixture.Repository.CreateBranch("release-2.0.0");
- fixture.Repository.Checkout("release-2.0.0");
-
- fixture.AssertFullSemver("2.0.0-beta.5+5");
+ fixture.AssertFullSemver("2.0.0-rc.1+0");
+ fixture.Repository.MakeCommits(2);
+ fixture.AssertFullSemver("2.0.0-rc.1+2");
}
}
@@ -67,7 +52,9 @@ public void CanHandleReleaseBranchWithStability()
fixture.Repository.CreateBranch("release-2.0.0-Final");
fixture.Repository.Checkout("release-2.0.0-Final");
- fixture.AssertFullSemver("2.0.0-beta.1+5");
+ fixture.AssertFullSemver("2.0.0-beta.1+0");
+ fixture.Repository.MakeCommits(2);
+ fixture.AssertFullSemver("2.0.0-beta.1+2");
}
}
@@ -85,13 +72,13 @@ public void WhenReleaseBranchIsMergedIntoMasterVersionIsTakenWithIt()
fixture.Repository.Checkout("master");
fixture.Repository.MergeNoFF("release-2.0.0", Constants.SignatureNow());
- // TODO For GitHubFlow this is 2.0.0+6, why is it different
- fixture.AssertFullSemver("2.0.0");
+ fixture.AssertFullSemver("2.0.0+0");
+ fixture.Repository.MakeCommits(2);
+ fixture.AssertFullSemver("2.0.0+2");
}
}
- // TODO This test fails for GitFlow, it needs to be fixed (although in reality a support branch should be used)
- [Test, Ignore]
+ [Test]
public void WhenReleaseBranchIsMergedIntoMasterHighestVersionIsTakenWithIt()
{
using (var fixture = new EmptyRepositoryFixture(new Config()))
@@ -116,7 +103,7 @@ public void WhenReleaseBranchIsMergedIntoMasterHighestVersionIsTakenWithIt()
fixture.Repository.Checkout("develop");
fixture.Repository.MergeNoFF("release-1.0.0", Constants.SignatureNow());
- fixture.AssertFullSemver("2.0.0+11");
+ fixture.AssertFullSemver("2.0.0-unstable.1+5");
}
}
}
\ No newline at end of file
diff --git a/GitVersionCore.Tests/IntegrationTests/GitFlow/SwitchingToGitFlowScenarios.cs b/GitVersionCore.Tests/IntegrationTests/GitFlow/SwitchingToGitFlowScenarios.cs
index 6db460f55f..b7f827d8ce 100644
--- a/GitVersionCore.Tests/IntegrationTests/GitFlow/SwitchingToGitFlowScenarios.cs
+++ b/GitVersionCore.Tests/IntegrationTests/GitFlow/SwitchingToGitFlowScenarios.cs
@@ -14,7 +14,7 @@ public void WhenDevelopBranchedFromMasterWithLegacyVersionTags_DevelopCanUseReac
fixture.Repository.MakeATaggedCommit("1.0.0.0");
fixture.Repository.MakeCommits(2);
fixture.Repository.CreateBranch("develop").Checkout();
- fixture.AssertFullSemver("1.1.0-unstable.0+0");
+ fixture.AssertFullSemver("1.1.0-unstable.1+2");
}
}
}
\ No newline at end of file
diff --git a/GitVersionCore.Tests/IntegrationTests/GitFlow/WikiScenarios.cs b/GitVersionCore.Tests/IntegrationTests/GitFlow/WikiScenarios.cs
index 2e27189f61..e4ce05549a 100644
--- a/GitVersionCore.Tests/IntegrationTests/GitFlow/WikiScenarios.cs
+++ b/GitVersionCore.Tests/IntegrationTests/GitFlow/WikiScenarios.cs
@@ -44,7 +44,8 @@ public void MinorReleaseExample()
// Branch to develop
fixture.Repository.CreateBranch("develop").Checkout();
- fixture.AssertFullSemver("1.3.0-unstable.0+0");
+ fixture.Repository.MakeACommit();
+ fixture.AssertFullSemver("1.3.0-unstable.1+1");
// Open Pull Request
fixture.Repository.CreateBranch("pull/2/merge").Checkout();
diff --git a/GitVersionCore.Tests/IntegrationTests/GitHubFlow/GitHubFlowFeatureBranchTests.cs b/GitVersionCore.Tests/IntegrationTests/GitHubFlow/GitHubFlowFeatureBranchTests.cs
index 1cdd7e34fb..953ab54f59 100644
--- a/GitVersionCore.Tests/IntegrationTests/GitHubFlow/GitHubFlowFeatureBranchTests.cs
+++ b/GitVersionCore.Tests/IntegrationTests/GitHubFlow/GitHubFlowFeatureBranchTests.cs
@@ -15,7 +15,7 @@ public void ShouldNotUseNumberInFeatureBranchAsPreReleaseNumber()
fixture.Repository.Checkout("feature/JIRA-123");
fixture.Repository.MakeCommits(5);
- fixture.AssertFullSemver("1.0.1-JIRA-123+5");
+ fixture.AssertFullSemver("1.0.1-JIRA-123.1+5");
}
}
@@ -29,7 +29,7 @@ public void TestFeatureBranch()
fixture.Repository.Checkout("feature-test");
fixture.Repository.MakeCommits(5);
- fixture.AssertFullSemver("1.0.1-feature-test+5");
+ fixture.AssertFullSemver("1.0.1-test.1+5");
}
}
}
\ No newline at end of file
diff --git a/GitVersionCore.Tests/IntegrationTests/GitHubFlow/GitHubFlowSupportBranchScenarios.cs b/GitVersionCore.Tests/IntegrationTests/GitHubFlow/GitHubFlowSupportBranchScenarios.cs
index 96ad48d0a9..ee6e4cabd7 100644
--- a/GitVersionCore.Tests/IntegrationTests/GitHubFlow/GitHubFlowSupportBranchScenarios.cs
+++ b/GitVersionCore.Tests/IntegrationTests/GitHubFlow/GitHubFlowSupportBranchScenarios.cs
@@ -37,16 +37,16 @@ public void SupportIsCalculatedCorrectly()
// Create 1.2.0 release
fixture.Repository.Checkout("support/1.0.0");
fixture.Repository.MergeNoFF("release/1.2.0");
- fixture.AssertFullSemver("1.2.0+2");
+ fixture.AssertFullSemver("1.2.0+0");
fixture.Repository.ApplyTag("1.2.0");
// Create 1.2.1 hotfix
fixture.Repository.CreateBranch("hotfix/1.2.1").Checkout();
fixture.Repository.MakeACommit();
- fixture.AssertFullSemver("1.2.1+1");
+ fixture.AssertFullSemver("1.2.1-beta.1+1");
fixture.Repository.Checkout("support/1.0.0");
fixture.Repository.MergeNoFF("hotfix/1.2.1");
- fixture.AssertFullSemver("1.2.1+2");
+ fixture.AssertFullSemver("1.2.1+0");
}
}
@@ -69,7 +69,7 @@ public void WhenSupportIsBranchedAndTaggedFromAnotherSupportEnsureNewMinorIsUsed
fixture.Repository.MakeACommit();
fixture.Repository.MakeACommit();
- fixture.AssertFullSemver("1.3.1+2");
+ fixture.AssertFullSemver("1.3.1+0");
}
}
}
\ No newline at end of file
diff --git a/GitVersionCore.Tests/IntegrationTests/GitHubFlow/ReleaseBranchTests.cs b/GitVersionCore.Tests/IntegrationTests/GitHubFlow/ReleaseBranchTests.cs
index 52b2f7896a..4626bca28d 100644
--- a/GitVersionCore.Tests/IntegrationTests/GitHubFlow/ReleaseBranchTests.cs
+++ b/GitVersionCore.Tests/IntegrationTests/GitHubFlow/ReleaseBranchTests.cs
@@ -15,7 +15,9 @@ public void CanTakeVersionFromReleaseBranch()
fixture.Repository.CreateBranch("release-2.0.0");
fixture.Repository.Checkout("release-2.0.0");
- fixture.AssertFullSemver("2.0.0-beta.1+5");
+ fixture.AssertFullSemver("2.0.0-beta.1+0");
+ fixture.Repository.MakeCommits(2);
+ fixture.AssertFullSemver("2.0.0-beta.1+2");
}
}
@@ -31,7 +33,9 @@ public void CanTakeVersionFromReleaseBranchWithTagOverriden()
fixture.Repository.CreateBranch("release-2.0.0");
fixture.Repository.Checkout("release-2.0.0");
- fixture.AssertFullSemver("2.0.0-rc.1+5");
+ fixture.AssertFullSemver("2.0.0-rc.1+0");
+ fixture.Repository.MakeCommits(2);
+ fixture.AssertFullSemver("2.0.0-rc.1+2");
}
}
@@ -48,7 +52,7 @@ public void WhenReleaseBranchIsMergedIntoMasterVersionIsTakenWithIt()
fixture.Repository.Checkout("master");
fixture.Repository.MergeNoFF("release-2.0.0", Constants.SignatureNow());
- fixture.AssertFullSemver("2.0.0+6");
+ fixture.AssertFullSemver("2.0.0+0");
}
}
[Test]
@@ -71,7 +75,7 @@ public void WhenReleaseBranchIsMergedIntoMasterHighestVersionIsTakenWithIt()
fixture.Repository.Checkout("master");
fixture.Repository.MergeNoFF("release-1.0.0", Constants.SignatureNow());
- fixture.AssertFullSemver("2.0.0+11");
+ fixture.AssertFullSemver("2.0.0+5");
}
}
diff --git a/GitVersionCore.Tests/IntegrationTests/PullRequestScenarios.cs b/GitVersionCore.Tests/IntegrationTests/PullRequestScenarios.cs
new file mode 100644
index 0000000000..d6eceedd69
--- /dev/null
+++ b/GitVersionCore.Tests/IntegrationTests/PullRequestScenarios.cs
@@ -0,0 +1,99 @@
+using GitVersion;
+using LibGit2Sharp;
+using NUnit.Framework;
+
+[TestFixture]
+public class PullRequestScenarios
+{
+ [Test]
+ public void CanCalculatePullRequestChanges()
+ {
+ using (var fixture = new EmptyRepositoryFixture(new Config()))
+ {
+ fixture.Repository.MakeATaggedCommit("0.1.0");
+ fixture.Repository.CreateBranch("feature/Foo").Checkout();
+ fixture.Repository.MakeACommit();
+
+ fixture.Repository.Checkout("master");
+ fixture.Repository.MergeNoFF("feature/Foo");
+ fixture.Repository.CreateBranch("pull/2/merge").Checkout();
+ fixture.Repository.Checkout("master");
+ fixture.Repository.Reset(ResetMode.Hard, "HEAD~1");
+ fixture.Repository.Checkout("pull/2/merge");
+
+ fixture.DumpGraph();
+ fixture.AssertFullSemver("0.1.1-PullRequest.1+2");
+ }
+ }
+
+ [Test]
+ public void CanCalculatePullRequestChangesInheritingConfig()
+ {
+ using (var fixture = new EmptyRepositoryFixture(new Config()))
+ {
+ fixture.Repository.MakeATaggedCommit("0.1.0");
+ fixture.Repository.CreateBranch("develop").Checkout();
+ fixture.Repository.MakeACommit();
+ fixture.Repository.CreateBranch("feature/Foo").Checkout();
+ fixture.Repository.MakeACommit();
+
+ fixture.Repository.Checkout("develop");
+ fixture.Repository.MergeNoFF("feature/Foo");
+ fixture.Repository.CreateBranch("pull/2/merge").Checkout();
+ fixture.Repository.Checkout("develop");
+ fixture.Repository.Reset(ResetMode.Hard, "HEAD~1");
+ fixture.Repository.Checkout("pull/2/merge");
+
+ fixture.DumpGraph();
+ fixture.AssertFullSemver("0.2.0-PullRequest.1+3");
+ }
+ }
+
+ [Test]
+ public void CanCalculatePullRequestChangesFromRemoteRepo()
+ {
+ using (var fixture = new EmptyRepositoryFixture(new Config()))
+ {
+ fixture.Repository.MakeATaggedCommit("0.1.0");
+ fixture.Repository.CreateBranch("feature/Foo").Checkout();
+ fixture.Repository.MakeACommit();
+
+ fixture.Repository.Checkout("master");
+ fixture.Repository.MergeNoFF("feature/Foo");
+ fixture.Repository.CreateBranch("pull/2/merge").Checkout();
+ fixture.Repository.Checkout("master");
+ fixture.Repository.Reset(ResetMode.Hard, "HEAD~1");
+ fixture.Repository.Checkout("pull/2/merge");
+ // If we delete the branch, it is effectively the same as remote PR
+ fixture.Repository.Branches.Remove("feature/Foo");
+
+ fixture.DumpGraph();
+ fixture.AssertFullSemver("0.1.1-PullRequest.1+2");
+ }
+ }
+
+ [Test]
+ public void CanCalculatePullRequestChangesInheritingConfigFromRemoteRepo()
+ {
+ using (var fixture = new EmptyRepositoryFixture(new Config()))
+ {
+ fixture.Repository.MakeATaggedCommit("0.1.0");
+ fixture.Repository.CreateBranch("develop").Checkout();
+ fixture.Repository.MakeACommit();
+ fixture.Repository.CreateBranch("feature/Foo").Checkout();
+ fixture.Repository.MakeACommit();
+
+ fixture.Repository.Checkout("develop");
+ fixture.Repository.MergeNoFF("feature/Foo");
+ fixture.Repository.CreateBranch("pull/2/merge").Checkout();
+ fixture.Repository.Checkout("develop");
+ fixture.Repository.Reset(ResetMode.Hard, "HEAD~1");
+ fixture.Repository.Checkout("pull/2/merge");
+ // If we delete the branch, it is effectively the same as remote PR
+ fixture.Repository.Branches.Remove("feature/Foo");
+
+ fixture.DumpGraph();
+ fixture.AssertFullSemver("0.2.0-PullRequest.1+3");
+ }
+ }
+}
\ No newline at end of file
diff --git a/GitVersionCore.Tests/Mocks/MockBranch.cs b/GitVersionCore.Tests/Mocks/MockBranch.cs
index b03e5d5a27..f4a2865d6f 100644
--- a/GitVersionCore.Tests/Mocks/MockBranch.cs
+++ b/GitVersionCore.Tests/Mocks/MockBranch.cs
@@ -31,6 +31,16 @@ public override string CanonicalName
get { return canonicalName; }
}
+ public override int GetHashCode()
+ {
+ return name.GetHashCode();
+ }
+
+ public override bool Equals(object obj)
+ {
+ return ReferenceEquals(this, obj);
+ }
+
public IEnumerator GetEnumerator()
{
return commits.GetEnumerator();
diff --git a/GitVersionCore.Tests/VersionCalculation/BaseVersionCalculatorTests.cs b/GitVersionCore.Tests/VersionCalculation/BaseVersionCalculatorTests.cs
index 5f8c204ad7..98fd552532 100644
--- a/GitVersionCore.Tests/VersionCalculation/BaseVersionCalculatorTests.cs
+++ b/GitVersionCore.Tests/VersionCalculation/BaseVersionCalculatorTests.cs
@@ -64,7 +64,7 @@ public V1Strategy(DateTimeOffset? when)
public override BaseVersion GetVersion(GitVersionContext context)
{
- return new BaseVersion(false, true, new SemanticVersion(1), when);
+ return new BaseVersion("Source 1", false, true, new SemanticVersion(1), when, null);
}
}
@@ -79,7 +79,7 @@ public V2Strategy(DateTimeOffset? when)
public override BaseVersion GetVersion(GitVersionContext context)
{
- return new BaseVersion(true, true, new SemanticVersion(2), when);
+ return new BaseVersion("Source 2", true, true, new SemanticVersion(2), when, null);
}
}
}
diff --git a/GitVersionCore.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs b/GitVersionCore.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs
index ac22497e58..5681045d66 100644
--- a/GitVersionCore.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs
+++ b/GitVersionCore.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs
@@ -10,8 +10,10 @@
public class MergeMessageBaseVersionStrategyTests
{
[Test]
- public void ShouldAllowIncrementOfVersion()
+ public void ShouldNotAllowIncrementOfVersion()
{
+ // When a branch is merged in you want to start building stable packages of that version
+ // So we shouldn't bump the version
var context = new GitVersionContextBuilder().WithRepository(new MockRepository
{
Head = new MockBranch("master") { new MockCommit
@@ -24,7 +26,7 @@ public void ShouldAllowIncrementOfVersion()
var baseVersion = sut.GetVersion(context);
- baseVersion.ShouldIncrement.ShouldBe(true);
+ baseVersion.ShouldIncrement.ShouldBe(false);
}
[TestCase("Merge branch 'hotfix-0.1.5'", false, null)]
diff --git a/GitVersionCore.Tests/VersionCalculation/TestBaseVersionCalculator.cs b/GitVersionCore.Tests/VersionCalculation/TestBaseVersionCalculator.cs
index f38dae098d..5cb51845b3 100644
--- a/GitVersionCore.Tests/VersionCalculation/TestBaseVersionCalculator.cs
+++ b/GitVersionCore.Tests/VersionCalculation/TestBaseVersionCalculator.cs
@@ -22,7 +22,7 @@ public TestBaseVersionCalculator(bool shouldIncrement, bool shouldUpdateTag, Sem
public BaseVersion GetBaseVersion(GitVersionContext context)
{
- return new BaseVersion(shouldIncrement, shouldUpdateTag, semanticVersion, source);
+ return new BaseVersion("Test source", shouldIncrement, shouldUpdateTag, semanticVersion, source, null);
}
}
}
\ No newline at end of file
diff --git a/GitVersionCore/Configuration/Config.cs b/GitVersionCore/Configuration/Config.cs
index 2d602b338f..4d571a6e26 100644
--- a/GitVersionCore/Configuration/Config.cs
+++ b/GitVersionCore/Configuration/Config.cs
@@ -13,6 +13,12 @@ public Config()
AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch;
TagPrefix = "[vV]";
VersioningMode = GitVersion.VersioningMode.ContinuousDelivery;
+
+ Branches["master"] = new BranchConfig
+ {
+ Tag = string.Empty,
+ Increment = IncrementStrategy.Patch,
+ };
Branches["release[/-]"] = new BranchConfig { Tag = "beta" };
Branches["feature[/-]"] = new BranchConfig
{
@@ -26,6 +32,11 @@ public Config()
Increment = IncrementStrategy.Minor,
VersioningMode = GitVersion.VersioningMode.ContinuousDeployment
};
+ Branches[@"(pull|pull\-requests|pr)[/-]"] = new BranchConfig
+ {
+ Tag = "PullRequest",
+ Increment = IncrementStrategy.Inherit
+ };
}
[YamlAlias("assembly-versioning-scheme")]
diff --git a/GitVersionCore/GitHubFlow/LastTaggedReleaseFinder.cs b/GitVersionCore/GitHubFlow/LastTaggedReleaseFinder.cs
index 2777693816..d3cb9b5f51 100644
--- a/GitVersionCore/GitHubFlow/LastTaggedReleaseFinder.cs
+++ b/GitVersionCore/GitHubFlow/LastTaggedReleaseFinder.cs
@@ -19,7 +19,7 @@ public bool GetVersion(out VersionTaggedCommit versionTaggedCommit)
SemanticVersion version;
if (SemanticVersion.TryParse(t.Name, context.Configuration.GitTagPrefix, out version))
{
- return new VersionTaggedCommit((Commit)t.Target, version);
+ return new VersionTaggedCommit((Commit)t.Target, version, t.Name);
}
return null;
})
diff --git a/GitVersionCore/GitHubFlow/VersionTaggedCommit.cs b/GitVersionCore/GitHubFlow/VersionTaggedCommit.cs
index 48d5fd13eb..712b1e7690 100644
--- a/GitVersionCore/GitHubFlow/VersionTaggedCommit.cs
+++ b/GitVersionCore/GitHubFlow/VersionTaggedCommit.cs
@@ -4,11 +4,13 @@
public class VersionTaggedCommit
{
+ public string Tag;
public Commit Commit;
public SemanticVersion SemVer;
- public VersionTaggedCommit(Commit commit, SemanticVersion semVer)
+ public VersionTaggedCommit(Commit commit, SemanticVersion semVer, string tag)
{
+ Tag = tag;
Commit = commit;
SemVer = semVer;
}
diff --git a/GitVersionCore/GitVersionContext.cs b/GitVersionCore/GitVersionContext.cs
index 0b8cbf2c67..25b6891ece 100644
--- a/GitVersionCore/GitVersionContext.cs
+++ b/GitVersionCore/GitVersionContext.cs
@@ -83,8 +83,10 @@ void CalculateEffectiveConfiguration()
{
var currentBranchConfig = GetBranchConfiguration(CurrentBranch);
- var versioningMode = currentBranchConfig.Value.VersioningMode ?? configuration.VersioningMode ?? VersioningMode.ContinuousDelivery;
- var tag = currentBranchConfig.Value.Tag;
+ // Versioning mode drills down, if top level is specified then it takes priority
+ var versioningMode = configuration.VersioningMode ?? currentBranchConfig.Value.VersioningMode ?? VersioningMode.ContinuousDelivery;
+
+ var tag = currentBranchConfig.Value.Tag ?? "useBranchName";
var nextVersion = configuration.NextVersion;
var incrementStrategy = currentBranchConfig.Value.Increment ?? IncrementStrategy.Patch;
var assemblyVersioningScheme = configuration.AssemblyVersioningScheme;
@@ -107,40 +109,7 @@ KeyValuePair GetBranchConfiguration(Branch currentBranch)
if (branchConfiguration.Increment == IncrementStrategy.Inherit)
{
- var branchPoint = currentBranch.FindCommitBranchWasBranchedFrom(Repository);
-
- List possibleParents;
- if (branchPoint.Sha == CurrentCommit.Sha)
- {
- possibleParents = ListBranchesContaininingCommit(Repository, CurrentCommit.Sha).Except(new[]
- {
- currentBranch
- }).ToList();
- }
- else
- {
- var branches = ListBranchesContaininingCommit(Repository, branchPoint.Sha).ToArray();
- var currentTipBranches = ListBranchesContaininingCommit(Repository, CurrentCommit.Sha).ToArray();
- possibleParents = branches
- .Except(currentTipBranches)
- .ToList();
- }
-
- // If it comes down to master and something, master is always first so we pick other branch
- if (possibleParents.Count == 2 && possibleParents.Any(p => p.Name == "master"))
- possibleParents.Remove(possibleParents.Single(p => p.Name == "master"));
-
- if (possibleParents.Count == 1)
- {
- return new KeyValuePair(
- keyValuePair.Key,
- new BranchConfig(branchConfiguration)
- {
- Increment = GetBranchConfiguration(possibleParents[0]).Value.Increment
- });
- }
-
- throw new Exception("Failed to inherit Increment branch configuration");
+ return InheritBranchConfiguration(currentBranch, keyValuePair, branchConfiguration);
}
return keyValuePair;
@@ -150,9 +119,71 @@ KeyValuePair GetBranchConfiguration(Branch currentBranch)
throw new Exception(string.Format(format, currentBranch.Name, string.Join(", ", matchingBranches.Select(b => b.Key))));
}
- static IEnumerable ListBranchesContaininingCommit(IRepository repo, string commitSha)
+ KeyValuePair InheritBranchConfiguration(Branch currentBranch, KeyValuePair keyValuePair, BranchConfig branchConfiguration)
+ {
+ var excludedBranches = new Branch[0];
+ // Check if we are a merge commit. If so likely we are a pull request
+ var parentCount = CurrentCommit.Parents.Count();
+ if (parentCount == 2)
+ {
+ var parents = CurrentCommit.Parents.ToArray();
+ var branch = Repository.Branches.SingleOrDefault(b => !b.IsRemote && b.Tip == parents[1]) ;
+ if (branch != null)
+ {
+ excludedBranches = new[]
+ {
+ currentBranch,
+ branch
+ };
+ currentBranch = branch;
+ }
+ else
+ {
+ currentBranch = Repository.Branches.SingleOrDefault(b => !b.IsRemote && b.Tip == parents[0]) ?? currentBranch;
+ }
+ }
+
+ var branchPoint = currentBranch.FindCommitBranchWasBranchedFrom(Repository, excludedBranches);
+
+ List possibleParents;
+ if (branchPoint.Sha == CurrentCommit.Sha)
+ {
+ possibleParents = ListBranchesContaininingCommit(Repository, CurrentCommit.Sha, excludedBranches).Except(new[]
+ {
+ currentBranch
+ }).ToList();
+ }
+ else
+ {
+ var branches = ListBranchesContaininingCommit(Repository, branchPoint.Sha, excludedBranches).ToArray();
+ var currentTipBranches = ListBranchesContaininingCommit(Repository, CurrentCommit.Sha, excludedBranches).ToArray();
+ possibleParents = branches
+ .Except(currentTipBranches)
+ .ToList();
+ }
+
+ // If it comes down to master and something, master is always first so we pick other branch
+ if (possibleParents.Count == 2 && possibleParents.Any(p => p.Name == "master"))
+ {
+ possibleParents.Remove(possibleParents.Single(p => p.Name == "master"));
+ }
+
+ if (possibleParents.Count == 1)
+ {
+ return new KeyValuePair(
+ keyValuePair.Key,
+ new BranchConfig(branchConfiguration)
+ {
+ Increment = GetBranchConfiguration(possibleParents[0]).Value.Increment
+ });
+ }
+
+ throw new Exception("Failed to inherit Increment branch configuration");
+ }
+
+ static IEnumerable ListBranchesContaininingCommit(IRepository repo, string commitSha, Branch[] excludedBranches)
{
- return from branch in repo.Branches
+ return from branch in repo.Branches.Except(excludedBranches)
where !branch.IsRemote
let commits = repo.Commits.QueryBy(new CommitFilter { Since = branch }).Where(c => c.Sha == commitSha)
where commits.Any()
diff --git a/GitVersionCore/LibGitExtensions.cs b/GitVersionCore/LibGitExtensions.cs
index b7980457af..ec87573844 100644
--- a/GitVersionCore/LibGitExtensions.cs
+++ b/GitVersionCore/LibGitExtensions.cs
@@ -24,10 +24,10 @@ public static Branch FindBranch(this IRepository repository, string branchName)
return repository.Branches.FirstOrDefault(x => x.Name == "origin/" + branchName);
}
- public static Commit FindCommitBranchWasBranchedFrom(this Branch branch, IRepository repository)
+ public static Commit FindCommitBranchWasBranchedFrom(this Branch branch, IRepository repository, params Branch[] excludedBranches)
{
- var tips = repository.Branches.Select(b => b.Tip).Where(c => c.Sha != branch.Tip.Sha).ToList();
- return repository.Commits.FirstOrDefault(c => tips.Contains(c) || c.Parents.Count() > 1) ?? branch.Tip;
+ var tips = repository.Branches.Except(excludedBranches).Where(b => b != branch && !b.IsRemote).Select(b => b.Tip).ToList();
+ return branch.Commits.FirstOrDefault(c => tips.Contains(c) || c.Parents.Count() > 1) ?? branch.Tip;
}
public static IEnumerable TagsByDate(this IRepository repository, Commit commit)
diff --git a/GitVersionCore/VersionCalculation/BaseVersionCalculator.cs b/GitVersionCore/VersionCalculation/BaseVersionCalculator.cs
index a87e55fd8c..5ad6897f0d 100644
--- a/GitVersionCore/VersionCalculation/BaseVersionCalculator.cs
+++ b/GitVersionCore/VersionCalculation/BaseVersionCalculator.cs
@@ -14,18 +14,33 @@ public BaseVersionCalculator(params BaseVersionStrategy[] strategies)
public BaseVersion GetBaseVersion(GitVersionContext context)
{
- return strategies
+ Logger.WriteInfo("Base Versions:");
+
+ var baseVersion = strategies
.Select(s => s.GetVersion(context))
- .Where(v => v != null)
+ .Where(v =>
+ {
+ if (v != null)
+ {
+ Logger.WriteInfo(v.ToString());
+ return true;
+ }
+
+ return false;
+ })
.Aggregate((v1, v2) =>
{
if (v1.SemanticVersion > v2.SemanticVersion)
{
- return new BaseVersion(v1.ShouldIncrement, v1.ShouldUpdateTag, v1.SemanticVersion, v1.BaseVersionSource ?? v2.BaseVersionSource);
+ return new BaseVersion(v1.Source, v1.ShouldIncrement, v1.ShouldUpdateTag, v1.SemanticVersion, v1.BaseVersionSource ?? v2.BaseVersionSource, v1.BranchNameOverride);
}
- return new BaseVersion(v2.ShouldIncrement, v2.ShouldUpdateTag, v2.SemanticVersion, v2.BaseVersionSource ?? v1.BaseVersionSource);
+ return new BaseVersion(v2.Source, v2.ShouldIncrement, v2.ShouldUpdateTag, v2.SemanticVersion, v2.BaseVersionSource ?? v1.BaseVersionSource, v2.BranchNameOverride);
});
+
+ Logger.WriteInfo(string.Format("Base version used: {0}", baseVersion));
+
+ return baseVersion;
}
}
}
\ No newline at end of file
diff --git a/GitVersionCore/VersionCalculation/BaseVersionCalculators/BaseVersion.cs b/GitVersionCore/VersionCalculation/BaseVersionCalculators/BaseVersion.cs
index f566090ce1..3ecf755580 100644
--- a/GitVersionCore/VersionCalculation/BaseVersionCalculators/BaseVersion.cs
+++ b/GitVersionCore/VersionCalculation/BaseVersionCalculators/BaseVersion.cs
@@ -4,14 +4,18 @@
public class BaseVersion
{
- public BaseVersion(bool shouldIncrement, bool shouldUpdateTag, SemanticVersion semanticVersion, Commit baseVersionSource)
+ public BaseVersion(string source, bool shouldIncrement, bool shouldUpdateTag, SemanticVersion semanticVersion, Commit baseVersionSource, string branchNameOverride)
{
+ Source = source;
ShouldIncrement = shouldIncrement;
ShouldUpdateTag = shouldUpdateTag;
SemanticVersion = semanticVersion;
BaseVersionSource = baseVersionSource;
+ BranchNameOverride = branchNameOverride;
}
+ public string Source { get; private set; }
+
public bool ShouldIncrement { get; private set; }
public bool ShouldUpdateTag { get; private set; }
@@ -19,5 +23,12 @@ public BaseVersion(bool shouldIncrement, bool shouldUpdateTag, SemanticVersion s
public SemanticVersion SemanticVersion { get; private set; }
public Commit BaseVersionSource { get; private set; }
+
+ public string BranchNameOverride { get; private set; }
+
+ public override string ToString()
+ {
+ return string.Format("{0}: {1} from commit {2}", Source, SemanticVersion.ToString("f"), BaseVersionSource == null ? "External Source" : BaseVersionSource.Sha);
+ }
}
}
\ No newline at end of file
diff --git a/GitVersionCore/VersionCalculation/BaseVersionCalculators/ConfigNextVersionBaseVersionStrategy.cs b/GitVersionCore/VersionCalculation/BaseVersionCalculators/ConfigNextVersionBaseVersionStrategy.cs
index 3bccf10ad9..d2d971e3e6 100644
--- a/GitVersionCore/VersionCalculation/BaseVersionCalculators/ConfigNextVersionBaseVersionStrategy.cs
+++ b/GitVersionCore/VersionCalculation/BaseVersionCalculators/ConfigNextVersionBaseVersionStrategy.cs
@@ -6,7 +6,8 @@ public override BaseVersion GetVersion(GitVersionContext context)
{
if (string.IsNullOrEmpty(context.Configuration.NextVersion))
return null;
- return new BaseVersion(false, true, SemanticVersion.Parse(context.Configuration.NextVersion, context.Configuration.GitTagPrefix), null);
+ var semanticVersion = SemanticVersion.Parse(context.Configuration.NextVersion, context.Configuration.GitTagPrefix);
+ return new BaseVersion("NextVersion in GitVersionConfig.yaml", false, true, semanticVersion, null, null);
}
}
}
\ No newline at end of file
diff --git a/GitVersionCore/VersionCalculation/BaseVersionCalculators/LastTagBaseVersionStrategy.cs b/GitVersionCore/VersionCalculation/BaseVersionCalculators/LastTagBaseVersionStrategy.cs
index ce621a87af..5f1b0f0be0 100644
--- a/GitVersionCore/VersionCalculation/BaseVersionCalculators/LastTagBaseVersionStrategy.cs
+++ b/GitVersionCore/VersionCalculation/BaseVersionCalculators/LastTagBaseVersionStrategy.cs
@@ -8,7 +8,7 @@ public override BaseVersion GetVersion(GitVersionContext context)
if (new LastTaggedReleaseFinder(context).GetVersion(out version))
{
var shouldUpdateVersion = version.Commit.Sha != context.CurrentCommit.Sha;
- return new BaseVersion(shouldUpdateVersion, shouldUpdateVersion, version.SemVer, version.Commit);
+ return new BaseVersion(string.Format("Git tag '{0}'", version.Tag), shouldUpdateVersion, shouldUpdateVersion, version.SemVer, version.Commit, null);
}
return null;
diff --git a/GitVersionCore/VersionCalculation/BaseVersionCalculators/MergeMessageBaseVersionStrategy.cs b/GitVersionCore/VersionCalculation/BaseVersionCalculators/MergeMessageBaseVersionStrategy.cs
index dea7b0736f..3cc422f936 100644
--- a/GitVersionCore/VersionCalculation/BaseVersionCalculators/MergeMessageBaseVersionStrategy.cs
+++ b/GitVersionCore/VersionCalculation/BaseVersionCalculators/MergeMessageBaseVersionStrategy.cs
@@ -16,7 +16,7 @@ public override BaseVersion GetVersion(GitVersionContext context)
if (MergeMessageParser.TryParse(c, context.Configuration, out semanticVersion))
return new[]
{
- new BaseVersion(true, true, semanticVersion, c)
+ new BaseVersion(string.Format("Merge message '{0}'", c.Message.Trim()), false, true, semanticVersion, c, null)
};
return Enumerable.Empty();
})
diff --git a/GitVersionCore/VersionCalculation/BaseVersionCalculators/VersionInBranchBaseVersionStrategy.cs b/GitVersionCore/VersionCalculation/BaseVersionCalculators/VersionInBranchBaseVersionStrategy.cs
index 7531c2a989..f2d0bfe2d1 100644
--- a/GitVersionCore/VersionCalculation/BaseVersionCalculators/VersionInBranchBaseVersionStrategy.cs
+++ b/GitVersionCore/VersionCalculation/BaseVersionCalculators/VersionInBranchBaseVersionStrategy.cs
@@ -1,7 +1,6 @@
namespace GitVersion.VersionCalculation.BaseVersionCalculators
{
using System;
- using System.Linq;
public class VersionInBranchBaseVersionStrategy : BaseVersionStrategy
{
@@ -11,8 +10,8 @@ public override BaseVersion GetVersion(GitVersionContext context)
if (versionInBranch != null)
{
var commitBranchWasBranchedFrom = context.CurrentBranch.FindCommitBranchWasBranchedFrom(context.Repository);
- var baseVersionSource = context.CurrentBranch.Commits.First(c => c.Sha != commitBranchWasBranchedFrom.Sha);
- return new BaseVersion(false, true, versionInBranch.Item2, baseVersionSource);
+ var branchNameOverride = context.CurrentBranch.Name.RegexReplace("[-/]" + versionInBranch.Item1, string.Empty);
+ return new BaseVersion("Version in branch name", false, true, versionInBranch.Item2, commitBranchWasBranchedFrom, branchNameOverride);
}
return null;
diff --git a/GitVersionCore/VersionCalculation/FallbackBaseVersionStrategy.cs b/GitVersionCore/VersionCalculation/FallbackBaseVersionStrategy.cs
index e0943ff2e4..f6aa89897a 100644
--- a/GitVersionCore/VersionCalculation/FallbackBaseVersionStrategy.cs
+++ b/GitVersionCore/VersionCalculation/FallbackBaseVersionStrategy.cs
@@ -7,7 +7,7 @@ public class FallbackBaseVersionStrategy : BaseVersionStrategy
{
public override BaseVersion GetVersion(GitVersionContext context)
{
- return new BaseVersion(false, true, new SemanticVersion(minor: 1), context.CurrentBranch.Commits.Last());
+ return new BaseVersion("Fallback base version", false, true, new SemanticVersion(minor: 1), context.CurrentBranch.Commits.Last(), null);
}
}
}
\ No newline at end of file
diff --git a/GitVersionCore/VersionCalculation/MetaDataCalculator.cs b/GitVersionCore/VersionCalculation/MetaDataCalculator.cs
index 9afb84787f..37bfdde0d3 100644
--- a/GitVersionCore/VersionCalculation/MetaDataCalculator.cs
+++ b/GitVersionCore/VersionCalculation/MetaDataCalculator.cs
@@ -14,7 +14,8 @@ public SemanticVersionBuildMetaData Create(Commit baseVersionSource, GitVersionC
SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Time
};
- var commitsSinceTag = context.Repository.Commits.QueryBy(qf).Count();
+ var commitLog = context.Repository.Commits.QueryBy(qf);
+ var commitsSinceTag = commitLog.Count();
return new SemanticVersionBuildMetaData(
commitsSinceTag,
diff --git a/GitVersionCore/VersionCalculation/NewNextVersionCalculator.cs b/GitVersionCore/VersionCalculation/NewNextVersionCalculator.cs
index 91762f9d4a..6d9c40f5c9 100644
--- a/GitVersionCore/VersionCalculation/NewNextVersionCalculator.cs
+++ b/GitVersionCore/VersionCalculation/NewNextVersionCalculator.cs
@@ -26,12 +26,17 @@ public SemanticVersion FindVersion(GitVersionContext context)
var baseVersion = baseVersionFinder.GetBaseVersion(context);
if (baseVersion.ShouldIncrement) IncrementVersion(context, baseVersion);
+ else Logger.WriteInfo("Skipping version increment");
if (baseVersion.ShouldUpdateTag && !baseVersion.SemanticVersion.PreReleaseTag.HasTag() && !string.IsNullOrEmpty(context.Configuration.Tag))
{
var tagToUse = context.Configuration.Tag;
if (tagToUse == "useBranchName")
- tagToUse = context.CurrentBranch.Name.RegexReplace(context.Configuration.BranchPrefixToTrim, string.Empty, RegexOptions.IgnoreCase);
+ {
+ Logger.WriteInfo("Using branch name to calculate version tag");
+ var name = baseVersion.BranchNameOverride ?? context.CurrentBranch.Name;
+ tagToUse = name.RegexReplace(context.Configuration.BranchPrefixToTrim, string.Empty, RegexOptions.IgnoreCase);
+ }
baseVersion.SemanticVersion.PreReleaseTag = new SemanticVersionPreReleaseTag(tagToUse, 1);
}
@@ -47,15 +52,19 @@ static void IncrementVersion(GitVersionContext context, BaseVersion baseVersion)
switch (context.Configuration.Increment)
{
case IncrementStrategy.None:
+ Logger.WriteInfo("Skipping version increment");
break;
case IncrementStrategy.Major:
+ Logger.WriteInfo("Incrementing Major Version");
baseVersion.SemanticVersion.Major++;
break;
case IncrementStrategy.Minor:
baseVersion.SemanticVersion.Minor++;
+ Logger.WriteInfo("Incrementing Minor Version");
break;
case IncrementStrategy.Patch:
baseVersion.SemanticVersion.Patch++;
+ Logger.WriteInfo("Incrementing Patch Version");
break;
default:
throw new ArgumentOutOfRangeException();