From 7c728645a452cebba3c532692cf3ba56f2fb5c85 Mon Sep 17 00:00:00 2001 From: Ruh Ullah Shah Date: Thu, 17 May 2018 14:20:04 +0200 Subject: [PATCH 1/2] Removing caret(^) addition to branch regex to avoid runtime crash due to Stack Overflow if the repository has multiple develop branches --- .../IntegrationTests/DevelopScenarios.cs | 21 +++++++++++++++++++ src/GitVersionCore/Configuration/Config.cs | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs index e95d420615..8131fcea70 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs @@ -183,4 +183,25 @@ public void InheritVersionFromReleaseBranch() fixture.AssertFullSemver("2.1.0-MyFeature.1+5"); } } + + [Test] + public void WhenMultipleDevelopBranchesExistAndCurrentBranchHasIncrementInheritPolicyAndCurrentCommitIsAMerge() + { + using (var fixture = new EmptyRepositoryFixture()) + { + fixture.Repository.MakeATaggedCommit("1.0.0"); + fixture.Repository.CreateBranch("bob_develop"); + fixture.Repository.CreateBranch("develop"); + fixture.Repository.CreateBranch("feature/x"); + + Commands.Checkout(fixture.Repository, "develop"); + fixture.Repository.MakeACommit(); + + Commands.Checkout(fixture.Repository, "feature/x"); + fixture.Repository.MakeACommit(); + fixture.Repository.MergeNoFF("develop"); + + fixture.AssertFullSemver("1.1.0-x.1+3"); + } + } } \ No newline at end of file diff --git a/src/GitVersionCore/Configuration/Config.cs b/src/GitVersionCore/Configuration/Config.cs index 733b294292..b95af84f14 100644 --- a/src/GitVersionCore/Configuration/Config.cs +++ b/src/GitVersionCore/Configuration/Config.cs @@ -101,7 +101,7 @@ public BranchConfig GetConfigForBranch(string branchName) { if (branchName == null) throw new ArgumentNullException(nameof(branchName)); var matches = Branches - .Where(b => Regex.IsMatch(branchName, "^" + b.Value.Regex, RegexOptions.IgnoreCase)); + .Where(b => Regex.IsMatch(branchName, b.Value.Regex, RegexOptions.IgnoreCase)); try { From 22686d1a2048d7c778d6b1c3f5ba09ef5bcb3356 Mon Sep 17 00:00:00 2001 From: Ruh Ullah Shah Date: Mon, 18 Feb 2019 16:25:40 +0100 Subject: [PATCH 2/2] Fixed failing testcases, updated the docs to reflect the changes in the regex --- docs/configuration.md | 14 +++++++------- ....CanWriteOutEffectiveConfiguration.approved.txt | 14 +++++++------- .../IntegrationTests/DevelopScenarios.cs | 6 +++--- .../Configuration/ConfigurationProvider.cs | 14 +++++++------- .../Configuration/LegacyConfigNotifier.cs | 3 ++- 5 files changed, 26 insertions(+), 25 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 217041adbd..f96b6ea4ee 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -189,7 +189,7 @@ If you have branch specific configuration upgrading to v4 will force you to upgr ```yaml branches: master: - regex: master + regex: ^master mode: ContinuousDelivery tag: '' increment: Patch @@ -198,7 +198,7 @@ branches: tracks-release-branches: false is-release-branch: false release: - regex: releases?[/-] + regex: ^releases?[/-] mode: ContinuousDelivery tag: beta increment: Patch @@ -207,7 +207,7 @@ branches: tracks-release-branches: false is-release-branch: true feature: - regex: features?[/-] + regex: ^features?[/-] mode: ContinuousDelivery tag: useBranchName increment: Inherit @@ -216,7 +216,7 @@ branches: tracks-release-branches: false is-release-branch: false pull-request: - regex: (pull|pull\-requests|pr)[/-] + regex: ^(pull|pull\-requests|pr)[/-] mode: ContinuousDelivery tag: PullRequest increment: Inherit @@ -226,7 +226,7 @@ branches: tracks-release-branches: false is-release-branch: false hotfix: - regex: hotfix(es)?[/-] + regex: ^hotfix(es)?[/-] mode: ContinuousDelivery tag: beta increment: Patch @@ -235,7 +235,7 @@ branches: tracks-release-branches: false is-release-branch: false support: - regex: support[/-] + regex: ^support[/-] mode: ContinuousDelivery tag: '' increment: Patch @@ -244,7 +244,7 @@ branches: tracks-release-branches: false is-release-branch: false develop: - regex: dev(elop)?(ment)?$ + regex: ^dev(elop)?(ment)?$ mode: ContinuousDeployment tag: unstable increment: Minor diff --git a/src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt b/src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt index 2650aedd2b..7d0d4f02a6 100644 --- a/src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt +++ b/src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt @@ -18,7 +18,7 @@ branches: increment: Minor prevent-increment-of-merged-branch-version: false track-merge-target: true - regex: dev(elop)?(ment)?$ + regex: ^dev(elop)?(ment)?$ source-branches: [] tracks-release-branches: true is-release-branch: false @@ -29,7 +29,7 @@ branches: increment: Patch prevent-increment-of-merged-branch-version: true track-merge-target: false - regex: master$ + regex: ^master$ source-branches: - develop - release @@ -42,7 +42,7 @@ branches: increment: Patch prevent-increment-of-merged-branch-version: true track-merge-target: false - regex: releases?[/-] + regex: ^releases?[/-] source-branches: - develop - master @@ -57,7 +57,7 @@ branches: increment: Inherit prevent-increment-of-merged-branch-version: false track-merge-target: false - regex: features?[/-] + regex: ^features?[/-] source-branches: - develop - master @@ -75,7 +75,7 @@ branches: prevent-increment-of-merged-branch-version: false tag-number-pattern: '[/-](?\d+)' track-merge-target: false - regex: (pull|pull\-requests|pr)[/-] + regex: ^(pull|pull\-requests|pr)[/-] source-branches: - develop - master @@ -92,7 +92,7 @@ branches: increment: Patch prevent-increment-of-merged-branch-version: false track-merge-target: false - regex: hotfix(es)?[/-] + regex: ^hotfix(es)?[/-] source-branches: - develop - master @@ -106,7 +106,7 @@ branches: increment: Patch prevent-increment-of-merged-branch-version: true track-merge-target: false - regex: support[/-] + regex: ^support[/-] source-branches: - master tracks-release-branches: false diff --git a/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs b/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs index 2d16b6ffa1..9f505afbf4 100644 --- a/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs +++ b/src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs @@ -1,4 +1,4 @@ -using GitTools.Testing; +using GitTools.Testing; using GitVersion; using GitVersionCore.Tests; using LibGit2Sharp; @@ -201,7 +201,7 @@ public void WhenMultipleDevelopBranchesExistAndCurrentBranchHasIncrementInheritP fixture.Repository.MakeACommit(); fixture.Repository.MergeNoFF("develop"); - fixture.AssertFullSemver("1.1.0-x.1+3"); + fixture.AssertFullSemver("1.0.1-x.1+3"); } } -} \ No newline at end of file +} diff --git a/src/GitVersionCore/Configuration/ConfigurationProvider.cs b/src/GitVersionCore/Configuration/ConfigurationProvider.cs index 796ecc9424..b6c6ae38a4 100644 --- a/src/GitVersionCore/Configuration/ConfigurationProvider.cs +++ b/src/GitVersionCore/Configuration/ConfigurationProvider.cs @@ -14,13 +14,13 @@ public class ConfigurationProvider public const string DefaultConfigFileName = "GitVersion.yml"; public const string ObsoleteConfigFileName = "GitVersionConfig.yaml"; - public const string ReleaseBranchRegex = "releases?[/-]"; - public const string FeatureBranchRegex = "features?[/-]"; - public const string PullRequestRegex = @"(pull|pull\-requests|pr)[/-]"; - public const string HotfixBranchRegex = "hotfix(es)?[/-]"; - public const string SupportBranchRegex = "support[/-]"; - public const string DevelopBranchRegex = "dev(elop)?(ment)?$"; - public const string MasterBranchRegex = "master$"; + public const string ReleaseBranchRegex = "^releases?[/-]"; + public const string FeatureBranchRegex = "^features?[/-]"; + public const string PullRequestRegex = @"^(pull|pull\-requests|pr)[/-]"; + public const string HotfixBranchRegex = "^hotfix(es)?[/-]"; + public const string SupportBranchRegex = "^support[/-]"; + public const string DevelopBranchRegex = "^dev(elop)?(ment)?$"; + public const string MasterBranchRegex = "^master$"; public const string MasterBranchKey = "master"; public const string ReleaseBranchKey = "release"; public const string FeatureBranchKey = "feature"; diff --git a/src/GitVersionCore/Configuration/LegacyConfigNotifier.cs b/src/GitVersionCore/Configuration/LegacyConfigNotifier.cs index 2086255579..00ba347cc3 100644 --- a/src/GitVersionCore/Configuration/LegacyConfigNotifier.cs +++ b/src/GitVersionCore/Configuration/LegacyConfigNotifier.cs @@ -17,7 +17,8 @@ public class LegacyConfigNotifier {ConfigurationProvider.ReleaseBranchRegex, ConfigurationProvider.ReleaseBranchKey}, {ConfigurationProvider.SupportBranchRegex, ConfigurationProvider.SupportBranchKey}, {ConfigurationProvider.PullRequestRegex, ConfigurationProvider.PullRequestBranchKey}, - {"release[/-]", ConfigurationProvider.ReleaseBranchKey}, + {"dev(elop)?(ment)?$", ConfigurationProvider.DevelopBranchKey }, + {"release[/-]", ConfigurationProvider.ReleaseBranchKey }, {"hotfix[/-]", ConfigurationProvider.HotfixBranchKey }, {"feature(s)?[/-]", ConfigurationProvider.FeatureBranchKey }, {"feature[/-]", ConfigurationProvider.FeatureBranchKey }