Skip to content

Commit 9d592ab

Browse files
committed
Revert "* ConfigurationProvider.cs clean code"
This reverts commit 7a2e309.
1 parent 7a2e309 commit 9d592ab

File tree

7 files changed

+60
-106
lines changed

7 files changed

+60
-106
lines changed

src/GitVersionCore/Configuration/ConfigurationProvider.cs

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
namespace GitVersion
22
{
3-
using GitVersion.Configuration.Init.Wizard;
4-
using GitVersion.Helpers;
53
using System.Collections.Generic;
64
using System.ComponentModel;
75
using System.IO;
86
using System.Linq;
97
using System.Text;
8+
using GitVersion.Configuration.Init.Wizard;
9+
using GitVersion.Helpers;
1010

1111
public class ConfigurationProvider
1212
{
@@ -103,27 +103,10 @@ static void MigrateBranches(Config config)
103103
// Map of current names and previous names
104104
var dict = new Dictionary<string, string[]>
105105
{
106-
{"hotfix(es)?[/-]", new[]
107-
{
108-
"hotfix[/-]"
109-
}
110-
},
111-
{"features?[/-]", new[]
112-
{
113-
"feature[/-]",
114-
"feature(s)?[/-]"
115-
}
116-
},
117-
{"releases?[/-]", new[]
118-
{
119-
"release[/-]"
120-
}
121-
},
122-
{"dev(elop)?(ment)?$", new[]
123-
{
124-
"develop"
125-
}
126-
}
106+
{ "hotfix(es)?[/-]", new [] { "hotfix[/-]" }},
107+
{ "features?[/-]", new [] { "feature[/-]", "feature(s)?[/-]" }},
108+
{ "releases?[/-]", new [] { "release[/-]" }},
109+
{ "dev(elop)?(ment)?$", new [] { "develop" }}
127110
};
128111

129112
foreach (var mapping in dict)
@@ -203,12 +186,12 @@ public static void Verify(GitPreparer gitPreparer, IFileSystem fileSystem)
203186
var workingDirectory = gitPreparer.WorkingDirectory;
204187
var projectRootDirectory = gitPreparer.GetProjectRootDirectory();
205188

206-
Verify(workingDirectory, projectRootDirectory, fileSystem);
189+
Verify(workingDirectory,projectRootDirectory, fileSystem);
207190
}
208191

209192
public static void Verify(string workingDirectory, string projectRootDirectory, IFileSystem fileSystem)
210193
{
211-
if (fileSystem.PathsEqual(workingDirectory, projectRootDirectory))
194+
if(fileSystem.PathsEqual(workingDirectory, projectRootDirectory))
212195
{
213196
WarnAboutObsoleteConfigFile(workingDirectory, fileSystem);
214197
return;
@@ -217,11 +200,6 @@ public static void Verify(string workingDirectory, string projectRootDirectory,
217200
WarnAboutObsoleteConfigFile(workingDirectory, fileSystem);
218201
WarnAboutObsoleteConfigFile(projectRootDirectory, fileSystem);
219202

220-
WarnAboutAmbigousConfigFileSelection(workingDirectory, projectRootDirectory, fileSystem);
221-
}
222-
223-
private static void WarnAboutAmbigousConfigFileSelection(string workingDirectory, string projectRootDirectory, IFileSystem fileSystem)
224-
{
225203
var workingConfigFile = GetConfigFilePath(workingDirectory, fileSystem);
226204
var projectRootConfigFile = GetConfigFilePath(projectRootDirectory, fileSystem);
227205

@@ -302,4 +280,4 @@ public static void Init(string workingDirectory, IFileSystem fileSystem, IConsol
302280
}
303281
}
304282
}
305-
}
283+
}

src/GitVersionCore/ExecuteCore.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
namespace GitVersion
22
{
3-
using GitVersion.Helpers;
4-
using LibGit2Sharp;
53
using System;
64
using System.ComponentModel;
75
using System.Linq;
6+
using GitVersion.Helpers;
7+
8+
using LibGit2Sharp;
89

910
public class ExecuteCore
1011
{
@@ -14,7 +15,7 @@ public class ExecuteCore
1415
public ExecuteCore(IFileSystem fileSystem)
1516
{
1617
if (fileSystem == null) throw new ArgumentNullException("fileSystem");
17-
18+
1819
this.fileSystem = fileSystem;
1920
gitVersionCache = new GitVersionCache(fileSystem);
2021
}
@@ -48,16 +49,10 @@ public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicReposi
4849
throw new Exception(string.Format("Failed to prepare or find the .git directory in path '{0}'.", workingDirectory));
4950
}
5051

51-
if (overrideConfig != null)
52-
{
53-
var overridenVersionVariables = ExecuteInternal(targetBranch, commitId, gitPreparer, buildServer, overrideConfig: overrideConfig);
54-
return overridenVersionVariables;
55-
}
56-
5752
var versionVariables = gitVersionCache.LoadVersionVariablesFromDiskCache(gitPreparer);
5853
if (versionVariables == null)
5954
{
60-
versionVariables = ExecuteInternal(targetBranch, commitId, gitPreparer, buildServer);
55+
versionVariables = ExecuteInternal(targetBranch, commitId, gitPreparer, buildServer, overrideConfig: overrideConfig);
6156
gitVersionCache.WriteVariablesToDiskCache(gitPreparer, versionVariables);
6257
}
6358

@@ -97,7 +92,7 @@ VersionVariables ExecuteInternal(string targetBranch, string commitId, GitPrepar
9792
gitPreparer.Initialise(buildServer != null, ResolveCurrentBranch(buildServer, targetBranch, gitPreparer.IsDynamicGitRepository));
9893

9994
var versionFinder = new GitVersionFinder();
100-
var configuration = ConfigurationProvider.Provide(gitPreparer, fileSystem, overrideConfig: overrideConfig);
95+
var configuration = ConfigurationProvider.Provide(gitPreparer, fileSystem, overrideConfig: overrideConfig);
10196

10297
return gitPreparer.WithRepository(repo =>
10398
{

src/GitVersionCore/GitVersionCache.cs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
namespace GitVersion
22
{
3-
using GitVersion.Helpers;
43
using System;
54
using System.Collections.Generic;
65
using System.IO;
76
using System.Linq;
87
using System.Security.Cryptography;
98
using System.Text;
9+
using GitVersion.Helpers;
10+
using LibGit2Sharp;
1011
using YamlDotNet.Serialization;
1112

1213
public class GitVersionCache
@@ -46,7 +47,7 @@ public void WriteVariablesToDiskCache(GitPreparer gitPreparer, VersionVariables
4647
private string PrepareCacheDirectory(GitPreparer gitPreparer)
4748
{
4849
var gitDir = gitPreparer.GetDotGitDirectory();
49-
50+
5051
// If the cacheDir already exists, CreateDirectory just won't do anything (it won't fail). @asbjornu
5152
var cacheDir = GetCacheDir(gitDir);
5253
fileSystem.CreateDirectory(cacheDir);
@@ -61,52 +62,51 @@ public VersionVariables LoadVersionVariablesFromDiskCache(GitPreparer gitPrepare
6162
var cacheDir = PrepareCacheDirectory(gitPreparer);
6263

6364
var cacheFileName = GetCacheFileName(GetKey(gitPreparer), cacheDir);
64-
if (!fileSystem.Exists(cacheFileName))
65-
{
66-
Logger.WriteInfo("Cache file " + cacheFileName + " not found.");
67-
return null;
68-
}
69-
70-
using (Logger.IndentLog("Deserializing version variables from cache file " + cacheFileName))
65+
VersionVariables vv = null;
66+
if (fileSystem.Exists(cacheFileName))
7167
{
72-
try
68+
using (Logger.IndentLog("Deserializing version variables from cache file " + cacheFileName))
7369
{
74-
var loadedVariables = VersionVariables.FromFile(cacheFileName, fileSystem);
75-
return loadedVariables;
76-
}
77-
catch (Exception ex)
78-
{
79-
Logger.WriteWarning("Unable to read cache file " + cacheFileName + ", deleting it.");
80-
Logger.WriteInfo(ex.ToString());
8170
try
8271
{
83-
fileSystem.Delete(cacheFileName);
72+
vv = VersionVariables.FromFile(cacheFileName, fileSystem);
8473
}
85-
catch (Exception deleteEx)
74+
catch (Exception ex)
8675
{
87-
Logger.WriteWarning(string.Format("Unable to delete corrupted version cache file {0}. Got {1} exception.", cacheFileName, deleteEx.GetType().FullName));
76+
Logger.WriteWarning("Unable to read cache file " + cacheFileName + ", deleting it.");
77+
Logger.WriteInfo(ex.ToString());
78+
try
79+
{
80+
fileSystem.Delete(cacheFileName);
81+
}
82+
catch (Exception deleteEx)
83+
{
84+
Logger.WriteWarning(string.Format("Unable to delete corrupted version cache file {0}. Got {1} exception.", cacheFileName, deleteEx.GetType().FullName));
85+
}
8886
}
89-
90-
return null;
9187
}
9288
}
89+
else
90+
{
91+
Logger.WriteInfo("Cache file " + cacheFileName + " not found.");
92+
}
93+
94+
return vv;
9395
}
9496
}
9597

9698
string GetKey(GitPreparer gitPreparer)
9799
{
98-
var dotGitDirectory = gitPreparer.GetDotGitDirectory();
100+
var gitDir = gitPreparer.GetDotGitDirectory();
99101

100102
// Maybe using timestamp in .git/refs directory is enough?
101-
var lastGitRefsChangedTicks = fileSystem.GetLastDirectoryWrite(Path.Combine(dotGitDirectory, "refs"));
103+
var ticks = fileSystem.GetLastDirectoryWrite(Path.Combine(gitDir, "refs"));
102104

103-
// will return the same hash even when config file will be moved
104-
// from workingDirectory to rootProjectDirectory. It's OK. Config essentially is the same.
105-
var configFilePath = ConfigurationProvider.SelectConfigFilePath(gitPreparer, fileSystem);
106-
var configFileContent = fileSystem.Exists(configFilePath) ? fileSystem.ReadAllText(configFilePath) : null;
107-
var configFileHash = configFileContent != null ? GetHash(configFileContent) : null;
105+
var configPath = ConfigurationProvider.SelectConfigFilePath(gitPreparer, fileSystem);
106+
var configText = fileSystem.Exists(configPath) ? fileSystem.ReadAllText(configPath) : null;
107+
var configHash = configText != null ? GetHash(configText) : null;
108108

109-
return gitPreparer.WithRepository(repo => string.Join(":", dotGitDirectory, repo.Head.CanonicalName, repo.Head.Tip.Sha, lastGitRefsChangedTicks, configFileHash));
109+
return gitPreparer.WithRepository(repo => string.Join(":", gitDir, repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks, configHash));
110110
}
111111

112112
static string GetCacheFileName(string key, string cacheDir)
@@ -131,4 +131,4 @@ static string GetHash(string textToHash)
131131
}
132132
}
133133
}
134-
}
134+
}

src/GitVersionExe/ArgumentParser.cs

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -263,43 +263,25 @@ public static Arguments ParseArguments(List<string> commandLineArguments)
263263

264264
if (arguments.UpdateAssemblyInfoFileName.Count > 1 && arguments.EnsureAssemblyInfo)
265265
{
266-
throw new WarningException("Can't specify multiple assembly info files when using /ensureassemblyinfo switch, either use a single assembly info file or do not specify /ensureassemblyinfo and create assembly info files manually");
266+
throw new WarningException("Can't specify multiple assembly info files when using -ensureassemblyinfo switch, either use a single assembly info file or do not specify -ensureassemblyinfo and create assembly info files manually");
267267
}
268268
continue;
269269
}
270270

271271
if (name.IsSwitch("overrideconfig"))
272272
{
273-
var keyValueOptions = value.Split(';');
274-
if (keyValueOptions.Length == 0)
275-
{
276-
continue;
277-
}
278-
279-
arguments.HasOverrideConfig = true;
280-
281-
if (keyValueOptions.Length > 1)
273+
foreach (var item in value.Split(';'))
282274
{
283-
throw new WarningException("Can't specify multiple /overrideconfig options: currently supported only 'tag-prefix' option");
284-
}
285-
286-
// key=value
287-
foreach (var keyValueOption in keyValueOptions)
288-
{
289-
var keyAndValue = keyValueOption.Split('=');
290-
if (keyAndValue.Length > 1)
291-
{
292-
throw new WarningException(string.Format("Could not parse /overrideconfig option: {0}. Ensure it is in format 'key=value'", keyValueOption));
293-
}
275+
var configOverride = item.Split('=');
294276

295-
var optionKey = keyAndValue[0].ToLowerInvariant();
296-
switch (optionKey)
277+
switch (configOverride[0])
297278
{
298279
case "tag-prefix":
299-
arguments.OverrideConfig.TagPrefix = keyAndValue[1];
280+
if (1 < configOverride.Length)
281+
{
282+
arguments.OverrideConfig.TagPrefix = configOverride[1];
283+
}
300284
break;
301-
default:
302-
throw new WarningException(string.Format("Could not parse /overrideconfig option: {0}. Currently supported only 'tag-prefix' option", optionKey));
303285
}
304286
}
305287

src/GitVersionExe/Arguments.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public Arguments()
1515
public Authentication Authentication;
1616

1717
public Config OverrideConfig;
18-
public bool HasOverrideConfig { get; set; }
1918

2019
public string TargetPath;
2120

@@ -31,7 +30,7 @@ public Arguments()
3130
public string ShowVariable;
3231

3332
public OutputType Output;
34-
33+
3534
public string Proj;
3635
public string ProjArgs;
3736
public string Exec;

src/GitVersionExe/HelpWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ path The directory containing .git. If not defined current directory
2424
/showvariable Used in conjuntion with /output json, will output just a particular variable.
2525
eg /output json /showvariable SemVer - will output `1.2.3+beta.4`
2626
/l Path to logfile.
27-
/showconfig Outputs the effective GitVersion config (defaults + custom from GitVersion.yml) in yaml format
27+
/showconfig Outputs the effective GitVersion config (defaults + custom from GitVersion.yaml) in yaml format
2828
/overrideconfig Overrides GitVersion config values inline (semicolon-separated key value pairs e.g. /overrideconfig:tag-prefix=Foo)
2929
Currently supported config overrides: tag-prefix
3030

src/GitVersionExe/SpecifiedArgumentRunner.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
namespace GitVersion
22
{
3-
using GitTools;
4-
using GitVersion.Helpers;
53
using System;
64
using System.Collections.Generic;
75
using System.Linq;
6+
using GitTools;
7+
using GitVersion.Helpers;
88
using WarningException = System.ComponentModel.WarningException;
99

1010
class SpecifiedArgumentRunner
1111
{
1212
private static readonly bool runningOnMono = Type.GetType("Mono.Runtime") != null;
13-
public static readonly string BuildTool = runningOnMono ? "xbuild" : @"c:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe";
13+
public static readonly string BuildTool = runningOnMono? "xbuild" : @"c:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe";
1414

1515
public static void Run(Arguments arguments, IFileSystem fileSystem)
1616
{
@@ -23,7 +23,7 @@ public static void Run(Arguments arguments, IFileSystem fileSystem)
2323
var dynamicRepositoryLocation = arguments.DynamicRepositoryLocation;
2424
var targetBranch = arguments.TargetBranch;
2525
var commitId = arguments.CommitId;
26-
var overrideConfig = arguments.HasOverrideConfig ? arguments.OverrideConfig : null;
26+
var overrideConfig = arguments.OverrideConfig;
2727

2828
var executeCore = new ExecuteCore(fileSystem);
2929
var variables = executeCore.ExecuteGitVersion(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId, overrideConfig: overrideConfig);

0 commit comments

Comments
 (0)