Skip to content

Commit f5ca9c3

Browse files
committed
Warn on obsolete branch configuration settings
1 parent b76bca9 commit f5ca9c3

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace GitVersion
2+
{
3+
using YamlDotNet.Serialization;
4+
5+
/// <summary>
6+
/// Obsolete properties are added to this, so we can check to see if they are used and provide good error messages for migration
7+
/// </summary>
8+
public class LegacyBranchConfig
9+
{
10+
[YamlMember(Alias = "is-develop")]
11+
public string IsDevelop
12+
{
13+
get; set;
14+
}
15+
}
16+
}
Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,56 @@
11
namespace GitVersion
22
{
3+
using System.Collections.Generic;
4+
using System.Linq;
35
using YamlDotNet.Serialization;
46

57
/// <summary>
68
/// Obsolete properties are added to this, so we can check to see if they are used and provide good error messages for migration
79
/// </summary>
810
public class LegacyConfig
911
{
12+
private Dictionary<string, LegacyBranchConfig> branches = new Dictionary<string, LegacyBranchConfig>();
13+
1014
public string assemblyVersioningScheme { get; set; }
1115

1216
[YamlMember(Alias = "develop-branch-tag")]
1317
public string DevelopBranchTag { get; set; }
1418

1519
[YamlMember(Alias = "release-branch-tag")]
1620
public string ReleaseBranchTag { get; set; }
21+
22+
[YamlMember(Alias = "branches")]
23+
public Dictionary<string, LegacyBranchConfig> Branches
24+
{
25+
get
26+
{
27+
return branches;
28+
}
29+
set
30+
{
31+
value.ToList().ForEach(_ =>
32+
{
33+
if (!branches.ContainsKey(_.Key))
34+
branches.Add(_.Key, new LegacyBranchConfig());
35+
36+
branches[_.Key] = MergeObjects(branches[_.Key], _.Value);
37+
});
38+
}
39+
}
40+
41+
private T MergeObjects<T>(T target, T source)
42+
{
43+
typeof(T).GetProperties()
44+
.Where(prop => prop.CanRead && prop.CanWrite)
45+
.Select(_ => new
46+
{
47+
prop = _,
48+
value = _.GetValue(source, null)
49+
})
50+
.Where(_ => _.value != null)
51+
.ToList()
52+
.ForEach(_ => _.prop.SetValue(target, _.value, null));
53+
return target;
54+
}
1755
}
18-
}
56+
}

src/GitVersionCore/Configuration/LegacyConfigNotifier.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public static void Notify(StringReader reader)
2626
if (legacyConfig.ReleaseBranchTag != null)
2727
issues.Add("release-branch-tag has been replaced by branch specific configuration. See http://gitversion.readthedocs.org/en/latest/configuration/#branch-configuration");
2828

29+
if (legacyConfig.Branches != null && legacyConfig.Branches.Any(branches => branches.Value.IsDevelop != null))
30+
issues.Add("'is-develop' is deprecated, use 'track-release-branches' instead. See http://gitversion.readthedocs.org/en/latest/configuration/#branch-configuration");
31+
2932
if (issues.Any())
3033
throw new OldConfigurationException("GitVersion configuration file contains old configuration, please fix the following errors:\r\n" + string.Join("\r\n", issues));
3134
}

src/GitVersionCore/GitVersionCore.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<Compile Include="Configuration\ConfigSerialiser.cs" />
9898
<Compile Include="Configuration\ConfigurationProvider.cs" />
9999
<Compile Include="Configuration\IncrementStrategy.cs" />
100+
<Compile Include="Configuration\LegacyBranchConfig.cs" />
100101
<Compile Include="Configuration\LegacyConfig.cs" />
101102
<Compile Include="Configuration\LegacyConfigNotifier.cs" />
102103
<Compile Include="Configuration\OldConfigurationException.cs" />

0 commit comments

Comments
 (0)