Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/input/docs/usage/cli/arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ GitVersion [path]
E.g. /output json /format {SemVer} - will output `1.2.3+beta.4`
/output json /format {Major}.{Minor} - will output `1.2`
/l Path to logfile.
/config Path to config file (defaults to GitVersion.yml)
/config Path to config file (defaults to GitVersion.yml or GitVersion.yaml)
/showconfig Outputs the effective GitVersion config (defaults + custom
from GitVersion.yml) in yaml format
from GitVersion.yml or GitVersion.yaml) in yaml format
/overrideconfig Overrides GitVersion config values inline (semicolon-
separated key value pairs e.g. /overrideconfig
label-prefix=Foo)
Expand Down Expand Up @@ -103,7 +103,7 @@ gitversion init Configuration utility for gitversion

## Override config

`/overrideconfig [key=value]` will override appropriate `key` from 'GitVersion.yml'.
`/overrideconfig [key=value]` will override appropriate `key` from 'GitVersion.yml' or 'GitVersion.yaml'.

To specify multiple options add multiple `/overrideconfig [key=value]` entries:
`/overrideconfig key1=value1 /overrideconfig key2=value2`.
Expand Down Expand Up @@ -135,7 +135,7 @@ Following options are supported:

Read more about [Configuration](/docs/reference/configuration).

Using `override-config` on the command line will not change the contents of the config file `GitVersion.yml`.
Using `override-config` on the command line will not change the contents of the config file `GitVersion.yml` or `GitVersion.yaml`.

### Example: How to override configuration option 'label-prefix' to use prefix 'custom'

Expand Down
5 changes: 4 additions & 1 deletion src/GitVersion.App/GitVersionExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ private bool HandleNonMainCommand(GitVersionOptions gitVersionOptions, out int e
this.log.Info("Working directory: " + workingDirectory);
}

this.configurationFileLocator.Verify(gitVersionOptions, this.repositoryInfo);
if (gitVersionOptions.RepositoryInfo.TargetUrl.IsNullOrWhiteSpace())
{
this.configurationFileLocator.Verify(workingDirectory, this.repositoryInfo.ProjectRootDirectory);
}

if (gitVersionOptions.Init)
{
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.App/OverrideConfigurationOptionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class OverrideConfigurationOptionParser
/// </summary>
/// <returns></returns>
/// <remarks>
/// Lookup keys are created from <see cref="System.Text.Json.Serialization.JsonPropertyNameAttribute"/> to match 'GitVersion.yml'
/// Lookup keys are created from <see cref="System.Text.Json.Serialization.JsonPropertyNameAttribute"/> to match 'GitVersion.yml' or 'GitVersion.yaml' file
/// options as close as possible.
/// </remarks>
private static ILookup<string?, PropertyInfo> GetSupportedProperties() => typeof(GitVersionConfiguration).GetProperties(BindingFlags.Public | BindingFlags.Instance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void GetCurrentBranchShouldHandleBranches()
var result = this.buildServer.GetCurrentBranch(false);

// Assert
result.ShouldBe($"refs/heads/feature/my-work");
result.ShouldBe("refs/heads/feature/my-work");
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public void Setup()
}

[TestCase(ConfigurationFileLocator.DefaultFileName, ConfigurationFileLocator.DefaultFileName)]
[TestCase(ConfigurationFileLocator.DefaultFileName, ConfigurationFileLocator.DefaultAlternativeFileName)]
[TestCase(ConfigurationFileLocator.DefaultAlternativeFileName, ConfigurationFileLocator.DefaultFileName)]
[TestCase(ConfigurationFileLocator.DefaultAlternativeFileName, ConfigurationFileLocator.DefaultAlternativeFileName)]
public void ThrowsExceptionOnAmbiguousConfigFileLocation(string repoConfigFile, string workingConfigFile)
{
var repositoryConfigFilePath = SetupConfigFileContent(string.Empty, repoConfigFile, this.repoPath);
Expand All @@ -50,16 +53,17 @@ public void ThrowsExceptionOnAmbiguousConfigFileLocation(string repoConfigFile,
exception.Message.ShouldBe(expectedMessage);
}

[Test]
public void NoWarnOnGitVersionYmlFile()
[TestCase(ConfigurationFileLocator.DefaultFileName)]
[TestCase(ConfigurationFileLocator.DefaultAlternativeFileName)]
public void NoWarnOnGitVersionYmlFile(string configurationFile)
{
SetupConfigFileContent(string.Empty, ConfigurationFileLocator.DefaultFileName, this.repoPath);
SetupConfigFileContent(string.Empty, configurationFile, this.repoPath);

Should.NotThrow(() => this.configurationProvider.ProvideInternal(this.repoPath));
Should.NotThrow(() => this.configurationProvider.ProvideForDirectory(this.repoPath));
}

[Test]
public void NoWarnOnNoGitVersionYmlFile() => Should.NotThrow(() => this.configurationProvider.ProvideInternal(this.repoPath));
public void NoWarnOnNoGitVersionYmlFile() => Should.NotThrow(() => this.configurationProvider.ProvideForDirectory(this.repoPath));

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

private string repoPath;
private string workingPath;
Expand All @@ -84,7 +89,7 @@ public class NamedConfigurationFileLocatorTests : TestBase
[SetUp]
public void Setup()
{
this.gitVersionOptions = new GitVersionOptions { ConfigurationInfo = { ConfigurationFile = "my-config.yaml" } };
this.gitVersionOptions = new GitVersionOptions { ConfigurationInfo = { ConfigurationFile = myConfigYaml } };
this.repoPath = DefaultRepoPath;
this.workingPath = DefaultWorkingPath;

Expand Down Expand Up @@ -167,7 +172,7 @@ public void NoWarnOnCustomYmlFile()

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

configurationProvider.ProvideInternal(this.repoPath);
configurationProvider.ProvideForDirectory(this.repoPath);
stringLogger.Length.ShouldBe(0);
}

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

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

configurationProvider.ProvideInternal(this.repoPath);
configurationProvider.ProvideForDirectory(this.repoPath);
stringLogger.Length.ShouldBe(0);
}

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

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

var workingPathFileConfig = PathHelper.Combine(this.workingPath, this.gitVersionOptions.ConfigurationInfo.ConfigurationFile);
var repoPathFileConfig = PathHelper.Combine(this.repoPath, this.gitVersionOptions.ConfigurationInfo.ConfigurationFile);
var configurationFile = this.gitVersionOptions.ConfigurationInfo.ConfigurationFile;
var workingPathFileConfig = PathHelper.Combine(this.workingPath, configurationFile);
var repoPathFileConfig = PathHelper.Combine(this.repoPath, configurationFile);
var expectedMessage = $"The configuration file was not found at '{workingPathFileConfig}' or '{repoPathFileConfig}'";
exception.Message.ShouldBe(expectedMessage);
}

private string SetupConfigFileContent(string text, string? fileName = null, string? path = null)
{
if (fileName.IsNullOrEmpty()) fileName = this.configFileLocator.FilePath;
if (fileName.IsNullOrEmpty())
{
fileName = gitVersionOptions.ConfigurationInfo.ConfigurationFile;
}
var filePath = fileName;
if (!path.IsNullOrEmpty())
filePath = PathHelper.Combine(path, filePath);
this.fileSystem.WriteAllText(filePath, text);
return filePath;
return filePath!;
}

private static IServiceProvider GetServiceProvider(GitVersionOptions gitVersionOptions, ILog? log = null) =>
Expand Down
Loading