From aa679c302ae365e6851ce466268565051406f0fc Mon Sep 17 00:00:00 2001 From: Ruh Ullah Shah Date: Mon, 18 Feb 2019 14:08:55 +0100 Subject: [PATCH] [Configuration Bugfix] Problem: Adding source-branches to the config had no effect and would always be over-written with the default value specified in the configuration provider for the default branches. Cause: SourceBranches from BranchConfig was not being checked before being over-written. Fix: Check SourceBranches and use it before applying the defaults. --- .../ConfigProviderTests.cs | 68 +++++++++++++++++++ .../Configuration/ConfigurationProvider.cs | 3 +- 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/GitVersionCore.Tests/ConfigProviderTests.cs b/src/GitVersionCore.Tests/ConfigProviderTests.cs index 035d4d15b6..c322ed50be 100644 --- a/src/GitVersionCore.Tests/ConfigProviderTests.cs +++ b/src/GitVersionCore.Tests/ConfigProviderTests.cs @@ -5,6 +5,7 @@ using NUnit.Framework; using Shouldly; using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; @@ -363,4 +364,71 @@ public void WarnOnObsoleteIsDevelopBranchConfigurationSetting() const string expectedMessage = @"'is-develop' is deprecated, use 'tracks-release-branches' instead."; exception.Message.ShouldContain(expectedMessage); } + + [Test] + public void ShouldUseSpecifiedSourceBranchesForDevelop() + { + var defaultConfig = ConfigurationProvider.Provide(repoPath, fileSystem); + const string text = @" +next-version: 2.0.0 +branches: + develop: + mode: ContinuousDeployment + source-branches: ['develop'] + tag: dev"; + SetupConfigFileContent(text); + var config = ConfigurationProvider.Provide(repoPath, fileSystem); + + config.Branches["develop"].SourceBranches.ShouldBe(new List { "develop" }); + } + + [Test] + public void ShouldUseDefaultSourceBranchesWhenNotSpecifiedForDevelop() + { + var defaultConfig = ConfigurationProvider.Provide(repoPath, fileSystem); + const string text = @" +next-version: 2.0.0 +branches: + develop: + mode: ContinuousDeployment + tag: dev"; + SetupConfigFileContent(text); + var config = ConfigurationProvider.Provide(repoPath, fileSystem); + + config.Branches["develop"].SourceBranches.ShouldBe(new List()); + } + + [Test] + public void ShouldUseSpecifiedSourceBranchesForFeature() + { + var defaultConfig = ConfigurationProvider.Provide(repoPath, fileSystem); + const string text = @" +next-version: 2.0.0 +branches: + feature: + mode: ContinuousDeployment + source-branches: ['develop', 'release'] + tag: dev"; + SetupConfigFileContent(text); + var config = ConfigurationProvider.Provide(repoPath, fileSystem); + + config.Branches["feature"].SourceBranches.ShouldBe(new List { "develop", "release" }); + } + + [Test] + public void ShouldUseDefaultSourceBranchesWhenNotSpecifiedForFeature() + { + var defaultConfig = ConfigurationProvider.Provide(repoPath, fileSystem); + const string text = @" +next-version: 2.0.0 +branches: + feature: + mode: ContinuousDeployment + tag: dev"; + SetupConfigFileContent(text); + var config = ConfigurationProvider.Provide(repoPath, fileSystem); + + config.Branches["feature"].SourceBranches.ShouldBe( + new List { "develop", "master", "release", "feature", "support", "hotfix" }); + } } diff --git a/src/GitVersionCore/Configuration/ConfigurationProvider.cs b/src/GitVersionCore/Configuration/ConfigurationProvider.cs index d0fc3b8d96..5237866b43 100644 --- a/src/GitVersionCore/Configuration/ConfigurationProvider.cs +++ b/src/GitVersionCore/Configuration/ConfigurationProvider.cs @@ -221,7 +221,8 @@ public static void ApplyBranchDefaults(Config config, bool isMainline = false) { branchConfig.Regex = string.IsNullOrEmpty(branchConfig.Regex) ? branchRegex : branchConfig.Regex; - branchConfig.SourceBranches = sourceBranches; + branchConfig.SourceBranches = branchConfig.SourceBranches == null || !branchConfig.SourceBranches.Any() + ? sourceBranches : branchConfig.SourceBranches; branchConfig.Tag = branchConfig.Tag ?? defaultTag; branchConfig.TagNumberPattern = branchConfig.TagNumberPattern ?? defaultTagNumberPattern; branchConfig.Increment = branchConfig.Increment ?? defaultIncrementStrategy ?? config.Increment ?? DefaultIncrementStrategy;