Skip to content

Commit 764ee79

Browse files
committed
fixed bug: /overrideconfig was ignored in caching results
When /overrideconfig presents version must be calculated explicitly without saving in cache.
1 parent 02036f9 commit 764ee79

File tree

4 files changed

+43
-19
lines changed

4 files changed

+43
-19
lines changed

src/GitVersionCore/ExecuteCore.cs

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

109
public class ExecuteCore
1110
{
@@ -15,7 +14,7 @@ public class ExecuteCore
1514
public ExecuteCore(IFileSystem fileSystem)
1615
{
1716
if (fileSystem == null) throw new ArgumentNullException("fileSystem");
18-
17+
1918
this.fileSystem = fileSystem;
2019
gitVersionCache = new GitVersionCache(fileSystem);
2120
}
@@ -49,10 +48,16 @@ public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicReposi
4948
throw new Exception(string.Format("Failed to prepare or find the .git directory in path '{0}'.", workingDirectory));
5049
}
5150

51+
if (overrideConfig != null)
52+
{
53+
var overridenVersionVariables = ExecuteInternal(targetBranch, commitId, gitPreparer, buildServer, overrideConfig: overrideConfig);
54+
return overridenVersionVariables;
55+
}
56+
5257
var versionVariables = gitVersionCache.LoadVersionVariablesFromDiskCache(gitPreparer);
5358
if (versionVariables == null)
5459
{
55-
versionVariables = ExecuteInternal(targetBranch, commitId, gitPreparer, buildServer, overrideConfig: overrideConfig);
60+
versionVariables = ExecuteInternal(targetBranch, commitId, gitPreparer, buildServer);
5661
gitVersionCache.WriteVariablesToDiskCache(gitPreparer, versionVariables);
5762
}
5863

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

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

97102
return gitPreparer.WithRepository(repo =>
98103
{

src/GitVersionExe/ArgumentParser.cs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,25 +263,43 @@ 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-
foreach (var item in value.Split(';'))
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)
274282
{
275-
var configOverride = item.Split('=');
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+
}
276294

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

src/GitVersionExe/Arguments.cs

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

1717
public Config OverrideConfig;
18+
public bool HasOverrideConfig { get; set; }
1819

1920
public string TargetPath;
2021

@@ -30,7 +31,7 @@ public Arguments()
3031
public string ShowVariable;
3132

3233
public OutputType Output;
33-
34+
3435
public string Proj;
3536
public string ProjArgs;
3637
public string Exec;

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;
35
using System;
46
using System.Collections.Generic;
57
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.OverrideConfig;
26+
var overrideConfig = arguments.HasOverrideConfig ? arguments.OverrideConfig : null;
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)