Skip to content

Commit 37be60e

Browse files
committed
#3420 - refactored ConfigurationFileLocator, add "GitVersion.yaml" as accepted
1 parent ed6c213 commit 37be60e

File tree

20 files changed

+218
-212
lines changed

20 files changed

+218
-212
lines changed

docs/input/docs/usage/cli/arguments.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ GitVersion [path]
4242
E.g. /output json /format {SemVer} - will output `1.2.3+beta.4`
4343
/output json /format {Major}.{Minor} - will output `1.2`
4444
/l Path to logfile.
45-
/config Path to config file (defaults to GitVersion.yml)
45+
/config Path to config file (defaults to GitVersion.yml or GitVersion.yaml)
4646
/showconfig Outputs the effective GitVersion config (defaults + custom
47-
from GitVersion.yml) in yaml format
47+
from GitVersion.yml or GitVersion.yaml) in yaml format
4848
/overrideconfig Overrides GitVersion config values inline (semicolon-
4949
separated key value pairs e.g. /overrideconfig
5050
label-prefix=Foo)
@@ -103,7 +103,7 @@ gitversion init Configuration utility for gitversion
103103
104104
## Override config
105105
106-
`/overrideconfig [key=value]` will override appropriate `key` from 'GitVersion.yml'.
106+
`/overrideconfig [key=value]` will override appropriate `key` from 'GitVersion.yml' or 'GitVersion.yaml'.
107107
108108
To specify multiple options add multiple `/overrideconfig [key=value]` entries:
109109
`/overrideconfig key1=value1 /overrideconfig key2=value2`.
@@ -135,7 +135,7 @@ Following options are supported:
135135
136136
Read more about [Configuration](/docs/reference/configuration).
137137
138-
Using `override-config` on the command line will not change the contents of the config file `GitVersion.yml`.
138+
Using `override-config` on the command line will not change the contents of the config file `GitVersion.yml` or `GitVersion.yaml`.
139139
140140
### Example: How to override configuration option 'label-prefix' to use prefix 'custom'
141141

src/GitVersion.App/GitVersionExecutor.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ private bool HandleNonMainCommand(GitVersionOptions gitVersionOptions, out int e
143143
this.log.Info("Working directory: " + workingDirectory);
144144
}
145145

146-
this.configurationFileLocator.Verify(gitVersionOptions, this.repositoryInfo);
146+
if (gitVersionOptions.RepositoryInfo.TargetUrl.IsNullOrWhiteSpace())
147+
{
148+
this.configurationFileLocator.Verify(workingDirectory, this.repositoryInfo.ProjectRootDirectory);
149+
}
147150

148151
if (gitVersionOptions.Init)
149152
{

src/GitVersion.App/OverrideConfigurationOptionParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal class OverrideConfigurationOptionParser
1717
/// </summary>
1818
/// <returns></returns>
1919
/// <remarks>
20-
/// Lookup keys are created from <see cref="System.Text.Json.Serialization.JsonPropertyNameAttribute"/> to match 'GitVersion.yml'
20+
/// Lookup keys are created from <see cref="System.Text.Json.Serialization.JsonPropertyNameAttribute"/> to match 'GitVersion.yml' or 'GitVersion.yaml' file
2121
/// options as close as possible.
2222
/// </remarks>
2323
private static ILookup<string?, PropertyInfo> GetSupportedProperties() => typeof(GitVersionConfiguration).GetProperties(BindingFlags.Public | BindingFlags.Instance)

src/GitVersion.BuildAgents.Tests/Agents/BitBucketPipelinesTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void GetCurrentBranchShouldHandleBranches()
8282
var result = this.buildServer.GetCurrentBranch(false);
8383

8484
// Assert
85-
result.ShouldBe($"refs/heads/feature/my-work");
85+
result.ShouldBe("refs/heads/feature/my-work");
8686
}
8787

8888
[Test]

src/GitVersion.Core.Tests/Configuration/ConfigurationFileLocatorTests.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public void Setup()
3939
}
4040

4141
[TestCase(ConfigurationFileLocator.DefaultFileName, ConfigurationFileLocator.DefaultFileName)]
42+
[TestCase(ConfigurationFileLocator.DefaultFileName, ConfigurationFileLocator.DefaultAlternativeFileName)]
43+
[TestCase(ConfigurationFileLocator.DefaultAlternativeFileName, ConfigurationFileLocator.DefaultFileName)]
44+
[TestCase(ConfigurationFileLocator.DefaultAlternativeFileName, ConfigurationFileLocator.DefaultAlternativeFileName)]
4245
public void ThrowsExceptionOnAmbiguousConfigFileLocation(string repoConfigFile, string workingConfigFile)
4346
{
4447
var repositoryConfigFilePath = SetupConfigFileContent(string.Empty, repoConfigFile, this.repoPath);
@@ -50,16 +53,17 @@ public void ThrowsExceptionOnAmbiguousConfigFileLocation(string repoConfigFile,
5053
exception.Message.ShouldBe(expectedMessage);
5154
}
5255

53-
[Test]
54-
public void NoWarnOnGitVersionYmlFile()
56+
[TestCase(ConfigurationFileLocator.DefaultFileName)]
57+
[TestCase(ConfigurationFileLocator.DefaultAlternativeFileName)]
58+
public void NoWarnOnGitVersionYmlFile(string configurationFile)
5559
{
56-
SetupConfigFileContent(string.Empty, ConfigurationFileLocator.DefaultFileName, this.repoPath);
60+
SetupConfigFileContent(string.Empty, configurationFile, this.repoPath);
5761

58-
Should.NotThrow(() => this.configurationProvider.ProvideInternal(this.repoPath));
62+
Should.NotThrow(() => this.configurationProvider.ProvideForDirectory(this.repoPath));
5963
}
6064

6165
[Test]
62-
public void NoWarnOnNoGitVersionYmlFile() => Should.NotThrow(() => this.configurationProvider.ProvideInternal(this.repoPath));
66+
public void NoWarnOnNoGitVersionYmlFile() => Should.NotThrow(() => this.configurationProvider.ProvideForDirectory(this.repoPath));
6367

6468
private string SetupConfigFileContent(string text, string fileName, string path)
6569
{
@@ -74,6 +78,7 @@ public class NamedConfigurationFileLocatorTests : TestBase
7478
{
7579
private const string DefaultRepoPath = @"c:\MyGitRepo";
7680
private const string DefaultWorkingPath = @"c:\MyGitRepo\Working";
81+
private const string myConfigYaml = "my-config.yaml";
7782

7883
private string repoPath;
7984
private string workingPath;
@@ -84,7 +89,7 @@ public class NamedConfigurationFileLocatorTests : TestBase
8489
[SetUp]
8590
public void Setup()
8691
{
87-
this.gitVersionOptions = new GitVersionOptions { ConfigurationInfo = { ConfigurationFile = "my-config.yaml" } };
92+
this.gitVersionOptions = new GitVersionOptions { ConfigurationInfo = { ConfigurationFile = myConfigYaml } };
8893
this.repoPath = DefaultRepoPath;
8994
this.workingPath = DefaultWorkingPath;
9095

@@ -167,7 +172,7 @@ public void NoWarnOnCustomYmlFile()
167172

168173
var configurationProvider = (ConfigurationProvider)sp.GetRequiredService<IConfigurationProvider>();
169174

170-
configurationProvider.ProvideInternal(this.repoPath);
175+
configurationProvider.ProvideForDirectory(this.repoPath);
171176
stringLogger.Length.ShouldBe(0);
172177
}
173178

@@ -188,7 +193,7 @@ public void NoWarnOnCustomYmlFileOutsideRepoPath()
188193

189194
var configurationProvider = (ConfigurationProvider)sp.GetRequiredService<IConfigurationProvider>();
190195

191-
configurationProvider.ProvideInternal(this.repoPath);
196+
configurationProvider.ProvideForDirectory(this.repoPath);
192197
stringLogger.Length.ShouldBe(0);
193198
}
194199

@@ -200,20 +205,24 @@ public void ThrowsExceptionOnCustomYmlFileDoesNotExist()
200205

201206
var exception = Should.Throw<WarningException>(() => this.configFileLocator.Verify(this.workingPath, this.repoPath));
202207

203-
var workingPathFileConfig = PathHelper.Combine(this.workingPath, this.gitVersionOptions.ConfigurationInfo.ConfigurationFile);
204-
var repoPathFileConfig = PathHelper.Combine(this.repoPath, this.gitVersionOptions.ConfigurationInfo.ConfigurationFile);
208+
var configurationFile = this.gitVersionOptions.ConfigurationInfo.ConfigurationFile;
209+
var workingPathFileConfig = PathHelper.Combine(this.workingPath, configurationFile);
210+
var repoPathFileConfig = PathHelper.Combine(this.repoPath, configurationFile);
205211
var expectedMessage = $"The configuration file was not found at '{workingPathFileConfig}' or '{repoPathFileConfig}'";
206212
exception.Message.ShouldBe(expectedMessage);
207213
}
208214

209215
private string SetupConfigFileContent(string text, string? fileName = null, string? path = null)
210216
{
211-
if (fileName.IsNullOrEmpty()) fileName = this.configFileLocator.FilePath;
217+
if (fileName.IsNullOrEmpty())
218+
{
219+
fileName = gitVersionOptions.ConfigurationInfo.ConfigurationFile;
220+
}
212221
var filePath = fileName;
213222
if (!path.IsNullOrEmpty())
214223
filePath = PathHelper.Combine(path, filePath);
215224
this.fileSystem.WriteAllText(filePath, text);
216-
return filePath;
225+
return filePath!;
217226
}
218227

219228
private static IServiceProvider GetServiceProvider(GitVersionOptions gitVersionOptions, ILog? log = null) =>

0 commit comments

Comments
 (0)