Skip to content

Commit 6f6305c

Browse files
committed
Merge pull request #342 from JakeGinnivan/legacyConfig
Throw error when user is using legacy configuration values
2 parents 9fd17dd + a65a115 commit 6f6305c

File tree

13 files changed

+97
-97
lines changed

13 files changed

+97
-97
lines changed

GitVersion.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PossibleMistakenCallToGetType_002E2/@EntryIndexedValue">ERROR</s:String>
5555
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PossibleNullReferenceException/@EntryIndexedValue">WARNING</s:String>
5656
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PrivateFieldCanBeConvertedToLocalVariable/@EntryIndexedValue">ERROR</s:String>
57+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantArgumentNameForLiteralExpression/@EntryIndexedValue">DO_NOT_SHOW</s:String>
5758
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantAssignment/@EntryIndexedValue">ERROR</s:String>
5859
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantBaseConstructorCall/@EntryIndexedValue">ERROR</s:String>
5960
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantBoolCompare/@EntryIndexedValue">ERROR</s:String>

GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public void CanInheritVersioningMode()
6363
SetupConfigFileContent(text);
6464
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
6565
config.Branches["develop"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
66-
config.Release.VersioningMode.ShouldBe(VersioningMode.ContinuousDelivery);
67-
config.Develop.Tag.ShouldBe("unstable");
66+
config.Branches["develop"].Tag.ShouldBe("unstable");
67+
config.Branches["release[/-]"].VersioningMode.ShouldBe(VersioningMode.ContinuousDelivery);
6868
}
6969

7070
[Test]
@@ -76,10 +76,11 @@ public void CanReadOldDocument()
7676
release-branch-tag: rc
7777
";
7878
SetupConfigFileContent(text);
79-
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
80-
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
81-
config.Branches["develop"].Tag.ShouldBe("alpha");
82-
config.Branches["release[/-]"].Tag.ShouldBe("rc");
79+
var error = Should.Throw<OldConfigurationException>(() => ConfigurationProvider.Provide(gitDirectory, fileSystem));
80+
error.Message.ShouldContainWithoutWhitespace(@"GitVersionConfig.yaml contains old configuration, please fix the following errors:
81+
assemblyVersioningScheme has been replaced by assembly-versioning-scheme
82+
develop-branch-tag has been replaced by branch specific configuration.See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration
83+
release-branch-tag has been replaced by branch specific configuration.See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration");
8384
}
8485

8586
[Test]

GitVersionCore.Tests/IntegrationTests/GitFlow/DevelopScenarios.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ public void CanHandleContinuousDelivery()
6262
[Test]
6363
public void CanClearDevelopTagViaConfig()
6464
{
65-
using (var fixture = new EmptyRepositoryFixture(new Config
66-
{
67-
Develop = {Tag= ""}
68-
}))
65+
var config = new Config();
66+
config.Branches["develop"].Tag = "";
67+
using (var fixture = new EmptyRepositoryFixture(config))
6968
{
7069
fixture.Repository.MakeATaggedCommit("1.0.0");
7170
fixture.Repository.CreateBranch("develop").Checkout();

GitVersionCore.Tests/IntegrationTests/GitFlow/ReleaseBranchTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public void CanTakeVersionFromReleaseBranch()
2323
[Test]
2424
public void CanTakeVersionFromReleaseBranchWithTagOverriden()
2525
{
26-
using (var fixture = new EmptyRepositoryFixture(new Config { ReleaseBranchTag = "rc" }))
26+
var config = new Config();
27+
config.Branches["release[/-]"].Tag = "rc";
28+
using (var fixture = new EmptyRepositoryFixture(config))
2729
{
2830
fixture.Repository.MakeATaggedCommit("1.0.3");
2931
fixture.Repository.CreateBranch("develop");

GitVersionCore.Tests/IntegrationTests/GitHubFlow/ReleaseBranchTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ public void CanTakeVersionFromReleaseBranch()
2222
[Test]
2323
public void CanTakeVersionFromReleaseBranchWithTagOverriden()
2424
{
25-
using (var fixture = new EmptyRepositoryFixture(new Config { ReleaseBranchTag = "rc" }))
25+
var config = new Config();
26+
config.Branches["release[/-]"].Tag = "rc";
27+
using (var fixture = new EmptyRepositoryFixture(config))
2628
{
2729
fixture.Repository.MakeATaggedCommit("1.0.3");
2830
fixture.Repository.MakeCommits(5);
Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
namespace GitVersion
22
{
3-
using System;
43
using System.Collections.Generic;
54
using System.Linq;
6-
75
using YamlDotNet.Serialization;
86

97
public class Config
@@ -16,44 +14,19 @@ public Config()
1614
{
1715
AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch;
1816
TagPrefix = "[vV]";
17+
VersioningMode = VersioningMode.ContinuousDelivery;
1918
Branches["release[/-]"] = new BranchConfig { Tag = "beta" };
2019
Branches["hotfix[/-]"] = new BranchConfig { Tag = "beta" };
21-
Branches["develop"] = new BranchConfig { Tag = "unstable" };
22-
VersioningMode = VersioningMode.ContinuousDelivery;
23-
Develop.VersioningMode = VersioningMode.ContinuousDeployment;
20+
Branches["develop"] = new BranchConfig
21+
{
22+
Tag = "unstable",
23+
VersioningMode = VersioningMode.ContinuousDeployment
24+
};
2425
}
2526

2627
[YamlAlias("assembly-versioning-scheme")]
2728
public AssemblyVersioningScheme AssemblyVersioningScheme { get; set; }
2829

29-
[YamlAlias("develop-branch-tag")]
30-
[Obsolete]
31-
public string DevelopBranchTag
32-
{
33-
set
34-
{
35-
Develop.Tag = value;
36-
}
37-
get
38-
{
39-
return Develop.Tag;
40-
}
41-
}
42-
43-
[YamlAlias("release-branch-tag")]
44-
[Obsolete]
45-
public string ReleaseBranchTag
46-
{
47-
set
48-
{
49-
Release.Tag = value;
50-
}
51-
get
52-
{
53-
return Release.Tag;
54-
}
55-
}
56-
5730
[YamlAlias("mode")]
5831
public VersioningMode VersioningMode
5932
{
@@ -97,23 +70,5 @@ private T MergeObjects<T>(T target, T source)
9770

9871
[YamlAlias("next-version")]
9972
public string NextVersion { get; set; }
100-
101-
[Obsolete]
102-
public BranchConfig Develop
103-
{
104-
get
105-
{
106-
return Branches["develop"];
107-
}
108-
}
109-
110-
[Obsolete]
111-
public BranchConfig Release
112-
{
113-
get
114-
{
115-
return Branches["release[/-]"];
116-
}
117-
}
11873
}
11974
}

GitVersionCore/Configuration/ConfigurationProvider.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ public static Config Provide(string gitDirectory, IFileSystem fileSystem)
1515
if (fileSystem.Exists(configFilePath))
1616
{
1717
var readAllText = fileSystem.ReadAllText(configFilePath);
18-
if (oldAssemblyVersioningScheme.IsMatch(readAllText))
19-
{
20-
readAllText = oldAssemblyVersioningScheme.Replace(readAllText, "assembly-versioning-scheme");
21-
fileSystem.WriteAllText(configFilePath, readAllText);
22-
Logger.WriteWarning("Found legacy configuration value 'assemblyVersioningScheme', replaced with 'assembly-versioning-scheme");
23-
}
18+
LegacyConfigNotifier.Notify(new StringReader(readAllText));
2419

2520
return ConfigReader.Read(new StringReader(readAllText));
2621
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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 LegacyConfig
9+
{
10+
public string assemblyVersioningScheme { get; set; }
11+
12+
[YamlAlias("develop-branch-tag")]
13+
public string DevelopBranchTag { get; set; }
14+
15+
[YamlAlias("release-branch-tag")]
16+
public string ReleaseBranchTag { get; set; }
17+
}
18+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace GitVersion
2+
{
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using YamlDotNet.Serialization;
7+
using YamlDotNet.Serialization.NamingConventions;
8+
9+
public class LegacyConfigNotifier
10+
{
11+
public static void Notify(StringReader reader)
12+
{
13+
var deserializer = new Deserializer(null, new NullNamingConvention(), ignoreUnmatched: true);
14+
var legacyConfig = deserializer.Deserialize<LegacyConfig>(reader);
15+
if (legacyConfig == null)
16+
return;
17+
18+
var issues = new List<string>();
19+
20+
if (legacyConfig.assemblyVersioningScheme != null)
21+
issues.Add("assemblyVersioningScheme has been replaced by assembly-versioning-scheme");
22+
23+
if (legacyConfig.DevelopBranchTag != null)
24+
issues.Add("develop-branch-tag has been replaced by branch specific configuration. See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration");
25+
26+
if (legacyConfig.ReleaseBranchTag != null)
27+
issues.Add("release-branch-tag has been replaced by branch specific configuration. See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration");
28+
29+
if (issues.Any())
30+
throw new OldConfigurationException("GitVersionConfig.yaml contains old configuration, please fix the following errors:\r\n" + string.Join("\r\n", issues));
31+
}
32+
}
33+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace GitVersion
2+
{
3+
using System;
4+
using System.Runtime.Serialization;
5+
6+
[Serializable]
7+
public class OldConfigurationException : Exception
8+
{
9+
public OldConfigurationException(string message) : base(message)
10+
{
11+
}
12+
13+
protected OldConfigurationException(
14+
SerializationInfo info,
15+
StreamingContext context) : base(info, context)
16+
{
17+
}
18+
}
19+
}

GitVersionCore/GitVersionCore.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@
7474
<Compile Include="Configuration\Config.cs" />
7575
<Compile Include="Configuration\ConfigReader.cs" />
7676
<Compile Include="Configuration\ConfigurationProvider.cs" />
77+
<Compile Include="Configuration\LegacyConfig.cs" />
78+
<Compile Include="Configuration\LegacyConfigNotifier.cs" />
79+
<Compile Include="Configuration\OldConfigurationException.cs" />
7780
<Compile Include="GitFlow\BranchFinders\BranchCommitDifferenceFinder.cs" />
7881
<Compile Include="GitFlow\BranchFinders\RecentTagVersionExtractor.cs" />
7982
<Compile Include="Helpers\FileSystem.cs" />

GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ public class UpdateAssemblyInfo : Task
1212
{
1313
public string AssemblyVersioningScheme { get; set; }
1414

15-
public string DevelopBranchTag { get; set; }
16-
17-
public string ReleaseBranchTag { get; set; }
18-
1915
public string TagPrefix { get; set; }
2016

2117
public string NextVersion { get; set; }
@@ -101,16 +97,6 @@ public void InnerExecute()
10197
// TODO This should be covered by tests
10298
// TODO would be good to not have to duplicate this in both msbuild tasks
10399
// Null is intentional. Empty string means the user has set the value to an empty string and wants to clear the tag
104-
if (DevelopBranchTag != null)
105-
{
106-
configuration.DevelopBranchTag = DevelopBranchTag;
107-
}
108-
109-
if (ReleaseBranchTag != null)
110-
{
111-
configuration.ReleaseBranchTag = ReleaseBranchTag;
112-
}
113-
114100
if (TagPrefix != null)
115101
{
116102
configuration.TagPrefix = TagPrefix;

GitVersionTask/GetVersion.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ public class GetVersion : Task
7575
[Output]
7676
public string NuGetVersion { get; set; }
7777

78-
public string DevelopBranchTag { get; set; }
79-
80-
public string ReleaseBranchTag { get; set; }
81-
8278
public string TagPrefix { get; set; }
8379

8480
public string NextVersion { get; set; }
@@ -104,16 +100,6 @@ public override bool Execute()
104100

105101
// TODO This should be covered by tests
106102
// Null is intentional. Empty string means the user has set the value to an empty string and wants to clear the tag
107-
if (DevelopBranchTag != null)
108-
{
109-
configuration.DevelopBranchTag = DevelopBranchTag;
110-
}
111-
112-
if (ReleaseBranchTag != null)
113-
{
114-
configuration.ReleaseBranchTag = ReleaseBranchTag;
115-
}
116-
117103
if (TagPrefix != null)
118104
{
119105
configuration.TagPrefix = TagPrefix;

0 commit comments

Comments
 (0)