diff --git a/GitVersion.yml b/GitVersion.yml index 28207f4374..11ca8fe20d 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -1,2 +1,6 @@ assembly-versioning-scheme: MajorMinorPatch -next-version: 3.4.0 +branches: + master: + tag: beta +ignore: + sha: [] diff --git a/docs/configuration.md b/docs/configuration.md index 9e4059ba34..12cdd451a9 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -48,6 +48,10 @@ The global configuration options are: - **`sha:`** A sequence of SHAs to be excluded from the version calculations. Useful when there is a rogue commit in history yielding a bad version. - **`commits-before:`** Allows to setup an exclusion range. Effectively any commit < `commits-before` will be ignored. + - **`is-develop:`** Indicates this branch config represents develop in GitFlow + + **`is-release-branch:`** Indicates this branch config represents a release branch in GitFlow + ## Branch configuration Then we have branch specific configuration, which looks something like this: diff --git a/docs/git-branching-strategies/img/05119d0cd4ecaaefff94_feature-branch.png b/docs/git-branching-strategies/img/05119d0cd4ecaaefff94_feature-branch.png index 906d758f05..a11136d3cc 100644 Binary files a/docs/git-branching-strategies/img/05119d0cd4ecaaefff94_feature-branch.png and b/docs/git-branching-strategies/img/05119d0cd4ecaaefff94_feature-branch.png differ diff --git a/docs/git-branching-strategies/img/09fdf46995b771f3164a_pull-request.png b/docs/git-branching-strategies/img/09fdf46995b771f3164a_pull-request.png index 0fbfe1ee05..62eb8ead00 100644 Binary files a/docs/git-branching-strategies/img/09fdf46995b771f3164a_pull-request.png and b/docs/git-branching-strategies/img/09fdf46995b771f3164a_pull-request.png differ diff --git a/docs/git-branching-strategies/img/2167fb1c4a5cf84edfd8_support-minor.png b/docs/git-branching-strategies/img/2167fb1c4a5cf84edfd8_support-minor.png index 6f972f0bee..7151facb20 100644 Binary files a/docs/git-branching-strategies/img/2167fb1c4a5cf84edfd8_support-minor.png and b/docs/git-branching-strategies/img/2167fb1c4a5cf84edfd8_support-minor.png differ diff --git a/docs/git-branching-strategies/img/39f9d8b8b007c82f1f80_major-release.png b/docs/git-branching-strategies/img/39f9d8b8b007c82f1f80_major-release.png index 5dc5ad3157..74a1b2f976 100644 Binary files a/docs/git-branching-strategies/img/39f9d8b8b007c82f1f80_major-release.png and b/docs/git-branching-strategies/img/39f9d8b8b007c82f1f80_major-release.png differ diff --git a/docs/git-branching-strategies/img/6d33d35a70a777608fa1_minor-release.png b/docs/git-branching-strategies/img/6d33d35a70a777608fa1_minor-release.png index cd141608c4..e5f8b4c8a0 100644 Binary files a/docs/git-branching-strategies/img/6d33d35a70a777608fa1_minor-release.png and b/docs/git-branching-strategies/img/6d33d35a70a777608fa1_minor-release.png differ diff --git a/docs/git-branching-strategies/img/b035b8ca99bd34239518_support-hotfix.png b/docs/git-branching-strategies/img/b035b8ca99bd34239518_support-hotfix.png index bb80329b0d..fa9ffaf673 100644 Binary files a/docs/git-branching-strategies/img/b035b8ca99bd34239518_support-hotfix.png and b/docs/git-branching-strategies/img/b035b8ca99bd34239518_support-hotfix.png differ diff --git a/docs/git-branching-strategies/img/f26ae57adbd9b74f74c4_hotfix.png b/docs/git-branching-strategies/img/f26ae57adbd9b74f74c4_hotfix.png index 3ee574c51d..b7bb60c8e7 100644 Binary files a/docs/git-branching-strategies/img/f26ae57adbd9b74f74c4_hotfix.png and b/docs/git-branching-strategies/img/f26ae57adbd9b74f74c4_hotfix.png differ diff --git a/src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt b/src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt index e8bce0cdb1..9fcb8beca8 100644 --- a/src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt +++ b/src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt @@ -16,18 +16,24 @@ branches: increment: Patch prevent-increment-of-merged-branch-version: true track-merge-target: false + is-develop: false + is-release-branch: false releases?[/-]: mode: ContinuousDelivery tag: beta increment: Patch prevent-increment-of-merged-branch-version: true track-merge-target: false + is-develop: false + is-release-branch: true features?[/-]: mode: ContinuousDelivery tag: useBranchName increment: Inherit prevent-increment-of-merged-branch-version: false track-merge-target: false + is-develop: false + is-release-branch: false (pull|pull\-requests|pr)[/-]: mode: ContinuousDelivery tag: PullRequest @@ -35,23 +41,31 @@ branches: prevent-increment-of-merged-branch-version: false tag-number-pattern: '[/-](?\d+)[-/]' track-merge-target: false + is-develop: false + is-release-branch: false hotfix(es)?[/-]: mode: ContinuousDelivery tag: beta increment: Patch prevent-increment-of-merged-branch-version: false track-merge-target: false + is-develop: false + is-release-branch: false support[/-]: mode: ContinuousDelivery tag: '' increment: Patch prevent-increment-of-merged-branch-version: true track-merge-target: false + is-develop: false + is-release-branch: false dev(elop)?(ment)?$: mode: ContinuousDeployment - tag: unstable + tag: alpha increment: Minor prevent-increment-of-merged-branch-version: false track-merge-target: true + is-develop: true + is-release-branch: false ignore: sha: [] diff --git a/src/GitVersionCore.Tests/ConfigProviderTests.cs b/src/GitVersionCore.Tests/ConfigProviderTests.cs index 643c505c67..f7f1fc8d4f 100644 --- a/src/GitVersionCore.Tests/ConfigProviderTests.cs +++ b/src/GitVersionCore.Tests/ConfigProviderTests.cs @@ -216,7 +216,7 @@ public void CanReadDefaultDocument() var config = ConfigurationProvider.Provide(repoPath, fileSystem); config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch); config.AssemblyInformationalFormat.ShouldBe(null); - config.Branches["dev(elop)?(ment)?$"].Tag.ShouldBe("unstable"); + config.Branches["dev(elop)?(ment)?$"].Tag.ShouldBe("alpha"); config.Branches["releases?[/-]"].Tag.ShouldBe("beta"); config.TagPrefix.ShouldBe(ConfigurationProvider.DefaultTagPrefix); config.NextVersion.ShouldBe(null); @@ -242,10 +242,10 @@ public void WarnOnExistingGitVersionConfigYamlFile(string path) var logOutput = string.Empty; Action action = info => { logOutput = info; }; - Logger.SetLoggers(action, action, action); - - ConfigurationProvider.Verify(workingPath, repoPath, fileSystem); - + using (Logger.AddLoggersTemporarily(action, action, action)) + { + ConfigurationProvider.Verify(workingPath, repoPath, fileSystem); + } var configFileDeprecatedWarning = string.Format("{0}' is deprecated, use '{1}' instead", ConfigurationProvider.ObsoleteConfigFileName, ConfigurationProvider.DefaultConfigFileName); logOutput.Contains(configFileDeprecatedWarning).ShouldBe(true); } @@ -289,10 +289,10 @@ public void NoWarnOnGitVersionYmlFile() var s = string.Empty; Action action = info => { s = info; }; - Logger.SetLoggers(action, action, action); - - ConfigurationProvider.Provide(repoPath, fileSystem); - + using (Logger.AddLoggersTemporarily(action, action, action)) + { + ConfigurationProvider.Provide(repoPath, fileSystem); + } s.Length.ShouldBe(0); } diff --git a/src/GitVersionCore.Tests/ExecuteCoreTests.cs b/src/GitVersionCore.Tests/ExecuteCoreTests.cs index 48b6b4647b..15fa7a7010 100644 --- a/src/GitVersionCore.Tests/ExecuteCoreTests.cs +++ b/src/GitVersionCore.Tests/ExecuteCoreTests.cs @@ -200,12 +200,10 @@ string RepositoryScope(ExecuteCore executeCore = null, Action infoLogger = s => { infoBuilder.AppendLine(s); - Console.WriteLine(s); }; executeCore = executeCore ?? new ExecuteCore(fileSystem); - Logger.SetLoggers(infoLogger, Console.WriteLine, Console.WriteLine); - + using (Logger.AddLoggersTemporarily(infoLogger, s => {}, s => { })) using (var fixture = new EmptyRepositoryFixture()) { fixture.Repository.MakeACommit(); diff --git a/src/GitVersionCore.Tests/GitToolsTestingExtensions.cs b/src/GitVersionCore.Tests/GitToolsTestingExtensions.cs index 1e6f4a635e..c556e0d7ab 100644 --- a/src/GitVersionCore.Tests/GitToolsTestingExtensions.cs +++ b/src/GitVersionCore.Tests/GitToolsTestingExtensions.cs @@ -15,9 +15,13 @@ public static Config ApplyDefaults(this Config config) return config; } - public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Config configuration, IRepository repository = null, string commitId = null, bool isForTrackedBranchOnly = true) + public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Config configuration = null, IRepository repository = null, string commitId = null, bool isForTrackedBranchOnly = true) { - ConfigurationProvider.ApplyDefaultsTo(configuration); + if (configuration == null) + { + configuration = new Config(); + ConfigurationProvider.ApplyDefaultsTo(configuration); + } var gitVersionContext = new GitVersionContext(repository ?? fixture.Repository, configuration, isForTrackedBranchOnly, commitId); var executeGitVersion = ExecuteGitVersion(gitVersionContext); var variables = VariableProvider.GetVariablesFor(executeGitVersion, gitVersionContext.Configuration, gitVersionContext.IsCurrentCommitTagged); @@ -55,7 +59,7 @@ public static void AssertFullSemver(this RepositoryFixtureBase fixture, Config c } if (commitId == null) { - fixture.SequenceDiagram.NoteOver(fullSemver, fixture.Repository.Head.FriendlyName, color: "#D3D3D3"); + fixture.SequenceDiagram.NoteOver(fullSemver, fixture.Repository.Head.FriendlyName, color: "#D3D3D3"); } } @@ -70,7 +74,7 @@ static SemanticVersion ExecuteGitVersion(GitVersionContext context) /// public static void InitialiseRepo(this RemoteRepositoryFixture fixture) { - // TODO !!new GitPreparer(null, null, new Authentication(), false, fixture.LocalRepositoryFixture.RepositoryPath).Initialise(true, null); + new GitPreparer(null, null, new Authentication(), false, fixture.LocalRepositoryFixture.RepositoryPath).Initialise(true, null); } } } \ No newline at end of file diff --git a/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs index 5c9f1a99df..a7de0697dd 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs @@ -21,7 +21,7 @@ public void WhenDevelopHasMultipleCommits_SpecifyExistingCommitId() fixture.Repository.MakeACommit(); fixture.Repository.MakeACommit(); - fixture.AssertFullSemver("1.1.0-unstable.3", commitId: thirdCommit.Sha); + fixture.AssertFullSemver("1.1.0-alpha.3", commitId: thirdCommit.Sha); } } @@ -39,7 +39,7 @@ public void WhenDevelopHasMultipleCommits_SpecifyNonExistingCommitId() fixture.Repository.MakeACommit(); fixture.Repository.MakeACommit(); - fixture.AssertFullSemver("1.1.0-unstable.5", commitId: "nonexistingcommitid"); + fixture.AssertFullSemver("1.1.0-alpha.5", commitId: "nonexistingcommitid"); } } @@ -61,10 +61,11 @@ public void CanChangeDevelopTagViaConfig() { Branches = { - {"dev(elop)?(ment)?$", new BranchConfig { - Tag = "alpha" - } + "dev(elop)?(ment)?$", new BranchConfig + { + Tag = "alpha" + } } } }; @@ -97,7 +98,7 @@ public void WhenDevelopBranchedFromMaster_MinorIsIncreased() fixture.Repository.MakeATaggedCommit("1.0.0"); fixture.Repository.Checkout(fixture.Repository.CreateBranch("develop")); fixture.Repository.MakeACommit(); - fixture.AssertFullSemver("1.1.0-unstable.1"); + fixture.AssertFullSemver("1.1.0-alpha.1"); } } @@ -116,7 +117,7 @@ public void MergingReleaseBranchBackIntoDevelopWithMergingToMaster_DoesBumpDevel fixture.Repository.Checkout("develop"); fixture.Repository.MergeNoFF("release-2.0.0", Generate.SignatureNow()); - fixture.AssertFullSemver("2.1.0-unstable.0"); + fixture.AssertFullSemver("2.1.0-alpha.2"); } } @@ -154,7 +155,30 @@ public void WhenDevelopBranchedFromMasterDetachedHead_MinorIsIncreased() var commit = fixture.Repository.Head.Tip; fixture.Repository.MakeACommit(); fixture.Repository.Checkout(commit); - fixture.AssertFullSemver("1.1.0-unstable.1"); + fixture.AssertFullSemver("1.1.0-alpha.1"); + } + } + + [Test] + public void InheritVersionFromReleaseBranch() + { + using (var fixture = new EmptyRepositoryFixture()) + { + fixture.MakeATaggedCommit("1.0.0"); + fixture.BranchTo("develop"); + fixture.MakeACommit(); + fixture.BranchTo("release/2.0.0"); + fixture.MakeACommit(); + fixture.MakeACommit(); + fixture.Checkout("develop"); + fixture.AssertFullSemver("2.1.0-alpha.0"); + fixture.MakeACommit(); + fixture.AssertFullSemver("2.1.0-alpha.1"); + fixture.MergeNoFF("release/2.0.0"); + fixture.AssertFullSemver("2.1.0-alpha.4"); + fixture.BranchTo("feature/MyFeature"); + fixture.MakeACommit(); + fixture.AssertFullSemver("2.1.0-MyFeature.1+3"); } } } \ No newline at end of file diff --git a/src/GitVersionCore.Tests/IntegrationTests/DocumentationSamples.cs b/src/GitVersionCore.Tests/IntegrationTests/DocumentationSamples.cs index 5774629b98..7f07b14bc3 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/DocumentationSamples.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/DocumentationSamples.cs @@ -1,6 +1,6 @@ -using GitTools; +using System; +using GitTools; using GitTools.Testing; -using GitVersion; using GitVersionCore.Tests; using NUnit.Framework; using Shouldly; @@ -23,7 +23,7 @@ public void GitFlowFeatureBranch() // Branch to develop fixture.MakeACommit(); - fixture.AssertFullSemver("1.3.0-unstable.1"); + fixture.AssertFullSemver("1.3.0-alpha.1"); // Open Pull Request fixture.BranchTo("feature/myfeature", "feature"); @@ -38,7 +38,8 @@ public void GitFlowFeatureBranch() fixture.SequenceDiagram.Destroy("feature/myfeature"); fixture.SequenceDiagram.NoteOver("Feature branches should\r\n" + "be deleted once merged", "feature/myfeature"); - fixture.AssertFullSemver("1.3.0-unstable.3"); + fixture.AssertFullSemver("1.3.0-alpha.3"); + Console.WriteLine(fixture.SequenceDiagram.GetDiagram()); } } @@ -57,7 +58,7 @@ public void GitFlowPullRequestBranch() // Branch to develop fixture.MakeACommit(); - fixture.AssertFullSemver("1.3.0-unstable.1"); + fixture.AssertFullSemver("1.3.0-alpha.1"); // Open Pull Request fixture.BranchTo("pull/2/merge", "pr"); @@ -72,7 +73,8 @@ public void GitFlowPullRequestBranch() fixture.SequenceDiagram.Destroy("pull/2/merge"); fixture.SequenceDiagram.NoteOver("Feature branches/pr's should\r\n" + "be deleted once merged", "pull/2/merge"); - fixture.AssertFullSemver("1.3.0-unstable.3"); + fixture.AssertFullSemver("1.3.0-alpha.3"); + Console.WriteLine(fixture.SequenceDiagram.GetDiagram()); } } @@ -103,6 +105,7 @@ public void GitFlowHotfixBranch() fixture.SequenceDiagram.Destroy("hotfix/1.2.1"); fixture.SequenceDiagram.NoteOver("Hotfix branches are deleted once merged", "hotfix/1.2.1"); fixture.ApplyTag("1.2.1"); + Console.WriteLine(fixture.SequenceDiagram.GetDiagram()); } } @@ -130,7 +133,7 @@ public void GitFlowMinorRelease() // Make another commit on develop fixture.Checkout("develop"); fixture.MakeACommit(); - fixture.AssertFullSemver("1.3.0-unstable.2"); + fixture.AssertFullSemver("1.4.0-alpha.1"); // Make a commit to release-1.3.0 fixture.Checkout("release/1.3.0"); @@ -159,7 +162,8 @@ public void GitFlowMinorRelease() // Not 0 for commit count as we can't know the increment rules of the merged branch fixture.Checkout("develop"); - fixture.AssertFullSemver("1.4.0-unstable.2"); + fixture.AssertFullSemver("1.4.0-alpha.4"); + Console.WriteLine(fixture.SequenceDiagram.GetDiagram()); } } @@ -186,7 +190,7 @@ public void GitFlowMajorRelease() // Make another commit on develop fixture.Checkout("develop"); fixture.MakeACommit(); - fixture.AssertFullSemver("1.4.0-unstable.2"); + fixture.AssertFullSemver("2.1.0-alpha.1"); // Make a commit to release-2.0.0 fixture.Checkout("release/2.0.0"); @@ -216,7 +220,8 @@ public void GitFlowMajorRelease() // Not 0 for commit count as we can't know the increment rules of the merged branch fixture.Checkout("develop"); - fixture.AssertFullSemver("2.1.0-unstable.2"); + fixture.AssertFullSemver("2.1.0-alpha.4"); + Console.WriteLine(fixture.SequenceDiagram.GetDiagram()); } } @@ -260,6 +265,7 @@ public void GitFlowSupportHotfixRelease() fixture.AssertFullSemver("1.3.1+4"); fixture.ApplyTag("1.3.1"); fixture.AssertFullSemver("1.3.1"); + Console.WriteLine(fixture.SequenceDiagram.GetDiagram()); } } @@ -304,6 +310,7 @@ public void GitFlowSupportMinorRelease() fixture.AssertFullSemver("1.4.0+0"); fixture.ApplyTag("1.4.0"); fixture.AssertFullSemver("1.4.0"); + Console.WriteLine(fixture.SequenceDiagram.GetDiagram()); } } @@ -395,7 +402,7 @@ public void GitHubFlowMajorRelease() fixture.AssertFullSemver("2.0.0-beta.1"); // test that the CommitsSinceVersionSource should still return commit count - var version = fixture.GetVersion(new Config()); + var version = fixture.GetVersion(); version.CommitsSinceVersionSource.ShouldBe("2"); // Make a commit after a tag should bump up the beta diff --git a/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs index fa2ac953e4..d078218c69 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs @@ -199,4 +199,42 @@ public void ShouldUseConfiguredTag(string tag, string featureName, string preRel fixture.AssertFullSemver(config, expectedFullSemVer); } } + + [Test] + public void BranchCreatedAfterFinishReleaseShouldInheritAndIncrementFromLastMasterCommitTag() + { + using (var fixture = new BaseGitFlowRepositoryFixture("0.1.0")) + { + //validate current version + fixture.AssertFullSemver("0.2.0-alpha.1"); + fixture.Repository.CreateBranch("release/0.2.0"); + fixture.Repository.Checkout("release/0.2.0"); + + //validate release version + fixture.AssertFullSemver("0.2.0-beta.1+0"); + + fixture.Checkout("master"); + fixture.Repository.MergeNoFF("release/0.2.0"); + fixture.Repository.ApplyTag("0.2.0"); + + //validate master branch version + fixture.AssertFullSemver("0.2.0"); + + 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) + fixture.AssertFullSemver("0.3.0-alpha.1"); + + //create a feature branch from develop + fixture.BranchTo("feature/TEST-1"); + fixture.Repository.MakeACommit(); + + //I'm not entirely sure what the + value should be but I know the semvar major/minor/patch should be 0.3.0 + fixture.AssertFullSemver("0.3.0-TEST-1.1+2"); + } + } } \ No newline at end of file diff --git a/src/GitVersionCore.Tests/IntegrationTests/HotfixBranchScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/HotfixBranchScenarios.cs index 568be0b2fd..34db00ecd9 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/HotfixBranchScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/HotfixBranchScenarios.cs @@ -37,10 +37,10 @@ public void PatchLatestReleaseExample() // Verify develop version fixture.Repository.Checkout("develop"); - fixture.AssertFullSemver("1.3.0-unstable.1"); + fixture.AssertFullSemver("1.3.0-alpha.1"); fixture.Repository.MergeNoFF("hotfix-1.2.1", Generate.SignatureNow()); - fixture.AssertFullSemver("1.3.0-unstable.5"); + fixture.AssertFullSemver("1.3.0-alpha.5"); } } @@ -118,9 +118,9 @@ public void PatchOlderReleaseExample() // Verify develop version fixture.Repository.Checkout("develop"); - fixture.AssertFullSemver("2.1.0-unstable.1"); + fixture.AssertFullSemver("2.1.0-alpha.1"); fixture.Repository.MergeNoFF("support-1.1", Generate.SignatureNow()); - fixture.AssertFullSemver("2.1.0-unstable.7"); + fixture.AssertFullSemver("2.1.0-alpha.7"); } } } \ No newline at end of file diff --git a/src/GitVersionCore.Tests/IntegrationTests/OtherScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/OtherScenarios.cs index 9c7ad0e311..f4872407f7 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/OtherScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/OtherScenarios.cs @@ -41,7 +41,7 @@ public void AllowNotHavingMaster() fixture.Repository.Checkout(fixture.Repository.CreateBranch("develop")); fixture.Repository.Branches.Remove(fixture.Repository.Branches["master"]); - fixture.AssertFullSemver("1.1.0-unstable.1"); + fixture.AssertFullSemver("1.1.0-alpha.1"); } } @@ -85,7 +85,7 @@ public void DoNotBlowUpWhenDevelopAndFeatureBranchPointAtSameCommit() fixture.LocalRepositoryFixture.Repository.Checkout(fixture.Repository.Head.Tip); fixture.LocalRepositoryFixture.Repository.Branches.Remove("master"); fixture.InitialiseRepo(); - fixture.AssertFullSemver("1.1.0-unstable.1"); + fixture.AssertFullSemver("1.1.0-alpha.1"); } } } diff --git a/src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs index 0a0e917d85..f7009c6db7 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs @@ -20,11 +20,10 @@ public void NoMergeBacksToDevelopInCaseThereAreNoChangesInReleaseBranch() fixture.Repository.MergeNoFF("release/1.0.0"); fixture.Repository.ApplyTag("1.0.0"); fixture.Repository.Checkout("develop"); - fixture.Repository.MakeACommit(); fixture.Repository.Branches.Remove(releaseBranch); - fixture.AssertFullSemver("1.1.0-unstable.1"); + fixture.AssertFullSemver("1.1.0-alpha.0"); } } @@ -48,12 +47,12 @@ public void NoMergeBacksToDevelopInCaseThereAreChangesInReleaseBranch() // Merge to develop fixture.Repository.Checkout("develop"); fixture.Repository.MergeNoFF("release/1.0.0"); - fixture.AssertFullSemver("1.1.0-unstable.1"); + fixture.AssertFullSemver("1.1.0-alpha.2"); fixture.Repository.MakeACommit(); fixture.Repository.Branches.Remove(releaseBranch); - fixture.AssertFullSemver("1.1.0-unstable.2"); + fixture.AssertFullSemver("1.1.0-alpha.2"); } } @@ -226,7 +225,7 @@ public void WhenReleaseBranchIsMergedIntoDevelopHighestVersionIsTakenWithIt() fixture.Repository.Checkout("develop"); fixture.Repository.MergeNoFF("release-1.0.0", Generate.SignatureNow()); - fixture.AssertFullSemver("2.1.0-unstable.5"); + fixture.AssertFullSemver("2.1.0-alpha.6"); } } @@ -265,7 +264,7 @@ public void WhenMergingReleaseBackToDevShouldNotResetBetaVersion() fixture.Repository.Checkout("develop"); fixture.Repository.MakeCommits(1); - fixture.AssertFullSemver("1.1.0-unstable.1"); + fixture.AssertFullSemver("1.1.0-alpha.1"); fixture.Repository.CreateBranch("release-2.0.0"); fixture.Repository.Checkout("release-2.0.0"); @@ -330,4 +329,35 @@ public void HotfixOffReleaseBranchShouldNotResetCount() fixture.AssertFullSemver(config, "2.0.0-beta.7"); } } + [Test] + public void MergeOnReleaseBranchShouldNotResetCount() + { + var config = new Config + { + AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatchTag, + VersioningMode = VersioningMode.ContinuousDeployment, + }; + using (var fixture = new EmptyRepositoryFixture()) + { + const string TaggedVersion = "1.0.3"; + fixture.Repository.MakeATaggedCommit(TaggedVersion); + fixture.Repository.CreateBranch("develop"); + fixture.Repository.Checkout("develop"); + fixture.Repository.MakeACommit(); + + fixture.Repository.CreateBranch("release/2.0.0"); + + fixture.Repository.CreateBranch("release/2.0.0-xxx"); + fixture.Repository.Checkout("release/2.0.0-xxx"); + fixture.Repository.MakeACommit(); + fixture.AssertFullSemver(config, "2.0.0-beta.1"); + + fixture.Repository.Checkout("release/2.0.0"); + fixture.Repository.MakeACommit(); + fixture.AssertFullSemver(config, "2.0.0-beta.1"); + + fixture.Repository.MergeNoFF("release/2.0.0-xxx"); + fixture.AssertFullSemver(config, "2.0.0-beta.2"); + } + } } \ No newline at end of file diff --git a/src/GitVersionCore.Tests/IntegrationTests/SwitchingToGitFlowScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/SwitchingToGitFlowScenarios.cs index 40fab4f303..a0da7fc231 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/SwitchingToGitFlowScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/SwitchingToGitFlowScenarios.cs @@ -15,7 +15,7 @@ public void WhenDevelopBranchedFromMasterWithLegacyVersionTags_DevelopCanUseReac fixture.Repository.MakeATaggedCommit("1.0.0.0"); fixture.Repository.MakeCommits(2); fixture.Repository.Checkout(fixture.Repository.CreateBranch("develop")); - fixture.AssertFullSemver("1.1.0-unstable.2"); + fixture.AssertFullSemver("1.1.0-alpha.2"); } } } \ No newline at end of file diff --git a/src/GitVersionCore.Tests/LoggerTest.cs b/src/GitVersionCore.Tests/LoggerTest.cs index 807a47fca9..742ccf8868 100644 --- a/src/GitVersionCore.Tests/LoggerTest.cs +++ b/src/GitVersionCore.Tests/LoggerTest.cs @@ -1,6 +1,8 @@ using NUnit.Framework; using System; using GitVersion; +using Shouldly; + namespace GitVersionCore.Tests { [TestFixture] @@ -15,11 +17,10 @@ public void LoggerObscuresPassword(string protocol) const string password = "password"; var s = string.Empty; Action action = info => { s = info; }; - Logger.SetLoggers(action, action, action); - - Logger.WriteInfo(string.Format("{0}://{1}:{2}@workspace.visualstudio.com/DefaultCollection/_git/CAS",protocol,username,password)); + using (Logger.AddLoggersTemporarily(action, action, action)) + Logger.WriteInfo(string.Format("{0}://{1}:{2}@workspace.visualstudio.com/DefaultCollection/_git/CAS",protocol,username,password)); - Assert.IsFalse(s.Contains(password)); + s.Contains(password).ShouldBe(false); } [Test] @@ -27,13 +28,11 @@ public void UsernameWithoutPassword() { var s = string.Empty; Action action = info => { s = info; }; - Logger.SetLoggers(action, action, action); - const string repoUrl = "http://username@workspace.visualstudio.com/DefaultCollection/_git/CAS"; - Logger.WriteInfo(repoUrl); + using (Logger.AddLoggersTemporarily(action, action, action)) + Logger.WriteInfo(repoUrl); - Assert.IsTrue(s.Contains(repoUrl)); + s.Contains(repoUrl).ShouldBe(true); } - } } diff --git a/src/GitVersionCore.Tests/ModuleInitializer.cs b/src/GitVersionCore.Tests/ModuleInitializer.cs index bd68e2c3b8..7ac7219ac2 100644 --- a/src/GitVersionCore.Tests/ModuleInitializer.cs +++ b/src/GitVersionCore.Tests/ModuleInitializer.cs @@ -1,5 +1,5 @@ -using System.Diagnostics; -using GitVersion; +using GitVersion; +using System; /// /// Used by the ModuleInit. All code inside the Initialize method is ran as soon as the assembly is loaded. @@ -11,6 +11,9 @@ public static class ModuleInitializer /// public static void Initialize() { - Logger.SetLoggers(s => Trace.WriteLine(s), s => Trace.WriteLine(s), s => Trace.WriteLine(s)); + Logger.SetLoggers( + s => Console.WriteLine(s), + s => Console.WriteLine(s), + s => Console.WriteLine(s)); } } diff --git a/src/GitVersionCore.Tests/TestEffectiveConfiguration.cs b/src/GitVersionCore.Tests/TestEffectiveConfiguration.cs index 1d445f77d7..d4412cca0d 100644 --- a/src/GitVersionCore.Tests/TestEffectiveConfiguration.cs +++ b/src/GitVersionCore.Tests/TestEffectiveConfiguration.cs @@ -26,14 +26,16 @@ public TestEffectiveConfiguration( int legacySemVerPadding = 4, int buildMetaDataPadding = 4, int commitsSinceVersionSourcePadding = 4, - IEnumerable versionFilters = null - ) : + IEnumerable versionFilters = null, + bool isDevelop = false, + bool isRelease = false) : base(assemblyVersioningScheme, assemblyInformationalFormat, versioningMode, gitTagPrefix, tag, nextVersion, IncrementStrategy.Patch, branchPrefixToTrim, preventIncrementForMergedBranchVersion, tagNumberPattern, continuousDeploymentFallbackTag, trackMergeTarget, majorMessage, minorMessage, patchMessage, commitMessageMode, legacySemVerPadding, buildMetaDataPadding, commitsSinceVersionSourcePadding, - versionFilters ?? Enumerable.Empty()) + versionFilters ?? Enumerable.Empty(), + isDevelop, isRelease) { } } diff --git a/src/GitVersionCore.Tests/VersionCalculation/NextVersionCalculatorTests.cs b/src/GitVersionCore.Tests/VersionCalculation/NextVersionCalculatorTests.cs index 3c015d5a7f..a236d4e517 100644 --- a/src/GitVersionCore.Tests/VersionCalculation/NextVersionCalculatorTests.cs +++ b/src/GitVersionCore.Tests/VersionCalculation/NextVersionCalculatorTests.cs @@ -52,7 +52,7 @@ public void AppliesBranchPreReleaseTag() var version = sut.FindVersion(context); - version.ToString("f").ShouldBe("1.0.0-unstable.1+2"); + version.ToString("f").ShouldBe("1.0.0-alpha.1+2"); } [Test] diff --git a/src/GitVersionCore/BranchConfigurationCalculator.cs b/src/GitVersionCore/BranchConfigurationCalculator.cs index f6dbea9481..957c9ab0a8 100644 --- a/src/GitVersionCore/BranchConfigurationCalculator.cs +++ b/src/GitVersionCore/BranchConfigurationCalculator.cs @@ -114,7 +114,9 @@ static KeyValuePair InheritBranchConfiguration(bool onlyEv new BranchConfig(branchConfiguration) { Increment = branchConfig.Increment, - PreventIncrementOfMergedBranchVersion = branchConfig.PreventIncrementOfMergedBranchVersion + PreventIncrementOfMergedBranchVersion = branchConfig.PreventIncrementOfMergedBranchVersion, + // If we are inheriting from develop then we should behave like develop + IsDevelop = branchConfig.IsDevelop }); } @@ -134,13 +136,15 @@ static KeyValuePair InheritBranchConfiguration(bool onlyEv var branchName = chosenBranch.FriendlyName; Logger.WriteWarning(errorMessage + Environment.NewLine + Environment.NewLine + "Falling back to " + branchName + " branch config"); - var value = GetBranchConfiguration(currentCommit, repository, onlyEvaluateTrackedBranches, config, chosenBranch).Value; + var inheritingBranchConfig = GetBranchConfiguration(currentCommit, repository, onlyEvaluateTrackedBranches, config, chosenBranch).Value; return new KeyValuePair( keyValuePair.Key, new BranchConfig(branchConfiguration) { - Increment = value.Increment, - PreventIncrementOfMergedBranchVersion = value.PreventIncrementOfMergedBranchVersion + 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 821a413811..9c52e440b4 100644 --- a/src/GitVersionCore/Configuration/BranchConfig.cs +++ b/src/GitVersionCore/Configuration/BranchConfig.cs @@ -17,6 +17,8 @@ public BranchConfig(BranchConfig branchConfiguration) TagNumberPattern = branchConfiguration.TagNumberPattern; TrackMergeTarget = branchConfiguration.TrackMergeTarget; CommitMessageIncrementing = branchConfiguration.CommitMessageIncrementing; + IsDevelop = branchConfiguration.IsDevelop; + IsReleaseBranch = branchConfiguration.IsReleaseBranch; } [YamlMember(Alias = "mode")] @@ -42,5 +44,11 @@ public BranchConfig(BranchConfig branchConfiguration) [YamlMember(Alias = "commit-message-incrementing")] public CommitMessageIncrementMode? CommitMessageIncrementing { get; set; } + + [YamlMember(Alias = "is-develop")] + public bool? IsDevelop { get; set; } + + [YamlMember(Alias = "is-release-branch")] + public bool? IsReleaseBranch { get; set; } } } diff --git a/src/GitVersionCore/Configuration/ConfigurationProvider.cs b/src/GitVersionCore/Configuration/ConfigurationProvider.cs index 2241308c4b..4e799db8e9 100644 --- a/src/GitVersionCore/Configuration/ConfigurationProvider.cs +++ b/src/GitVersionCore/Configuration/ConfigurationProvider.cs @@ -70,7 +70,7 @@ public static void ApplyDefaultsTo(Config config) var configBranches = config.Branches.ToList(); ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "master"), defaultTag: string.Empty, defaultPreventIncrement: true); - ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "releases?[/-]"), defaultTag: "beta", defaultPreventIncrement: true); + ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "releases?[/-]"), defaultTag: "beta", defaultPreventIncrement: true, isReleaseBranch: true); ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "features?[/-]"), defaultIncrementStrategy: IncrementStrategy.Inherit); ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, @"(pull|pull\-requests|pr)[/-]"), defaultTag: "PullRequest", @@ -79,10 +79,11 @@ public static void ApplyDefaultsTo(Config config) ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "hotfix(es)?[/-]"), defaultTag: "beta"); ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "support[/-]"), defaultTag: string.Empty, defaultPreventIncrement: true); ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, "dev(elop)?(ment)?$"), - defaultTag: "unstable", + defaultTag: "alpha", defaultIncrementStrategy: IncrementStrategy.Minor, defaultVersioningMode: VersioningMode.ContinuousDeployment, - defaultTrackMergeTarget: true); + 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 @@ -140,7 +141,9 @@ public static void ApplyBranchDefaults(Config config, bool defaultPreventIncrement = false, VersioningMode? defaultVersioningMode = null, // Looked up from main config bool defaultTrackMergeTarget = false, - string defaultTagNumberPattern = null) + string defaultTagNumberPattern = null, + bool isDevelop = false, + bool isReleaseBranch = false) { branchConfig.Tag = branchConfig.Tag ?? defaultTag; branchConfig.TagNumberPattern = branchConfig.TagNumberPattern ?? defaultTagNumberPattern; @@ -148,6 +151,8 @@ public static void ApplyBranchDefaults(Config config, branchConfig.PreventIncrementOfMergedBranchVersion = branchConfig.PreventIncrementOfMergedBranchVersion ?? defaultPreventIncrement; branchConfig.TrackMergeTarget = branchConfig.TrackMergeTarget ?? defaultTrackMergeTarget; branchConfig.VersioningMode = branchConfig.VersioningMode ?? defaultVersioningMode ?? config.VersioningMode; + branchConfig.IsDevelop = branchConfig.IsDevelop ?? isDevelop; + branchConfig.IsReleaseBranch = branchConfig.IsReleaseBranch ?? isReleaseBranch; } static Config ReadConfig(string workingDirectory, IFileSystem fileSystem) diff --git a/src/GitVersionCore/EffectiveConfiguration.cs b/src/GitVersionCore/EffectiveConfiguration.cs index 3f99ca0fa8..6341cb49d2 100644 --- a/src/GitVersionCore/EffectiveConfiguration.cs +++ b/src/GitVersionCore/EffectiveConfiguration.cs @@ -25,8 +25,9 @@ public EffectiveConfiguration( int legacySemVerPaddding, int buildMetaDataPadding, int commitsSinceVersionSourcePadding, - IEnumerable versionFilters - ) + IEnumerable versionFilters, + bool isCurrentBranchDevelop, + bool isCurrentBranchRelease) { AssemblyVersioningScheme = assemblyVersioningScheme; AssemblyInformationalFormat = assemblyInformationalFormat; @@ -48,8 +49,13 @@ IEnumerable versionFilters BuildMetaDataPadding = buildMetaDataPadding; CommitsSinceVersionSourcePadding = commitsSinceVersionSourcePadding; VersionFilters = versionFilters; + IsCurrentBranchDevelop = isCurrentBranchDevelop; + IsCurrentBranchRelease = isCurrentBranchRelease; } + public bool IsCurrentBranchDevelop { get; private set; } + public bool IsCurrentBranchRelease { get; private set; } + public VersioningMode VersioningMode { get; private set; } public AssemblyVersioningScheme AssemblyVersioningScheme { get; private set; } diff --git a/src/GitVersionCore/GitVersionContext.cs b/src/GitVersionCore/GitVersionContext.cs index d9c7533c6a..b600769b80 100644 --- a/src/GitVersionCore/GitVersionContext.cs +++ b/src/GitVersionCore/GitVersionContext.cs @@ -9,8 +9,6 @@ /// public class GitVersionContext { - readonly Config configuration; - public GitVersionContext(IRepository repository, Config configuration, bool isForTrackingBranchOnly = true, string commitId = null) : this(repository, repository.Head, configuration, isForTrackingBranchOnly, commitId) { @@ -19,7 +17,7 @@ public GitVersionContext(IRepository repository, Config configuration, bool isFo public GitVersionContext(IRepository repository, Branch currentBranch, Config configuration, bool onlyEvaluateTrackedBranches = true, string commitId = null) { Repository = repository; - this.configuration = configuration; + FullConfiguration = configuration; OnlyEvaluateTrackedBranches = onlyEvaluateTrackedBranches; if (currentBranch == null) @@ -69,9 +67,15 @@ public GitVersionContext(IRepository repository, Branch currentBranch, Config co IsCurrentCommitTagged = CurrentCommitTaggedVersion != null; } + /// + /// Contains the raw configuration, use Configuration for specific config based on the current GitVersion context. + /// + public Config FullConfiguration { get; private set; } + public SemanticVersion CurrentCommitTaggedVersion { get; private set; } public bool OnlyEvaluateTrackedBranches { get; private set; } public EffectiveConfiguration Configuration { get; private set; } + public IRepository Repository { get; private set; } public Branch CurrentBranch { get; private set; } public Commit CurrentCommit { get; private set; } @@ -79,7 +83,7 @@ public GitVersionContext(IRepository repository, Branch currentBranch, Config co void CalculateEffectiveConfiguration() { - var currentBranchConfig = BranchConfigurationCalculator.GetBranchConfiguration(CurrentCommit, Repository, OnlyEvaluateTrackedBranches, configuration, CurrentBranch); + var currentBranchConfig = BranchConfigurationCalculator.GetBranchConfiguration(CurrentCommit, Repository, OnlyEvaluateTrackedBranches, FullConfiguration, CurrentBranch); if (!currentBranchConfig.Value.VersioningMode.HasValue) throw new Exception(string.Format("Configuration value for 'Versioning mode' for branch {0} has no value. (this should not happen, please report an issue)", currentBranchConfig.Key)); @@ -89,10 +93,21 @@ void CalculateEffectiveConfiguration() throw new Exception(string.Format("Configuration value for 'PreventIncrementOfMergedBranchVersion' for branch {0} has no value. (this should not happen, please report an issue)", currentBranchConfig.Key)); if (!currentBranchConfig.Value.TrackMergeTarget.HasValue) throw new Exception(string.Format("Configuration value for 'TrackMergeTarget' for branch {0} has no value. (this should not happen, please report an issue)", currentBranchConfig.Key)); - if (!configuration.AssemblyVersioningScheme.HasValue) + if (!currentBranchConfig.Value.IsDevelop.HasValue) + throw new Exception(string.Format("Configuration value for 'IsDevelop' for branch {0} has no value. (this should not happen, please report an issue)", currentBranchConfig.Key)); + if (!currentBranchConfig.Value.IsReleaseBranch.HasValue) + throw new Exception(string.Format("Configuration value for 'IsReleaseBranch' for branch {0} has no value. (this should not happen, please report an issue)", currentBranchConfig.Key)); + + if (!FullConfiguration.AssemblyVersioningScheme.HasValue) throw new Exception("Configuration value for 'AssemblyVersioningScheme' has no value. (this should not happen, please report an issue)"); - if (!configuration.CommitMessageIncrementing.HasValue) + if (!FullConfiguration.CommitMessageIncrementing.HasValue) throw new Exception("Configuration value for 'CommitMessageIncrementing' has no value. (this should not happen, please report an issue)"); + if (!FullConfiguration.LegacySemVerPadding.HasValue) + throw new Exception("Configuration value for 'LegacySemVerPadding' has no value. (this should not happen, please report an issue)"); + if (!FullConfiguration.BuildMetaDataPadding.HasValue) + throw new Exception("Configuration value for 'BuildMetaDataPadding' has no value. (this should not happen, please report an issue)"); + if (!FullConfiguration.CommitsSinceVersionSourcePadding.HasValue) + throw new Exception("Configuration value for 'CommitsSinceVersionSourcePadding' has no value. (this should not happen, please report an issue)"); var versioningMode = currentBranchConfig.Value.VersioningMode.Value; var tag = currentBranchConfig.Value.Tag; @@ -101,29 +116,30 @@ void CalculateEffectiveConfiguration() var preventIncrementForMergedBranchVersion = currentBranchConfig.Value.PreventIncrementOfMergedBranchVersion.Value; var trackMergeTarget = currentBranchConfig.Value.TrackMergeTarget.Value; - var nextVersion = configuration.NextVersion; - var assemblyVersioningScheme = configuration.AssemblyVersioningScheme.Value; - var assemblyInformationalFormat = configuration.AssemblyInformationalFormat; - var gitTagPrefix = configuration.TagPrefix; - var majorMessage = configuration.MajorVersionBumpMessage; - var minorMessage = configuration.MinorVersionBumpMessage; - var patchMessage = configuration.PatchVersionBumpMessage; + var nextVersion = FullConfiguration.NextVersion; + var assemblyVersioningScheme = FullConfiguration.AssemblyVersioningScheme.Value; + var assemblyInformationalFormat = FullConfiguration.AssemblyInformationalFormat; + var gitTagPrefix = FullConfiguration.TagPrefix; + var majorMessage = FullConfiguration.MajorVersionBumpMessage; + var minorMessage = FullConfiguration.MinorVersionBumpMessage; + var patchMessage = FullConfiguration.PatchVersionBumpMessage; - var commitMessageVersionBump = currentBranchConfig.Value.CommitMessageIncrementing ?? configuration.CommitMessageIncrementing.Value; + var commitMessageVersionBump = currentBranchConfig.Value.CommitMessageIncrementing ?? FullConfiguration.CommitMessageIncrementing.Value; Configuration = new EffectiveConfiguration( assemblyVersioningScheme, assemblyInformationalFormat, versioningMode, gitTagPrefix, tag, nextVersion, incrementStrategy, currentBranchConfig.Key, preventIncrementForMergedBranchVersion, - tagNumberPattern, configuration.ContinuousDeploymentFallbackTag, + tagNumberPattern, FullConfiguration.ContinuousDeploymentFallbackTag, trackMergeTarget, majorMessage, minorMessage, patchMessage, commitMessageVersionBump, - configuration.LegacySemVerPadding.Value, - configuration.BuildMetaDataPadding.Value, - configuration.CommitsSinceVersionSourcePadding.Value, - configuration.Ignore.ToFilters() - ); + FullConfiguration.LegacySemVerPadding.Value, + FullConfiguration.BuildMetaDataPadding.Value, + FullConfiguration.CommitsSinceVersionSourcePadding.Value, + FullConfiguration.Ignore.ToFilters(), + currentBranchConfig.Value.IsDevelop.Value, + currentBranchConfig.Value.IsReleaseBranch.Value); } } } diff --git a/src/GitVersionCore/GitVersionCore.csproj b/src/GitVersionCore/GitVersionCore.csproj index 42b7adbf28..0208ef28f3 100644 --- a/src/GitVersionCore/GitVersionCore.csproj +++ b/src/GitVersionCore/GitVersionCore.csproj @@ -141,11 +141,11 @@ - + diff --git a/src/GitVersionCore/LibGitExtensions.cs b/src/GitVersionCore/LibGitExtensions.cs index 48c7caa332..8ca8d666f5 100644 --- a/src/GitVersionCore/LibGitExtensions.cs +++ b/src/GitVersionCore/LibGitExtensions.cs @@ -62,44 +62,13 @@ public static Commit FindCommitBranchWasBranchedFrom([NotNull] this Branch branc return null; } - // Otherbranch tip is a forward merge - var commitToFindCommonBase = otherBranch.Tip; - if (otherBranch.Tip.Parents.Contains(branch.Tip)) - { - commitToFindCommonBase = otherBranch.Tip.Parents.First(); - } - - var findMergeBase = repository.ObjectDatabase.FindMergeBase(branch.Tip, commitToFindCommonBase); - if (findMergeBase != null) - { - using (Logger.IndentLog(string.Format("Found merge base of {0} against {1}", findMergeBase.Sha, otherBranch.FriendlyName))) - { - // We do not want to include merge base commits which got forward merged into the other branch - bool mergeBaseWasFowardMerge; - do - { - // Now make sure that the merge base is not a forward merge - mergeBaseWasFowardMerge = otherBranch.Commits - .SkipWhile(c => c != commitToFindCommonBase) - .TakeWhile(c => c != findMergeBase) - .Any(c => c.Parents.Contains(findMergeBase)); - if (mergeBaseWasFowardMerge) - { - Logger.WriteInfo("Merge base was due to a forward merge, moving to next merge base"); - var second = commitToFindCommonBase.Parents.First(); - var mergeBase = repository.ObjectDatabase.FindMergeBase(branch.Tip, second); - if (mergeBase == findMergeBase) break; - findMergeBase = mergeBase; - } - } while (mergeBaseWasFowardMerge); - } - } + var findMergeBase = FindMergeBase(branch, otherBranch, repository); return new { mergeBaseCommit = findMergeBase, branch = otherBranch }; - }).Where(b => b != null && b.mergeBaseCommit != null).OrderByDescending(b => b.mergeBaseCommit.Committer.When).ToList(); + }).Where(b => b != null).OrderByDescending(b => b.mergeBaseCommit.Committer.When).ToList(); var firstOrDefault = mergeBases.FirstOrDefault(); if (firstOrDefault != null) @@ -110,6 +79,47 @@ public static Commit FindCommitBranchWasBranchedFrom([NotNull] this Branch branc } } + 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))) + { + // Otherbranch tip is a forward merge + var commitToFindCommonBase = otherBranch.Tip; + if (otherBranch.Tip.Parents.Contains(branch.Tip)) + { + commitToFindCommonBase = otherBranch.Tip.Parents.First(); + } + + var findMergeBase = repository.ObjectDatabase.FindMergeBase(branch.Tip, commitToFindCommonBase); + if (findMergeBase != null) + { + Logger.WriteInfo(string.Format("Found merge base of {0} against {1}", findMergeBase.Sha, otherBranch.FriendlyName)); + // We do not want to include merge base commits which got forward merged into the other branch + bool mergeBaseWasFowardMerge; + do + { + // Now make sure that the merge base is not a forward merge + mergeBaseWasFowardMerge = otherBranch.Commits + .SkipWhile(c => c != commitToFindCommonBase) + .TakeWhile(c => c != findMergeBase) + .Any(c => c.Parents.Contains(findMergeBase)); + if (mergeBaseWasFowardMerge) + { + var second = commitToFindCommonBase.Parents.First(); + var mergeBase = repository.ObjectDatabase.FindMergeBase(branch.Tip, second); + if (mergeBase == findMergeBase) + { + break; + } + findMergeBase = mergeBase; + Logger.WriteInfo(string.Format("Merge base was due to a forward merge, next merge base is {0}", findMergeBase)); + } + } while (mergeBaseWasFowardMerge); + } + return findMergeBase; + } + } + static bool IsSameBranch(Branch branch, Branch b) { return (b.IsRemote ? diff --git a/src/GitVersionCore/Logger.cs b/src/GitVersionCore/Logger.cs index f3a1eddd3f..151edf7578 100644 --- a/src/GitVersionCore/Logger.cs +++ b/src/GitVersionCore/Logger.cs @@ -52,6 +52,32 @@ public static void SetLoggers(Action info, Action warn, Action info, Action warn, Action error) + { + var currentInfo = WriteInfo; + var currentWarn = WriteWarning; + var currentError = WriteError; + SetLoggers(s => { + info(s); + currentInfo(s); + }, s => + { + warn(s); + currentWarn(s); + }, s => + { + error(s); + currentError(s); + }); + + return new ActionDisposable(() => + { + WriteInfo = currentInfo; + WriteWarning = currentWarn; + WriteError = currentError; + }); + } + static Action LogMessage(Action logAction, string level) { return s => logAction(string.Format(CultureInfo.InvariantCulture, "{0}{1} [{2:MM/dd/yy H:mm:ss:ff}] {3}", indent, level, DateTime.Now, s)); diff --git a/src/GitVersionCore/VersionCalculation/BaseVersionCalculator.cs b/src/GitVersionCore/VersionCalculation/BaseVersionCalculator.cs index 80b1d1599d..e3b9c29275 100644 --- a/src/GitVersionCore/VersionCalculation/BaseVersionCalculator.cs +++ b/src/GitVersionCore/VersionCalculation/BaseVersionCalculator.cs @@ -46,7 +46,7 @@ public BaseVersion GetBaseVersion(GitVersionContext context) var maxVersion = baseVersions.Aggregate((v1, v2) => v1.IncrementedVersion > v2.IncrementedVersion ? v1 : v2); var matchingVersionsOnceIncremented = baseVersions - .Where(b => b != maxVersion && b.Version.BaseVersionSource != null && b.IncrementedVersion == maxVersion.IncrementedVersion) + .Where(b => b.Version.BaseVersionSource != null && b.IncrementedVersion == maxVersion.IncrementedVersion) .ToList(); BaseVersion baseVersionWithOldestSource; if (matchingVersionsOnceIncremented.Any()) diff --git a/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs b/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs index 0336ceedb5..eaea434d53 100644 --- a/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs +++ b/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs @@ -1,5 +1,6 @@ namespace GitVersion.VersionCalculation.BaseVersionCalculators { + using System; using System.Collections.Generic; using System.Linq; using LibGit2Sharp; @@ -8,16 +9,17 @@ public class TaggedCommitVersionStrategy : BaseVersionStrategy { public override IEnumerable GetVersions(GitVersionContext context) { - var olderThan = context.CurrentCommit.When(); + return GetTaggedVersions(context, context.CurrentBranch, context.CurrentCommit.When()); + } + + public IEnumerable GetTaggedVersions(GitVersionContext context, Branch currentBranch, DateTimeOffset? olderThan) + { var allTags = context.Repository.Tags - .Where(tag => ((Commit)tag.PeeledTarget()).When() <= olderThan) + .Where(tag => !olderThan.HasValue || ((Commit) tag.PeeledTarget()).When() <= olderThan.Value) .ToList(); - var tagsOnBranch = context.CurrentBranch + var tagsOnBranch = currentBranch .Commits - .SelectMany(commit => - { - return allTags.Where(t => IsValidTag(t, commit)); - }) + .SelectMany(commit => { return allTags.Where(t => IsValidTag(t, commit)); }) .Select(t => { SemanticVersion version; diff --git a/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TrackMergeTargetBaseVersionStrategy.cs b/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TrackMergeTargetBaseVersionStrategy.cs deleted file mode 100644 index 79141e83bf..0000000000 --- a/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TrackMergeTargetBaseVersionStrategy.cs +++ /dev/null @@ -1,62 +0,0 @@ -namespace GitVersion.VersionCalculation.BaseVersionCalculators -{ - using System; - using System.Collections.Generic; - using System.Linq; - using LibGit2Sharp; - - public class TrackMergeTargetBaseVersionStrategy : TaggedCommitVersionStrategy - { - public override IEnumerable GetVersions(GitVersionContext context) - { - if(!context.Configuration.TrackMergeTarget) - { - yield break; - } - - string currentBranchName = null; - var head = context.Repository.Head; - if (head != null) - { - currentBranchName = head.CanonicalName; - } - - if (string.IsNullOrWhiteSpace(currentBranchName)) - { - yield break; - } - - foreach (var version in base.GetVersions(context)) - { - yield return version; - } - } - - protected override bool IsValidTag(Tag tag, Commit commit) - { - return IsDirectMergeFromCommit(tag, commit); - } - - protected override string FormatSource(VersionTaggedCommit version) - { - return string.Format("Merge target tagged '{0}'", version.Tag); - } - - static bool IsDirectMergeFromCommit(Tag tag, Commit commit) - { - var targetCommit = tag.Target as Commit; - if (targetCommit != null) - { - var parents = targetCommit.Parents; - if (parents != null) - { - return parents - .Where(parent => parent != null) - .Any(parent => string.Equals(parent.Id.Sha, commit.Id.Sha, StringComparison.OrdinalIgnoreCase)); - } - } - - return false; - } - } -} diff --git a/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/VersionInBranchBaseVersionStrategy.cs b/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/VersionInBranchBaseVersionStrategy.cs index d59e14c4dd..8e0bcc7470 100644 --- a/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/VersionInBranchBaseVersionStrategy.cs +++ b/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/VersionInBranchBaseVersionStrategy.cs @@ -2,27 +2,37 @@ { using System; using System.Collections.Generic; + using LibGit2Sharp; public class VersionInBranchBaseVersionStrategy : BaseVersionStrategy { public override IEnumerable GetVersions(GitVersionContext context) { - var versionInBranch = GetVersionInBranch(context); + var currentBranch = context.CurrentBranch; + var tagPrefixRegex = context.Configuration.GitTagPrefix; + var repository = context.Repository; + return GetVersions(tagPrefixRegex, currentBranch, repository); + } + + public IEnumerable GetVersions(string tagPrefixRegex, Branch currentBranch, IRepository repository) + { + var branchName = currentBranch.FriendlyName; + var versionInBranch = GetVersionInBranch(branchName, tagPrefixRegex); if (versionInBranch != null) { - var commitBranchWasBranchedFrom = context.CurrentBranch.FindCommitBranchWasBranchedFrom(context.Repository); - var branchNameOverride = context.CurrentBranch.FriendlyName.RegexReplace("[-/]" + versionInBranch.Item1, string.Empty); + var commitBranchWasBranchedFrom = currentBranch.FindCommitBranchWasBranchedFrom(repository); + var branchNameOverride = branchName.RegexReplace("[-/]" + versionInBranch.Item1, string.Empty); yield return new BaseVersion("Version in branch name", false, versionInBranch.Item2, commitBranchWasBranchedFrom, branchNameOverride); } } - Tuple GetVersionInBranch(GitVersionContext context) + Tuple GetVersionInBranch(string branchName, string tagPrefixRegex) { - var branchParts = context.CurrentBranch.FriendlyName.Split('/', '-'); + var branchParts = branchName.Split('/', '-'); foreach (var part in branchParts) { SemanticVersion semanticVersion; - if (SemanticVersion.TryParse(part, context.Configuration.GitTagPrefix, out semanticVersion)) + if (SemanticVersion.TryParse(part, tagPrefixRegex, out semanticVersion)) { return Tuple.Create(part, semanticVersion); } diff --git a/src/GitVersionCore/VersionCalculation/DevelopVersionStrategy.cs b/src/GitVersionCore/VersionCalculation/DevelopVersionStrategy.cs new file mode 100644 index 0000000000..b74459f6d0 --- /dev/null +++ b/src/GitVersionCore/VersionCalculation/DevelopVersionStrategy.cs @@ -0,0 +1,77 @@ +namespace GitVersion.VersionCalculation +{ + using System.Collections.Generic; + using System.Linq; + using System.Text.RegularExpressions; + using BaseVersionCalculators; + using GitTools; + using LibGit2Sharp; + + /// + /// Inherit version from release branch and tags on master + /// + public class DevelopVersionStrategy : BaseVersionStrategy + { + VersionInBranchBaseVersionStrategy releaseVersionStrategy = new VersionInBranchBaseVersionStrategy(); + TaggedCommitVersionStrategy taggedCommitVersionStrategy = new TaggedCommitVersionStrategy(); + + public override IEnumerable GetVersions(GitVersionContext context) + { + if (context.Configuration.IsCurrentBranchDevelop) + { + return ReleaseBranchBaseVersions(context).Union(MasterTagsVersions(context)); + } + + return new BaseVersion[0]; + } + + private IEnumerable MasterTagsVersions(GitVersionContext context) + { + var master = context.Repository.FindBranch("master"); + if (master != null) + { + return taggedCommitVersionStrategy.GetTaggedVersions(context, master, null); + } + + return new BaseVersion[0]; + } + + private IEnumerable ReleaseBranchBaseVersions(GitVersionContext context) + { + var releaseBranchConfig = context.FullConfiguration.Branches + .Where(b => b.Value.IsReleaseBranch == true) + .ToList(); + if (releaseBranchConfig.Any()) + { + var releaseBranches = context.Repository.Branches + .Where(b => releaseBranchConfig.Any(c => Regex.IsMatch(b.FriendlyName, c.Key))); + + return releaseBranches + .SelectMany(b => GetReleaseVersion(context, b)) + .Select(baseVersion => + { + // Need to drop branch overrides and give a bit more context about + // where this version came from + var source1 = "Release branch exists -> " + baseVersion.Source; + return new BaseVersion(source1, + baseVersion.ShouldIncrement, + baseVersion.SemanticVersion, + baseVersion.BaseVersionSource, + null); + }) + .ToList(); + } + return new BaseVersion[0]; + } + + IEnumerable GetReleaseVersion(GitVersionContext context, Branch releaseBranch) + { + var tagPrefixRegex = context.Configuration.GitTagPrefix; + var repository = context.Repository; + var baseSource = releaseBranch.FindMergeBase(context.CurrentBranch, repository); + return releaseVersionStrategy + .GetVersions(tagPrefixRegex, releaseBranch, repository) + .Select(b => new BaseVersion(b.Source, true, b.SemanticVersion, baseSource, b.BranchNameOverride)); + } + } +} \ No newline at end of file diff --git a/src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs b/src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs index 2b4bf6183c..930f76a600 100644 --- a/src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs +++ b/src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs @@ -17,14 +17,13 @@ public NextVersionCalculator(IBaseVersionCalculator baseVersionCalculator = null new FallbackBaseVersionStrategy(), new ConfigNextVersionBaseVersionStrategy(), new TaggedCommitVersionStrategy(), - new TrackMergeTargetBaseVersionStrategy(), new MergeMessageBaseVersionStrategy(), - new VersionInBranchBaseVersionStrategy()); + new VersionInBranchBaseVersionStrategy(), + new DevelopVersionStrategy()); } public SemanticVersion FindVersion(GitVersionContext context) { - SemanticVersion taggedSemanticVersion = null; // If current commit is tagged, don't do anything except add build metadata if (context.IsCurrentCommitTagged) @@ -33,8 +32,6 @@ public SemanticVersion FindVersion(GitVersionContext context) var semanticVersionBuildMetaData = metaDataCalculator.Create(context.CurrentCommit, context); semanticVersionBuildMetaData.CommitsSinceTag = null; - - var semanticVersion = new SemanticVersion(context.CurrentCommitTaggedVersion) { BuildMetaData = semanticVersionBuildMetaData diff --git a/src/GitVersionExe.Tests/AssemblyInfoFileUpdateTests.cs b/src/GitVersionExe.Tests/AssemblyInfoFileUpdateTests.cs index 0a0b2e6ad6..9dea96aeaf 100644 --- a/src/GitVersionExe.Tests/AssemblyInfoFileUpdateTests.cs +++ b/src/GitVersionExe.Tests/AssemblyInfoFileUpdateTests.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; using GitVersion; @@ -17,7 +16,6 @@ public class AssemblyInfoFileUpdateTests public void SetLoggers() { ShouldlyConfiguration.ShouldMatchApprovedDefaults.LocateTestMethodUsingAttribute(); - Logger.SetLoggers(m => Debug.WriteLine(m), m => Debug.WriteLine(m), m => Debug.WriteLine(m)); } [TestCase("cs")]