Skip to content

Commit 2189b7c

Browse files
committed
Merge pull request #829 from labmonkey42/master
Implemented configuration override for #826
2 parents 84ffe82 + 6a35384 commit 2189b7c

File tree

6 files changed

+41
-6
lines changed

6 files changed

+41
-6
lines changed

src/GitVersionCore/Configuration/ConfigurationProvider.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ public class ConfigurationProvider
1111
{
1212
internal const string DefaultTagPrefix = "[vV]";
1313

14-
public static Config Provide(string workingDirectory, IFileSystem fileSystem, bool applyDefaults = true)
14+
public static Config Provide(string workingDirectory, IFileSystem fileSystem, bool applyDefaults = true, Config overrideConfig = null)
1515
{
1616
var readConfig = ReadConfig(workingDirectory, fileSystem);
1717
if (applyDefaults)
1818
ApplyDefaultsTo(readConfig);
19+
if (null != overrideConfig)
20+
ApplyOverridesTo(readConfig, overrideConfig);
1921
return readConfig;
2022
}
2123

@@ -61,6 +63,11 @@ public static void ApplyDefaultsTo(Config config)
6163
}
6264
}
6365

66+
public static void ApplyOverridesTo(Config config, Config overrideConfig)
67+
{
68+
config.TagPrefix = string.IsNullOrWhiteSpace(overrideConfig.TagPrefix) ? config.TagPrefix : overrideConfig.TagPrefix;
69+
}
70+
6471
static void MigrateBranches(Config config)
6572
{
6673
// Map of current names and previous names

src/GitVersionCore/ExecuteCore.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public ExecuteCore(IFileSystem fileSystem)
2020
gitVersionCache = new GitVersionCache(fileSystem);
2121
}
2222

23-
public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId)
23+
public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId, Config overrideConfig = null)
2424
{
2525
// Normalise if we are running on build server
2626
var applicableBuildServers = BuildServerList.GetApplicableBuildServers();
@@ -54,7 +54,7 @@ public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicReposi
5454
var versionVariables = gitVersionCache.LoadVersionVariablesFromDiskCache(repo, dotGitDirectory);
5555
if (versionVariables == null)
5656
{
57-
versionVariables = ExecuteInternal(targetBranch, commitId, repo, gitPreparer, projectRoot, buildServer);
57+
versionVariables = ExecuteInternal(targetBranch, commitId, repo, gitPreparer, projectRoot, buildServer, overrideConfig: overrideConfig);
5858
gitVersionCache.WriteVariablesToDiskCache(repo, dotGitDirectory, versionVariables);
5959
}
6060

@@ -90,12 +90,12 @@ static string ResolveCurrentBranch(IBuildServer buildServer, string targetBranch
9090
return currentBranch;
9191
}
9292

93-
VersionVariables ExecuteInternal(string targetBranch, string commitId, IRepository repo, GitPreparer gitPreparer, string projectRoot, IBuildServer buildServer)
93+
VersionVariables ExecuteInternal(string targetBranch, string commitId, IRepository repo, GitPreparer gitPreparer, string projectRoot, IBuildServer buildServer, Config overrideConfig = null)
9494
{
9595
gitPreparer.Initialise(buildServer != null, ResolveCurrentBranch(buildServer, targetBranch, gitPreparer.IsDynamicGitRepository));
9696

9797
var versionFinder = new GitVersionFinder();
98-
var configuration = ConfigurationProvider.Provide(projectRoot, fileSystem);
98+
var configuration = ConfigurationProvider.Provide(projectRoot, fileSystem, overrideConfig: overrideConfig);
9999

100100
var gitVersionContext = new GitVersionContext(repo, configuration, commitId : commitId);
101101
var semanticVersion = versionFinder.FindVersion(gitVersionContext);

src/GitVersionExe/ArgumentParser.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,28 @@ public static Arguments ParseArguments(List<string> commandLineArguments)
285285
continue;
286286
}
287287

288+
if (IsSwitch("overrideconfig", name))
289+
{
290+
foreach (var item in value.Split(';'))
291+
{
292+
var configOverride = item.Split('=');
293+
294+
switch (configOverride[0])
295+
{
296+
case "tag-prefix":
297+
if (1 < configOverride.Length)
298+
{
299+
arguments.OverrideConfig.TagPrefix = configOverride[1];
300+
}
301+
break;
302+
default:
303+
break;
304+
}
305+
}
306+
307+
continue;
308+
}
309+
288310
throw new WarningException(string.Format("Could not parse command line parameter '{0}'.", name));
289311
}
290312

src/GitVersionExe/Arguments.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ public class Arguments
77
public Arguments()
88
{
99
Authentication = new Authentication();
10+
OverrideConfig = new Config();
1011
Output = OutputType.Json;
1112
UpdateAssemblyInfoFileName = new HashSet<string>();
1213
}
1314

1415
public Authentication Authentication;
1516

17+
public Config OverrideConfig;
18+
1619
public string TargetPath;
1720

1821
public string TargetUrl;

src/GitVersionExe/HelpWriter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ path The directory containing .git. If not defined current directory
2525
eg /output json /showvariable SemVer - will output `1.2.3+beta.4`
2626
/l Path to logfile.
2727
/showconfig Outputs the effective GitVersion config (defaults + custom from GitVersion.yaml) in yaml format
28+
/overrideconfig Overrides GitVersion config values inline (semicolon-separated key value pairs e.g. /overrideconfig:tag-prefix=Foo)
29+
Currently supported config overrides: tag-prefix
2830
2931
# AssemblyInfo updating
3032
/updateassemblyinfo

src/GitVersionExe/SpecifiedArgumentRunner.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ public static void Run(Arguments arguments, IFileSystem fileSystem)
2020
var dynamicRepositoryLocation = arguments.DynamicRepositoryLocation;
2121
var targetBranch = arguments.TargetBranch;
2222
var commitId = arguments.CommitId;
23+
var overrideConfig = arguments.OverrideConfig;
2324

2425
var executeCore = new ExecuteCore(fileSystem);
25-
var variables = executeCore.ExecuteGitVersion(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId);
26+
var variables = executeCore.ExecuteGitVersion(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId, overrideConfig: overrideConfig);
2627

2728
if (arguments.Output == OutputType.BuildServer)
2829
{

0 commit comments

Comments
 (0)