Skip to content

Config filename case insensitive #4452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2025
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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

# top-most EditorConfig file
root = true
charset = utf-8

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

Expand Down
2 changes: 1 addition & 1 deletion build/.run/Build.run.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<component name="ProjectRunConfigurationManager">
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Build" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/../run/build" />
<option name="PROGRAM_PARAMETERS" value="--target=Build" />
Expand Down
2 changes: 1 addition & 1 deletion build/.run/Clean.run.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<component name="ProjectRunConfigurationManager">
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Clean" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/../run/build" />
<option name="PROGRAM_PARAMETERS" value="--target=Clean" />
Expand Down
2 changes: 1 addition & 1 deletion build/.run/Package.run.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<component name="ProjectRunConfigurationManager">
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Package" type="DotNetProject" factoryName=".NET Project" folderName="Package">
<option name="EXE_PATH" value="$PROJECT_DIR$/../run/build" />
<option name="PROGRAM_PARAMETERS" value="--target=Package" />
Expand Down
2 changes: 1 addition & 1 deletion build/.run/PublishCoverage.run.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<component name="ProjectRunConfigurationManager">
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="PublishCoverage" type="DotNetProject" factoryName=".NET Project" folderName="Unit Test">
<option name="EXE_PATH" value="$PROJECT_DIR$/../run/build" />
<option name="PROGRAM_PARAMETERS" value="--target=PublishCoverage --dotnet_version=8.0" />
Expand Down
2 changes: 1 addition & 1 deletion build/.run/Test.run.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<component name="ProjectRunConfigurationManager">
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Test" type="DotNetProject" factoryName=".NET Project" folderName="Unit Test">
<option name="EXE_PATH" value="$PROJECT_DIR$/../run/build" />
<option name="PROGRAM_PARAMETERS" value="" />
Expand Down
2 changes: 1 addition & 1 deletion build/CI.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sln", "sln", "{EC2C1EC4-BE56-4CAE-A3EE-4A67EED6BC6C}"
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
Expand Down
2 changes: 1 addition & 1 deletion build/CI.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=OS/@EntryIndexedValue">OS</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Addins/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=endgroup/@EntryIndexedValue">True</s:Boolean>
Expand Down
2 changes: 1 addition & 1 deletion build/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project>
<Project>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
Expand Down
2 changes: 1 addition & 1 deletion build/build/Build.csproj.DotSettings
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=tasks_005Cpackage/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=tasks_005Ctest/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
2 changes: 1 addition & 1 deletion new-cli/.run/Tester.run.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<component name="ProjectRunConfigurationManager">
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Tester" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/GitVersion.Core.Tester/bin/Debug/net9.0/gv" />
<option name="PROGRAM_PARAMETERS" value="" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\GitVersion.Common.Command\GitVersion.Common.Command.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion new-cli/GitVersion.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitVersion.Cli", "GitVersion.Cli\GitVersion.Cli.csproj", "{E2520F2D-A6FF-4079-85A4-584AA0CC8594}"
EndProject
Expand Down
2 changes: 1 addition & 1 deletion new-cli/GitVersion.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=enricher/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
2 changes: 1 addition & 1 deletion new-cli/nuget.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
Expand Down
2 changes: 1 addition & 1 deletion src/.run/schema.run.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<component name="ProjectRunConfigurationManager">
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="schema" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/GitVersion.Schema/bin/Debug/net9.0/schema" />
<option name="PROGRAM_PARAMETERS" value="--OutputDirectory schemas --Version 6.1" />
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.App.Tests/TestBuildFile.proj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="OutputResults">
<Message Text="GitVersion_FullSemVer: $(GitVersion_FullSemVer)"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,22 @@ public void DoNotThrowWhenWorkingAndRepoPathsAreSame_WithDifferentCasing()
Should.NotThrow(() => this.configFileLocator.Verify(this.workingPath, this.repoPath));
}

[Test]
public void DoNotThrowWhenFileNameAreSame_WithDifferentCasing()
{
this.workingPath = this.repoPath;

this.gitVersionOptions = new() { ConfigurationInfo = { ConfigurationFile = "MyConfig.yaml" } };
var sp = GetServiceProvider(this.gitVersionOptions);
this.configFileLocator = sp.GetRequiredService<IConfigurationFileLocator>();
this.fileSystem = sp.GetRequiredService<IFileSystem>();

using var _ = this.fileSystem.SetupConfigFile(path: this.workingPath, fileName: ConfigFile.ToLower());

var config = Should.NotThrow(() => this.configFileLocator.GetConfigurationFile(this.workingPath));
config.ShouldNotBe(null);
}

[Test]
public void DoNotThrowWhenConfigFileIsInSubDirectoryOfRepoPath()
{
Expand Down
56 changes: 33 additions & 23 deletions src/GitVersion.Configuration/ConfigurationFileLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ internal class ConfigurationFileLocator(
public const string DefaultAlternativeFileName = "GitVersion.yaml";
public const string DefaultFileNameDotted = $".{DefaultFileName}";
public const string DefaultAlternativeFileNameDotted = $".{DefaultAlternativeFileName}";
public List<string> SupportedConfigFileNames = [DefaultFileName, DefaultAlternativeFileName, DefaultFileNameDotted, DefaultAlternativeFileNameDotted];

private readonly string[] SupportedConfigFileNames =
[
DefaultFileName,
DefaultAlternativeFileName,
DefaultFileNameDotted,
DefaultAlternativeFileNameDotted
];

private readonly IFileSystem fileSystem = fileSystem.NotNull();
private readonly ILog log = log.NotNull();
Expand All @@ -35,21 +42,28 @@ public void Verify(string? workingDirectory, string? projectRootDirectory)
{
if (directory is null) return null;

string?[] candidates = [this.ConfigurationFile, .. SupportedConfigFileNames];
var candidatePaths =
from candidate in candidates
where !candidate.IsNullOrWhiteSpace()
select PathHelper.Combine(directory, candidate);
string[] candidates = !string.IsNullOrWhiteSpace(this.ConfigurationFile)
? [this.ConfigurationFile, .. this.SupportedConfigFileNames]
: this.SupportedConfigFileNames;

foreach (var candidatePath in candidatePaths)
foreach (var fileName in candidates)
{
this.log.Debug($"Trying to find configuration file at '{candidatePath}'");
if (fileSystem.File.Exists(candidatePath))
this.log.Debug($"Trying to find configuration file {fileName} at '{directory}'");
if (directory != null && fileSystem.Directory.Exists(directory))
{
this.log.Info($"Found configuration file at '{candidatePath}'");
return candidatePath;
var files = fileSystem.Directory.GetFiles(directory);

var matchingFile = files.FirstOrDefault(file =>
string.Equals(fileSystem.Path.GetFileName(file), fileName, StringComparison.OrdinalIgnoreCase));

if (matchingFile != null)
{
this.log.Info($"Found configuration file at '{matchingFile}'");
return matchingFile;
}
}
this.log.Debug($"Configuration file not found at '{candidatePath}'");

this.log.Debug($"Configuration file {fileName} not found at '{directory}'");
}

return null;
Expand All @@ -60,22 +74,18 @@ private void WarnAboutAmbiguousConfigFileSelection(string? workingDirectory, str
var workingConfigFile = GetConfigurationFile(workingDirectory);
var projectRootConfigFile = GetConfigurationFile(projectRootDirectory);

var hasConfigInWorkingDirectory = workingConfigFile != null;
var hasConfigInProjectRootDirectory = projectRootConfigFile != null;
var hasConfigInWorkingDirectory = workingConfigFile is not null;
var hasConfigInProjectRootDirectory = projectRootConfigFile is not null;

if (hasConfigInProjectRootDirectory && hasConfigInWorkingDirectory)
{
throw new WarningException($"Ambiguous configuration file selection from '{workingConfigFile}' and '{projectRootConfigFile}'");
}

if (!hasConfigInProjectRootDirectory && !hasConfigInWorkingDirectory)
{
if (!SupportedConfigFileNames.Any(entry => entry.Equals(this.ConfigurationFile, StringComparison.OrdinalIgnoreCase)))
{
workingConfigFile = PathHelper.Combine(workingDirectory, this.ConfigurationFile);
projectRootConfigFile = PathHelper.Combine(projectRootDirectory, this.ConfigurationFile);
throw new WarningException($"The configuration file was not found at '{workingConfigFile}' or '{projectRootConfigFile}'");
}
}
if (hasConfigInProjectRootDirectory || hasConfigInWorkingDirectory || this.SupportedConfigFileNames.Any(entry => entry.Equals(this.ConfigurationFile, StringComparison.OrdinalIgnoreCase))) return;

workingConfigFile = PathHelper.Combine(workingDirectory, this.ConfigurationFile);
projectRootConfigFile = PathHelper.Combine(projectRootDirectory, this.ConfigurationFile);
throw new WarningException($"The configuration file was not found at '{workingConfigFile}' or '{projectRootConfigFile}'");
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// GitVersion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' GitVersion
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[<assembly: {0}>]
[<assembly: {0}>]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by GitVersion.
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by GitVersion.
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
''------------------------------------------------------------------------------
''------------------------------------------------------------------------------
'' <auto-generated>
'' This code was generated by GitVersion.
''
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">


<s:Boolean x:Key="/Default/CodeEditing/Intellisense/CodeCompletion/AutoCompleteBasicCompletion/@EntryValue">True</s:Boolean>
Expand Down