Skip to content

Commit 6e472fb

Browse files
author
Oren Novotny
committed
Add a migration step
1 parent 1416f9e commit 6e472fb

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

src/GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void Setup()
2424
}
2525

2626
[Test]
27-
public void CanReadDocument()
27+
public void CanReadDocumentAndMigrate()
2828
{
2929
const string text = @"
3030
assembly-versioning-scheme: MajorMinor
@@ -46,10 +46,10 @@ public void CanReadDocument()
4646
config.NextVersion.ShouldBe("2.0.0");
4747
config.TagPrefix.ShouldBe("[vV|version-]");
4848
config.VersioningMode.ShouldBe(VersioningMode.ContinuousDelivery);
49-
config.Branches["develop"].Tag.ShouldBe("dev");
50-
config.Branches["release[/-]"].Tag.ShouldBe("rc");
51-
config.Branches["release[/-]"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
52-
config.Branches["develop"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
49+
config.Branches["dev(elop)?(ment)?$"].Tag.ShouldBe("dev");
50+
config.Branches["releases?[/-]"].Tag.ShouldBe("rc");
51+
config.Branches["releases?[/-]"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
52+
config.Branches["dev(elop)?(ment)?$"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
5353
}
5454

5555
[Test]

src/GitVersionCore/Configuration/ConfigurationProvider.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace GitVersion
22
{
3+
using System.Collections.Generic;
34
using System.IO;
45
using System.Linq;
56
using System.Text;
@@ -20,6 +21,8 @@ public static Config Provide(string workingDirectory, IFileSystem fileSystem, bo
2021

2122
public static void ApplyDefaultsTo(Config config)
2223
{
24+
MigrateBranches(config);
25+
2326
config.AssemblyVersioningScheme = config.AssemblyVersioningScheme ?? AssemblyVersioningScheme.MajorMinorPatch;
2427
config.TagPrefix = config.TagPrefix ?? DefaultTagPrefix;
2528
config.VersioningMode = config.VersioningMode ?? VersioningMode.ContinuousDelivery;
@@ -53,6 +56,33 @@ public static void ApplyDefaultsTo(Config config)
5356
}
5457
}
5558

59+
static void MigrateBranches(Config config)
60+
{
61+
// Map of current names and previous names
62+
var dict = new Dictionary<string, string[]>
63+
{
64+
{ "hotfix(es)?[/-]", new []{"hotfix[/-]"}},
65+
{ "features?[/-]", new []{"feature[/-]"}},
66+
{ "releases?[/-]", new []{"release[/-]"}},
67+
{ "dev(elop)?(ment)?$", new []{"develop"}}
68+
};
69+
70+
foreach (var mapping in dict)
71+
{
72+
foreach (var source in mapping.Value)
73+
{
74+
if (config.Branches.ContainsKey(source))
75+
{
76+
// found one, rename
77+
var bc = config.Branches[source];
78+
config.Branches.Remove(source);
79+
config.Branches[mapping.Key] = bc; // re-add with new name
80+
}
81+
}
82+
}
83+
}
84+
85+
5686
static BranchConfig GetOrCreateBranchDefaults(Config config, string branch)
5787
{
5888
if (!config.Branches.ContainsKey(branch))

0 commit comments

Comments
 (0)