diff --git a/GitVersionCore.Tests/Fixtures/BaseGitFlowRepositoryFixture.cs b/GitVersionCore.Tests/Fixtures/BaseGitFlowRepositoryFixture.cs index ad7b5f43d7..8c16dffaee 100644 --- a/GitVersionCore.Tests/Fixtures/BaseGitFlowRepositoryFixture.cs +++ b/GitVersionCore.Tests/Fixtures/BaseGitFlowRepositoryFixture.cs @@ -1,15 +1,30 @@ using System; using System.IO; +using System.Text; using GitVersion; +using GitVersion.Helpers; using LibGit2Sharp; +/// +/// Creates a repo with a develop branch off master which is a single commit ahead of master +/// public class BaseGitFlowRepositoryFixture : EmptyRepositoryFixture { + /// + /// Creates a repo with a develop branch off master which is a single commit ahead of master + /// + /// Master will be tagged with the initial version before branching develop + /// public BaseGitFlowRepositoryFixture(string initialVersion) : base(new Config()) { SetupRepo(r => r.MakeATaggedCommit(initialVersion)); } + /// + /// Creates a repo with a develop branch off master which is a single commit ahead of master + /// + /// The initial setup actions will be performed before branching develop + /// public BaseGitFlowRepositoryFixture(Action initialMasterAction) : base(new Config()) { SetupRepo(initialMasterAction); @@ -24,5 +39,21 @@ void SetupRepo(Action initialMasterAction) initialMasterAction(Repository); Repository.CreateBranch("develop").Checkout(); + Repository.MakeACommit(); + } + + public void DumpGraph() + { + var output = new StringBuilder(); + + ProcessHelper.Run( + o => output.AppendLine(o), + e => output.AppendLineFormat("ERROR: {0}", e), + null, + "git", + @"log --graph --abbrev-commit --decorate --date=relative --all", + RepositoryPath); + + Console.Write(output.ToString()); } } \ No newline at end of file diff --git a/GitVersionCore.Tests/IntegrationTests/GitFlow/PatchScenarios.cs b/GitVersionCore.Tests/IntegrationTests/GitFlow/PatchScenarios.cs index e17fc1e37f..a2146c5c21 100644 --- a/GitVersionCore.Tests/IntegrationTests/GitFlow/PatchScenarios.cs +++ b/GitVersionCore.Tests/IntegrationTests/GitFlow/PatchScenarios.cs @@ -1,5 +1,4 @@ using System.Linq; -using System.Threading; using LibGit2Sharp; using NUnit.Framework; @@ -14,13 +13,13 @@ public void PatchLatestReleaseExample() // create hotfix fixture.Repository.CreateBranch("hotfix-1.2.1").Checkout(); - fixture.AssertFullSemver("1.2.1-beta.1+0"); - fixture.Repository.MakeACommit(); fixture.AssertFullSemver("1.2.1-beta.1+1"); + fixture.Repository.MakeACommit(); + fixture.AssertFullSemver("1.2.1-beta.1+2"); fixture.Repository.ApplyTag("1.2.1-beta.1"); - fixture.AssertFullSemver("1.2.1-beta.1+1"); + fixture.AssertFullSemver("1.2.1-beta.1+2"); fixture.Repository.MakeACommit(); - fixture.AssertFullSemver("1.2.1-beta.2+2"); + fixture.AssertFullSemver("1.2.1-beta.2+3"); // Merge hotfix branch to master fixture.Repository.Checkout("master"); @@ -36,14 +35,7 @@ public void PatchLatestReleaseExample() fixture.Repository.Checkout("develop"); fixture.AssertFullSemver("1.3.0-unstable.0+0"); - // Warning: Hack-ish hack - // - // Ensure the merge commit is done at a different time than the previous one - // Otherwise, as they would have the same content and signature, the same sha would be generated. - // Thus 'develop' and 'master' would point at the same exact commit and the Assert below would fail. - Thread.Sleep(1000); fixture.Repository.MergeNoFF("hotfix-1.2.1", Constants.SignatureNow()); - fixture.AssertFullSemver("1.3.0-unstable.1+1"); } } @@ -58,7 +50,6 @@ public void PatchOlderReleaseExample() r.MakeATaggedCommit("1.2.0"); })) { - // create hotfix branch fixture.Repository.CreateBranch("hotfix-1.1.1", (Commit) fixture.Repository.Tags.Single(t => t.Name == "1.1.0").Target).Checkout(); @@ -78,7 +69,7 @@ public void PatchOlderReleaseExample() // Verify develop version fixture.Repository.Checkout("develop"); - fixture.AssertFullSemver("1.3.0-unstable.0+0"); + fixture.AssertFullSemver("1.3.0-unstable.1+1"); } } } \ No newline at end of file diff --git a/GitVersionCore.Tests/IntegrationTests/GitFlow/SupportBranchScenarios.cs b/GitVersionCore.Tests/IntegrationTests/GitFlow/SupportBranchScenarios.cs index c195278fde..2a773297a7 100644 --- a/GitVersionCore.Tests/IntegrationTests/GitFlow/SupportBranchScenarios.cs +++ b/GitVersionCore.Tests/IntegrationTests/GitFlow/SupportBranchScenarios.cs @@ -10,18 +10,18 @@ public class SupportBranchScenarios public void SupportIsCalculatedCorrectly() { using (var fixture = new BaseGitFlowRepositoryFixture("1.1.0")) - { + { // Create 2.0.0 release fixture.Repository.CreateBranch("release-2.0.0").Checkout(); fixture.Repository.MakeCommits(2); - + // Merge into develop and master fixture.Repository.Checkout("master"); fixture.Repository.MergeNoFF("release-2.0.0"); fixture.Repository.ApplyTag("2.0.0"); fixture.Repository.Checkout("develop"); fixture.Repository.MergeNoFF("release-2.0.0"); - fixture.AssertFullSemver("2.1.0-unstable.0+0"); + fixture.AssertFullSemver("2.1.0-unstable.1+1"); // Now lets support 1.x release fixture.Repository.Checkout("1.1.0"); @@ -47,6 +47,6 @@ public void SupportIsCalculatedCorrectly() fixture.Repository.MergeNoFF("hotfix/1.2.1"); fixture.AssertFullSemver("1.2.1"); } - } + } } } \ No newline at end of file diff --git a/GitVersionCore/Configuration/Config.cs b/GitVersionCore/Configuration/Config.cs index 8c481fbe8a..a3cc136c48 100644 --- a/GitVersionCore/Configuration/Config.cs +++ b/GitVersionCore/Configuration/Config.cs @@ -17,6 +17,7 @@ public Config() AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch; TagPrefix = "[vV]"; Branches["release[/-]"] = new BranchConfig { Tag = "beta" }; + Branches["hotfix[/-]"] = new BranchConfig { Tag = "beta" }; Branches["develop"] = new BranchConfig { Tag = "unstable" }; VersioningMode = VersioningMode.ContinuousDelivery; Develop.VersioningMode = VersioningMode.ContinuousDeployment; diff --git a/GitVersionCore/GitFlow/BranchFinders/DevelopBasedVersionFinderBase.cs b/GitVersionCore/GitFlow/BranchFinders/DevelopBasedVersionFinderBase.cs index 02365cca81..fc52a919a0 100644 --- a/GitVersionCore/GitFlow/BranchFinders/DevelopBasedVersionFinderBase.cs +++ b/GitVersionCore/GitFlow/BranchFinders/DevelopBasedVersionFinderBase.cs @@ -9,7 +9,6 @@ protected SemanticVersion FindVersion( GitVersionContext context, BranchType branchType) { - context.CurrentBranchConfig = context.Configuration.Branches["develop"]; var ancestor = FindCommonAncestorWithDevelop(context.Repository, context.CurrentBranch, branchType); if (!IsThereAnyCommitOnTheBranch(context.Repository, context.CurrentBranch)) diff --git a/GitVersionCore/GitFlow/GitFlowVersionFinder.cs b/GitVersionCore/GitFlow/GitFlowVersionFinder.cs index cf31bf9cd3..9ba18ac429 100644 --- a/GitVersionCore/GitFlow/GitFlowVersionFinder.cs +++ b/GitVersionCore/GitFlow/GitFlowVersionFinder.cs @@ -11,19 +11,16 @@ public SemanticVersion FindVersion(GitVersionContext context) if (context.CurrentBranch.IsHotfix()) { - context.CurrentBranchConfig = context.Configuration.Branches["release[/-]"]; return new HotfixVersionFinder().FindVersion(context); } if (context.CurrentBranch.IsRelease()) { - context.CurrentBranchConfig = context.Configuration.Branches["release[/-]"]; return new ReleaseVersionFinder().FindVersion(context); } if (context.CurrentBranch.IsDevelop()) { - context.CurrentBranchConfig = context.Configuration.Branches["develop"]; return new DevelopVersionFinder().FindVersion(context); } diff --git a/GitVersionCore/GitVersionContext.cs b/GitVersionCore/GitVersionContext.cs index a76f400261..d0fbfcf3e9 100644 --- a/GitVersionCore/GitVersionContext.cs +++ b/GitVersionCore/GitVersionContext.cs @@ -1,7 +1,9 @@ namespace GitVersion { + using System; using System.Collections.Generic; using System.Linq; + using System.Text.RegularExpressions; using LibGit2Sharp; /// @@ -9,6 +11,8 @@ /// public class GitVersionContext { + readonly bool IsContextForTrackedBranchesOnly; + public GitVersionContext(IRepository repository, Config configuration, bool isForTrackingBranchOnly = true) : this(repository, repository.Head, configuration, isForTrackingBranchOnly) { @@ -34,6 +38,8 @@ public GitVersionContext(IRepository repository, Branch currentBranch, Config co { CurrentBranch = currentBranch; } + + AssignBranchConfiguration(); } public Config Configuration { get; private set; } @@ -41,9 +47,7 @@ public GitVersionContext(IRepository repository, Branch currentBranch, Config co public Branch CurrentBranch { get; private set; } public Commit CurrentCommit { get; private set; } - public BranchConfig CurrentBranchConfig { get; set; } - - readonly bool IsContextForTrackedBranchesOnly = true; + public BranchConfig CurrentBranchConfig { get; private set; } IEnumerable GetBranchesContainingCommit(string commitSha) @@ -77,5 +81,24 @@ IEnumerable GetBranchesContainingCommit(string commitSha) yield return branch; } } + + void AssignBranchConfiguration() + { + var matchingBranches = Configuration.Branches.Where(b => Regex.IsMatch("^" + CurrentBranch.Name, b.Key)).ToArray(); + + if (matchingBranches.Length == 0) + { + CurrentBranchConfig = new BranchConfig(); + } + else if (matchingBranches.Length == 1) + { + CurrentBranchConfig = matchingBranches[0].Value; + } + else + { + const string format = "Multiple branch configurations match the current branch name of '{0}'. Matching configurations: '{1}'"; + throw new Exception(string.Format(format, CurrentBranch.Name, string.Join(", ", matchingBranches.Select(b => b.Key)))); + } + } } } \ No newline at end of file diff --git a/GitVersionCore/GitVersionCore.csproj b/GitVersionCore/GitVersionCore.csproj index 1ad027dc05..844bc72d74 100644 --- a/GitVersionCore/GitVersionCore.csproj +++ b/GitVersionCore/GitVersionCore.csproj @@ -78,6 +78,7 @@ + diff --git a/GitVersionExe/ProcessHelper.cs b/GitVersionCore/Helpers/ProcessHelper.cs similarity index 98% rename from GitVersionExe/ProcessHelper.cs rename to GitVersionCore/Helpers/ProcessHelper.cs index 77822bff81..9d1a231c3e 100644 --- a/GitVersionExe/ProcessHelper.cs +++ b/GitVersionCore/Helpers/ProcessHelper.cs @@ -1,4 +1,4 @@ -namespace GitVersion +namespace GitVersion.Helpers { using System; using System.Collections.Generic; @@ -7,7 +7,7 @@ namespace GitVersion using System.Runtime.InteropServices; using System.Threading; - static class ProcessHelper + public static class ProcessHelper { static volatile object lockObject = new object(); diff --git a/GitVersionExe.Tests/GitVersionHelper.cs b/GitVersionExe.Tests/GitVersionHelper.cs index f48b5f0d86..1823f7dc3b 100644 --- a/GitVersionExe.Tests/GitVersionHelper.cs +++ b/GitVersionExe.Tests/GitVersionHelper.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Text; -using GitVersion; +using GitVersion.Helpers; using LibGit2Sharp; public static class GitVersionHelper diff --git a/GitVersionExe/GitVersionExe.csproj b/GitVersionExe/GitVersionExe.csproj index f80ec6a881..0b04ca2b72 100644 --- a/GitVersionExe/GitVersionExe.csproj +++ b/GitVersionExe/GitVersionExe.csproj @@ -57,7 +57,6 @@ -