Skip to content

Commit f319232

Browse files
committed
Fixed exception when adding new branch specs to config
1 parent 216b03c commit f319232

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ public void OverwritesDefaultsWithProvidedConfig()
8888
config.Branches["develop"].Tag.ShouldBe("dev");
8989
}
9090

91+
[Test]
92+
public void CanProvideConfigForNewBranch()
93+
{
94+
const string text = @"
95+
next-version: 2.0.0
96+
branches:
97+
bug[/-]:
98+
tag: bugfix";
99+
SetupConfigFileContent(text);
100+
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
101+
102+
config.Branches["bug[/-]"].Tag.ShouldBe("bugfix");
103+
}
104+
91105
[Test]
92106
[MethodImpl(MethodImplOptions.NoInlining)]
93107
public void CanWriteOutEffectiveConfiguration()

GitVersionCore/Configuration/Config.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ public Dictionary<string, BranchConfig> Branches
7272
}
7373
set
7474
{
75-
value.ToList().ForEach(_ => branches[_.Key] = MergeObjects(branches[_.Key], _.Value));
75+
value.ToList().ForEach(_ =>
76+
{
77+
if (!branches.ContainsKey(_.Key))
78+
branches.Add(_.Key, new BranchConfig());
79+
80+
branches[_.Key] = MergeObjects(branches[_.Key], _.Value);
81+
});
7682
}
7783
}
7884

0 commit comments

Comments
 (0)