diff --git a/build.cake b/build.cake index 5a96078c06..62ec1c3d25 100644 --- a/build.cake +++ b/build.cake @@ -47,6 +47,7 @@ void Build(string configuration, string nugetVersion, string semVersion, string } } +// This build task can be run to just build Task("DogfoodBuild") .IsDependentOn("NuGet-Package-Restore") .Does(() => @@ -92,7 +93,7 @@ Task("Build") }); Task("Run-NUnit-Tests") - .IsDependentOn("Build") + .IsDependentOn("DogfoodBuild") .Does(() => { var settings = new NUnit3Settings(); @@ -113,6 +114,7 @@ Task("Run-NUnit-Tests") }); Task("Zip-Files") + .IsDependentOn("Build") .IsDependentOn("Run-NUnit-Tests") .Does(() => { diff --git a/src/GitVersionCore.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs b/src/GitVersionCore.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs index 6890b1080f..8b259d9b52 100644 --- a/src/GitVersionCore.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs +++ b/src/GitVersionCore.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs @@ -58,6 +58,7 @@ public void ShouldNotAllowIncrementOfVersion() [TestCase("Finish 0.14.1", true, "0.14.1")] //Support Syntevo SmartGit/Hg's Gitflow merge commit messages for finishing a 'Hotfix' branch [TestCase("Merge branch 'Release-v0.2.0'", true, "0.2.0")] [TestCase("Merge branch 'Release-v2.2'", true, "2.2.0")] + [TestCase("Merge remote-tracking branch 'origin/release/0.8.0' into develop/master", true, "0.8.0")] public void AssertMergeMessage(string message, bool isMergeCommit, string expectedVersion) { var parents = GetParents(isMergeCommit); @@ -121,6 +122,7 @@ static void AssertMergeMessage(string message, string expectedVersion, List public static BranchConfig GetBranchConfiguration(GitVersionContext context, Branch targetBranch, IList excludedInheritBranches = null) { - var matchingBranches = context.FullConfiguration.GetConfigForBranch(targetBranch.FriendlyName); + var matchingBranches = context.FullConfiguration.GetConfigForBranch(targetBranch.NameWithoutRemote()); if (matchingBranches == null) { @@ -27,11 +27,20 @@ public static BranchConfig GetBranchConfiguration(GitVersionContext context, Bra ConfigurationProvider.ApplyBranchDefaults(context.FullConfiguration, matchingBranches, "", new List()); } - return matchingBranches.Increment == IncrementStrategy.Inherit ? - InheritBranchConfiguration(context, targetBranch, matchingBranches, excludedInheritBranches) : - matchingBranches; + if (matchingBranches.Increment == IncrementStrategy.Inherit) + { + matchingBranches = InheritBranchConfiguration(context, targetBranch, matchingBranches, excludedInheritBranches); + if (matchingBranches.Name == FallbackConfigName && matchingBranches.Increment == IncrementStrategy.Inherit) + { + // We tried, and failed to inherit, just fall back to patch + matchingBranches.Increment = IncrementStrategy.Patch; + } + } + + return matchingBranches; } + // TODO I think we need to take a fresh approach to this.. it's getting really complex with heaps of edge cases static BranchConfig InheritBranchConfiguration(GitVersionContext context, Branch targetBranch, BranchConfig branchConfiguration, IList excludedInheritBranches) { var repository = context.Repository; @@ -50,9 +59,9 @@ static BranchConfig InheritBranchConfiguration(GitVersionContext context, Branch { excludedInheritBranches = repository.Branches.Where(b => { - var branchConfig = config.GetConfigForBranch(b.FriendlyName); + var branchConfig = config.GetConfigForBranch(b.NameWithoutRemote()); - return branchConfig != null && branchConfig.Increment == IncrementStrategy.Inherit; + return branchConfig == null || branchConfig.Increment == IncrementStrategy.Inherit; }).ToList(); } // Add new excluded branches. @@ -60,7 +69,7 @@ static BranchConfig InheritBranchConfiguration(GitVersionContext context, Branch { excludedInheritBranches.Add(excludedBranch); } - var branchesToEvaluate = repository.Branches.Except(excludedInheritBranches).ToList(); + var branchesToEvaluate = repository.Branches.ExcludingBranches(excludedInheritBranches).ToList(); var branchPoint = context.RepositoryMetadataProvider .FindCommitBranchWasBranchedFrom(targetBranch, excludedInheritBranches.ToArray()); @@ -94,13 +103,17 @@ static BranchConfig InheritBranchConfiguration(GitVersionContext context, Branch if (possibleParents.Count == 1) { var branchConfig = GetBranchConfiguration(context, possibleParents[0], excludedInheritBranches); - return new BranchConfig(branchConfiguration) + // If we have resolved a fallback config we should not return that we have got config + if (branchConfig.Name != FallbackConfigName) { - Increment = branchConfig.Increment, - PreventIncrementOfMergedBranchVersion = branchConfig.PreventIncrementOfMergedBranchVersion, - // If we are inheriting from develop then we should behave like develop - TracksReleaseBranches = branchConfig.TracksReleaseBranches - }; + return new BranchConfig(branchConfiguration) + { + Increment = branchConfig.Increment, + PreventIncrementOfMergedBranchVersion = branchConfig.PreventIncrementOfMergedBranchVersion, + // If we are inheriting from develop then we should behave like develop + TracksReleaseBranches = branchConfig.TracksReleaseBranches + }; + } } // If we fail to inherit it is probably because the branch has been merged and we can't do much. So we will fall back to develop's config diff --git a/src/GitVersionCore/GitRepoMetadataProvider.cs b/src/GitVersionCore/GitRepoMetadataProvider.cs index 9927ed899d..fcf4441e89 100644 --- a/src/GitVersionCore/GitRepoMetadataProvider.cs +++ b/src/GitVersionCore/GitRepoMetadataProvider.cs @@ -198,8 +198,7 @@ public BranchCommit FindCommitBranchWasBranchedFrom(Branch branch, params Branch return BranchCommit.Empty; } - var possibleBranches = GetMergeCommitsForBranch(branch) - .ExcludingBranches(excludedBranches) + var possibleBranches = GetMergeCommitsForBranch(branch, excludedBranches) .Where(b => !branch.IsSameBranch(b.Branch)) .ToList(); @@ -216,7 +215,7 @@ public BranchCommit FindCommitBranchWasBranchedFrom(Branch branch, params Branch } } - List GetMergeCommitsForBranch(Branch branch) + List GetMergeCommitsForBranch(Branch branch, Branch[] excludedBranches) { if (mergeBaseCommitsCache.ContainsKey(branch)) { @@ -226,11 +225,12 @@ List GetMergeCommitsForBranch(Branch branch) return mergeBaseCommitsCache[branch]; } - var currentBranchConfig = configuration.GetConfigForBranch(branch.FriendlyName); + var currentBranchConfig = configuration.GetConfigForBranch(branch.NameWithoutRemote()); var regexesToCheck = currentBranchConfig == null ? new [] { ".*" } // Match anything if we can't find a branch config : currentBranchConfig.SourceBranches.Select(sb => configuration.Branches[sb].Regex); var branchMergeBases = Repository.Branches + .ExcludingBranches(excludedBranches) .Where(b => { if (b == branch) return false; diff --git a/src/GitVersionCore/IncrementStrategyFinder.cs b/src/GitVersionCore/IncrementStrategyFinder.cs index 724fae89fe..f094d8195e 100644 --- a/src/GitVersionCore/IncrementStrategyFinder.cs +++ b/src/GitVersionCore/IncrementStrategyFinder.cs @@ -129,7 +129,7 @@ private static Regex CreateRegex(string pattern) public static VersionField FindDefaultIncrementForBranch( GitVersionContext context, string branch = null ) { - var config = context.FullConfiguration.GetConfigForBranch(branch ?? context.CurrentBranch.FriendlyName); + var config = context.FullConfiguration.GetConfigForBranch(branch ?? context.CurrentBranch.NameWithoutRemote()); if ( config?.Increment != null && config.Increment != IncrementStrategy.Inherit ) { return config.Increment.Value.ToVersionField(); diff --git a/src/GitVersionCore/LibGitExtensions.cs b/src/GitVersionCore/LibGitExtensions.cs index ea827aa525..8e339a43c1 100644 --- a/src/GitVersionCore/LibGitExtensions.cs +++ b/src/GitVersionCore/LibGitExtensions.cs @@ -17,15 +17,21 @@ public static DateTimeOffset When(this Commit commit) /// /// Checks if the two branch objects refer to the same branch (have the same friendly name). /// - public static bool IsSameBranch(this Branch branch, Branch otherBranch) + public static string NameWithoutRemote(this Branch branch) { - // For each branch, fixup the friendly name if the branch is remote. - var otherBranchFriendlyName = otherBranch.IsRemote ? - otherBranch.FriendlyName.Substring(otherBranch.FriendlyName.IndexOf("/", StringComparison.Ordinal) + 1) : - otherBranch.FriendlyName; - var branchFriendlyName = branch.IsRemote ? + return branch.IsRemote ? branch.FriendlyName.Substring(branch.FriendlyName.IndexOf("/", StringComparison.Ordinal) + 1) : branch.FriendlyName; + } + + /// + /// Checks if the two branch objects refer to the same branch (have the same friendly name). + /// + public static bool IsSameBranch(this Branch branch, Branch otherBranch) + { + // For each branch, fixup the friendly name if the branch is remote. + var otherBranchFriendlyName = otherBranch.NameWithoutRemote(); + var branchFriendlyName = branch.NameWithoutRemote(); return otherBranchFriendlyName == branchFriendlyName; } diff --git a/src/GitVersionCore/MergeMessage.cs b/src/GitVersionCore/MergeMessage.cs index 1dd5ecc3ac..1766f54fba 100644 --- a/src/GitVersionCore/MergeMessage.cs +++ b/src/GitVersionCore/MergeMessage.cs @@ -15,6 +15,10 @@ class MergeMessage static Regex smartGitMergeMessage = new Regex( @"^Finish (?.*)", RegexOptions.IgnoreCase | RegexOptions.Compiled); + static Regex parseRemoteTrackingMergeMessage = new Regex( + @"^Merge remote-tracking branch '(?.*)' into (?.*)", + RegexOptions.IgnoreCase | RegexOptions.Compiled); + private string mergeMessage; private Config config; @@ -73,7 +77,14 @@ private string ParseBranch() PullRequestNumber = pullNumber; } var from = match.Groups["Source"].Value; - // We could remove/separate the remote name at this point? + // TODO We could remove/separate the remote name at this point? + return from; + } + + match = parseRemoteTrackingMergeMessage.Match(mergeMessage); + if (match.Success) { + var from = match.Groups["SourceBranch"].Value; + // TODO We could remove/separate the remote name at this point? return from; }