Skip to content

Commit c9ce4d8

Browse files
committed
* ConfigurationProvider.cs refactored MigrateBranches - clean&readable code that doesn't fear Reshaper
1 parent dbc988b commit c9ce4d8

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

src/GitVersionCore/Configuration/ConfigurationProvider.cs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ namespace GitVersion
22
{
33
using GitVersion.Configuration.Init.Wizard;
44
using GitVersion.Helpers;
5-
using System.Collections.Generic;
65
using System.ComponentModel;
76
using System.IO;
87
using System.Linq;
@@ -100,27 +99,25 @@ public static void ApplyOverridesTo(Config config, Config overrideConfig)
10099

101100
static void MigrateBranches(Config config)
102101
{
103-
// Map of current names and previous names
104-
var dict = new Dictionary<string, string[]>
105-
{
106-
{"hotfix(es)?[/-]", new[] { "hotfix[/-]" }},
107-
{"features?[/-]", new[] { "feature[/-]", "feature(s)?[/-]" }},
108-
{"releases?[/-]", new[] { "release[/-]" }},
109-
{"dev(elop)?(ment)?$", new[] { "develop" }}
110-
};
102+
MigrateObsoleteBranches(config, "hotfix(es)?[/-]", "hotfix[/-]");
103+
MigrateObsoleteBranches(config, "features?[/-]", "feature[/-]", "feature(s)?[/-]");
104+
MigrateObsoleteBranches(config, "releases?[/-]", "release[/-]");
105+
MigrateObsoleteBranches(config, "dev(elop)?(ment)?$", "develop");
106+
}
111107

112-
foreach (var mapping in dict)
108+
static void MigrateObsoleteBranches(Config config, string newBranch, params string[] obsoleteBranches)
109+
{
110+
foreach (var obsoleteBranch in obsoleteBranches)
113111
{
114-
foreach (var source in mapping.Value)
112+
if (!config.Branches.ContainsKey(obsoleteBranch))
115113
{
116-
if (config.Branches.ContainsKey(source))
117-
{
118-
// found one, rename
119-
var bc = config.Branches[source];
120-
config.Branches.Remove(source);
121-
config.Branches[mapping.Key] = bc; // re-add with new name
122-
}
114+
continue;
123115
}
116+
117+
// found one, rename
118+
var bc = config.Branches[obsoleteBranch];
119+
config.Branches.Remove(obsoleteBranch);
120+
config.Branches[newBranch] = bc; // re-add with new name
124121
}
125122
}
126123

0 commit comments

Comments
 (0)