Skip to content

Commit 060ae41

Browse files
committed
Added branches in default config to GitVersion init branch list
GitVersion init branch configuration only includes branches which have custom config, this made it not very useful. Now at least you don't have to look at the source to se the branch regexes. We probably should take the next step of creating an alias so they key doesn't have to be a regex
1 parent f82e3b6 commit 060ae41

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/GitVersionCore/Configuration/Init/SetConfig/ConfigureBranches.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace GitVersion.Configuration.Init.SetConfig
33
using System;
44
using System.Collections.Generic;
55
using System.Linq;
6-
using GitVersion.Configuration.Init.Wizard;
6+
using Wizard;
77
using GitVersion.Helpers;
88

99
public class ConfigureBranches : ConfigInitWizardStep
@@ -26,7 +26,13 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
2626
try
2727
{
2828
var foundBranch = OrderedBranches(config).ElementAt(parsed - 1);
29-
steps.Enqueue(new ConfigureBranch(foundBranch.Key, foundBranch.Value, Console, FileSystem));
29+
var branchConfig = foundBranch.Value;
30+
if (branchConfig == null)
31+
{
32+
branchConfig = new BranchConfig();
33+
config.Branches.Add(foundBranch.Key, branchConfig);
34+
}
35+
steps.Enqueue(new ConfigureBranch(foundBranch.Key, branchConfig, Console, FileSystem));
3036
return StepResult.Ok();
3137
}
3238
catch (ArgumentOutOfRangeException)
@@ -46,7 +52,13 @@ protected override string GetPrompt(Config config, string workingDirectory)
4652

4753
static IOrderedEnumerable<KeyValuePair<string, BranchConfig>> OrderedBranches(Config config)
4854
{
49-
return config.Branches.OrderBy(b => b.Key);
55+
var defaultConfig = new Config();
56+
ConfigurationProvider.ApplyDefaultsTo(defaultConfig);
57+
var defaultConfigurationBranches = defaultConfig.Branches
58+
.Where(k => !config.Branches.ContainsKey(k.Key))
59+
// Return an empty branch config
60+
.Select(v => new KeyValuePair<string, BranchConfig>(v.Key, null));
61+
return config.Branches.Union(defaultConfigurationBranches).OrderBy(b => b.Key);
5062
}
5163

5264
protected override string DefaultResult

0 commit comments

Comments
 (0)