Skip to content

Commit 371a896

Browse files
Ruh Ullah Shahasbjornu
Ruh Ullah Shah
authored andcommitted
[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.
1 parent 0b051f4 commit 371a896

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

src/GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using NUnit.Framework;
55
using Shouldly;
66
using System;
7+
using System.Collections.Generic;
78
using System.IO;
89
using System.Linq;
910
using System.Reflection;
@@ -362,4 +363,71 @@ public void WarnOnObsoleteIsDevelopBranchConfigurationSetting()
362363
const string expectedMessage = @"'is-develop' is deprecated, use 'tracks-release-branches' instead.";
363364
exception.Message.ShouldContain(expectedMessage);
364365
}
366+
367+
[Test]
368+
public void ShouldUseSpecifiedSourceBranchesForDevelop()
369+
{
370+
var defaultConfig = ConfigurationProvider.Provide(repoPath, fileSystem);
371+
const string text = @"
372+
next-version: 2.0.0
373+
branches:
374+
develop:
375+
mode: ContinuousDeployment
376+
source-branches: ['develop']
377+
tag: dev";
378+
SetupConfigFileContent(text);
379+
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
380+
381+
config.Branches["develop"].SourceBranches.ShouldBe(new List<string> { "develop" });
382+
}
383+
384+
[Test]
385+
public void ShouldUseDefaultSourceBranchesWhenNotSpecifiedForDevelop()
386+
{
387+
var defaultConfig = ConfigurationProvider.Provide(repoPath, fileSystem);
388+
const string text = @"
389+
next-version: 2.0.0
390+
branches:
391+
develop:
392+
mode: ContinuousDeployment
393+
tag: dev";
394+
SetupConfigFileContent(text);
395+
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
396+
397+
config.Branches["develop"].SourceBranches.ShouldBe(new List<string>());
398+
}
399+
400+
[Test]
401+
public void ShouldUseSpecifiedSourceBranchesForFeature()
402+
{
403+
var defaultConfig = ConfigurationProvider.Provide(repoPath, fileSystem);
404+
const string text = @"
405+
next-version: 2.0.0
406+
branches:
407+
feature:
408+
mode: ContinuousDeployment
409+
source-branches: ['develop', 'release']
410+
tag: dev";
411+
SetupConfigFileContent(text);
412+
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
413+
414+
config.Branches["feature"].SourceBranches.ShouldBe(new List<string> { "develop", "release" });
415+
}
416+
417+
[Test]
418+
public void ShouldUseDefaultSourceBranchesWhenNotSpecifiedForFeature()
419+
{
420+
var defaultConfig = ConfigurationProvider.Provide(repoPath, fileSystem);
421+
const string text = @"
422+
next-version: 2.0.0
423+
branches:
424+
feature:
425+
mode: ContinuousDeployment
426+
tag: dev";
427+
SetupConfigFileContent(text);
428+
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
429+
430+
config.Branches["feature"].SourceBranches.ShouldBe(
431+
new List<string> { "develop", "master", "release", "feature", "support", "hotfix" });
432+
}
365433
}

src/GitVersionCore/Configuration/ConfigurationProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ public static void ApplyBranchDefaults(Config config,
220220
bool isMainline = false)
221221
{
222222
branchConfig.Regex = string.IsNullOrEmpty(branchConfig.Regex) ? branchRegex : branchConfig.Regex;
223-
branchConfig.SourceBranches = sourceBranches;
223+
branchConfig.SourceBranches = branchConfig.SourceBranches == null || !branchConfig.SourceBranches.Any()
224+
? sourceBranches : branchConfig.SourceBranches;
224225
branchConfig.Tag = branchConfig.Tag ?? defaultTag;
225226
branchConfig.TagNumberPattern = branchConfig.TagNumberPattern ?? defaultTagNumberPattern;
226227
branchConfig.Increment = branchConfig.Increment ?? defaultIncrementStrategy ?? config.Increment ?? DefaultIncrementStrategy;

0 commit comments

Comments
 (0)