Skip to content

Commit 22f553a

Browse files
authored
Merge pull request #4452 from arturcic/fix/config-filename-case-insensitive
Config filename case insensitive
2 parents 74c9868 + 0388b70 commit 22f553a

26 files changed

+73
-47
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
# top-most EditorConfig file
44
root = true
5+
charset = utf-8
56

67
[*]
78
indent_style = space
89
indent_size = 4
910
end_of_line = lf
10-
charset = utf-8
1111
trim_trailing_whitespace = true
1212
insert_final_newline = true
1313

build/.run/Build.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<component name="ProjectRunConfigurationManager">
1+
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="Build" type="DotNetProject" factoryName=".NET Project">
33
<option name="EXE_PATH" value="$PROJECT_DIR$/../run/build" />
44
<option name="PROGRAM_PARAMETERS" value="--target=Build" />

build/.run/Clean.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<component name="ProjectRunConfigurationManager">
1+
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="Clean" type="DotNetProject" factoryName=".NET Project">
33
<option name="EXE_PATH" value="$PROJECT_DIR$/../run/build" />
44
<option name="PROGRAM_PARAMETERS" value="--target=Clean" />

build/.run/Package.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<component name="ProjectRunConfigurationManager">
1+
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="Package" type="DotNetProject" factoryName=".NET Project" folderName="Package">
33
<option name="EXE_PATH" value="$PROJECT_DIR$/../run/build" />
44
<option name="PROGRAM_PARAMETERS" value="--target=Package" />

build/.run/PublishCoverage.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<component name="ProjectRunConfigurationManager">
1+
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="PublishCoverage" type="DotNetProject" factoryName=".NET Project" folderName="Unit Test">
33
<option name="EXE_PATH" value="$PROJECT_DIR$/../run/build" />
44
<option name="PROGRAM_PARAMETERS" value="--target=PublishCoverage --dotnet_version=8.0" />

build/.run/Test.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<component name="ProjectRunConfigurationManager">
1+
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="Test" type="DotNetProject" factoryName=".NET Project" folderName="Unit Test">
33
<option name="EXE_PATH" value="$PROJECT_DIR$/../run/build" />
44
<option name="PROGRAM_PARAMETERS" value="" />

build/CI.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Microsoft Visual Studio Solution File, Format Version 12.00
1+
Microsoft Visual Studio Solution File, Format Version 12.00
22
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sln", "sln", "{EC2C1EC4-BE56-4CAE-A3EE-4A67EED6BC6C}"
33
ProjectSection(SolutionItems) = preProject
44
Directory.Build.props = Directory.Build.props

build/CI.sln.DotSettings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<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">
1+
<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">
22
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=OS/@EntryIndexedValue">OS</s:String>
33
<s:Boolean x:Key="/Default/UserDictionary/Words/=Addins/@EntryIndexedValue">True</s:Boolean>
44
<s:Boolean x:Key="/Default/UserDictionary/Words/=endgroup/@EntryIndexedValue">True</s:Boolean>

build/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project>
1+
<Project>
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
44
<TargetFramework>net9.0</TargetFramework>

build/build/Build.csproj.DotSettings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<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">
1+
<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">
22
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=tasks_005Cpackage/@EntryIndexedValue">True</s:Boolean>
33
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=tasks_005Ctest/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

new-cli/.run/Tester.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<component name="ProjectRunConfigurationManager">
1+
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="Tester" type="DotNetProject" factoryName=".NET Project">
33
<option name="EXE_PATH" value="$PROJECT_DIR$/GitVersion.Core.Tester/bin/Debug/net9.0/gv" />
44
<option name="PROGRAM_PARAMETERS" value="" />

new-cli/GitVersion.Calculation/GitVersion.Calculation.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<ItemGroup>
44
<ProjectReference Include="..\GitVersion.Common.Command\GitVersion.Common.Command.csproj" />

new-cli/GitVersion.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
22
Microsoft Visual Studio Solution File, Format Version 12.00
33
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitVersion.Cli", "GitVersion.Cli\GitVersion.Cli.csproj", "{E2520F2D-A6FF-4079-85A4-584AA0CC8594}"
44
EndProject

new-cli/GitVersion.sln.DotSettings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
<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">
1+
<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">
22
<s:Boolean x:Key="/Default/UserDictionary/Words/=enricher/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

new-cli/nuget.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<packageSources>
44
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />

src/.run/schema.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<component name="ProjectRunConfigurationManager">
1+
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="schema" type="DotNetProject" factoryName=".NET Project">
33
<option name="EXE_PATH" value="$PROJECT_DIR$/GitVersion.Schema/bin/Debug/net9.0/schema" />
44
<option name="PROGRAM_PARAMETERS" value="--OutputDirectory schemas --Version 6.1" />

src/GitVersion.App.Tests/TestBuildFile.proj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Target Name="OutputResults">
44
<Message Text="GitVersion_FullSemVer: $(GitVersion_FullSemVer)"/>

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,22 @@ public void DoNotThrowWhenWorkingAndRepoPathsAreSame_WithDifferentCasing()
153153
Should.NotThrow(() => this.configFileLocator.Verify(this.workingPath, this.repoPath));
154154
}
155155

156+
[Test]
157+
public void DoNotThrowWhenFileNameAreSame_WithDifferentCasing()
158+
{
159+
this.workingPath = this.repoPath;
160+
161+
this.gitVersionOptions = new() { ConfigurationInfo = { ConfigurationFile = "MyConfig.yaml" } };
162+
var sp = GetServiceProvider(this.gitVersionOptions);
163+
this.configFileLocator = sp.GetRequiredService<IConfigurationFileLocator>();
164+
this.fileSystem = sp.GetRequiredService<IFileSystem>();
165+
166+
using var _ = this.fileSystem.SetupConfigFile(path: this.workingPath, fileName: ConfigFile.ToLower());
167+
168+
var config = Should.NotThrow(() => this.configFileLocator.GetConfigurationFile(this.workingPath));
169+
config.ShouldNotBe(null);
170+
}
171+
156172
[Test]
157173
public void DoNotThrowWhenConfigFileIsInSubDirectoryOfRepoPath()
158174
{

src/GitVersion.Configuration/ConfigurationFileLocator.cs

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ internal class ConfigurationFileLocator(
1616
public const string DefaultAlternativeFileName = "GitVersion.yaml";
1717
public const string DefaultFileNameDotted = $".{DefaultFileName}";
1818
public const string DefaultAlternativeFileNameDotted = $".{DefaultAlternativeFileName}";
19-
public List<string> SupportedConfigFileNames = [DefaultFileName, DefaultAlternativeFileName, DefaultFileNameDotted, DefaultAlternativeFileNameDotted];
19+
20+
private readonly string[] SupportedConfigFileNames =
21+
[
22+
DefaultFileName,
23+
DefaultAlternativeFileName,
24+
DefaultFileNameDotted,
25+
DefaultAlternativeFileNameDotted
26+
];
2027

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

38-
string?[] candidates = [this.ConfigurationFile, .. SupportedConfigFileNames];
39-
var candidatePaths =
40-
from candidate in candidates
41-
where !candidate.IsNullOrWhiteSpace()
42-
select PathHelper.Combine(directory, candidate);
45+
string[] candidates = !string.IsNullOrWhiteSpace(this.ConfigurationFile)
46+
? [this.ConfigurationFile, .. this.SupportedConfigFileNames]
47+
: this.SupportedConfigFileNames;
4348

44-
foreach (var candidatePath in candidatePaths)
49+
foreach (var fileName in candidates)
4550
{
46-
this.log.Debug($"Trying to find configuration file at '{candidatePath}'");
47-
if (fileSystem.File.Exists(candidatePath))
51+
this.log.Debug($"Trying to find configuration file {fileName} at '{directory}'");
52+
if (directory != null && fileSystem.Directory.Exists(directory))
4853
{
49-
this.log.Info($"Found configuration file at '{candidatePath}'");
50-
return candidatePath;
54+
var files = fileSystem.Directory.GetFiles(directory);
55+
56+
var matchingFile = files.FirstOrDefault(file =>
57+
string.Equals(fileSystem.Path.GetFileName(file), fileName, StringComparison.OrdinalIgnoreCase));
58+
59+
if (matchingFile != null)
60+
{
61+
this.log.Info($"Found configuration file at '{matchingFile}'");
62+
return matchingFile;
63+
}
5164
}
52-
this.log.Debug($"Configuration file not found at '{candidatePath}'");
65+
66+
this.log.Debug($"Configuration file {fileName} not found at '{directory}'");
5367
}
5468

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

63-
var hasConfigInWorkingDirectory = workingConfigFile != null;
64-
var hasConfigInProjectRootDirectory = projectRootConfigFile != null;
77+
var hasConfigInWorkingDirectory = workingConfigFile is not null;
78+
var hasConfigInProjectRootDirectory = projectRootConfigFile is not null;
6579

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

71-
if (!hasConfigInProjectRootDirectory && !hasConfigInWorkingDirectory)
72-
{
73-
if (!SupportedConfigFileNames.Any(entry => entry.Equals(this.ConfigurationFile, StringComparison.OrdinalIgnoreCase)))
74-
{
75-
workingConfigFile = PathHelper.Combine(workingDirectory, this.ConfigurationFile);
76-
projectRootConfigFile = PathHelper.Combine(projectRootDirectory, this.ConfigurationFile);
77-
throw new WarningException($"The configuration file was not found at '{workingConfigFile}' or '{projectRootConfigFile}'");
78-
}
79-
}
85+
if (hasConfigInProjectRootDirectory || hasConfigInWorkingDirectory || this.SupportedConfigFileNames.Any(entry => entry.Equals(this.ConfigurationFile, StringComparison.OrdinalIgnoreCase))) return;
86+
87+
workingConfigFile = PathHelper.Combine(workingDirectory, this.ConfigurationFile);
88+
projectRootConfigFile = PathHelper.Combine(projectRootDirectory, this.ConfigurationFile);
89+
throw new WarningException($"The configuration file was not found at '{workingConfigFile}' or '{projectRootConfigFile}'");
8090
}
8191
}

src/GitVersion.Output.Tests/Output/Approved/fs/GitVersionInfoGeneratorTests.ShouldProperlyOutputNamespaceDeclaration.approved.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//------------------------------------------------------------------------------
1+
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was generated by a tool.
44
// GitVersion

src/GitVersion.Output.Tests/Output/Approved/vb/GitVersionInfoGeneratorTests.ShouldProperlyOutputNamespaceDeclaration.approved.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'------------------------------------------------------------------------------
1+
'------------------------------------------------------------------------------
22
' <auto-generated>
33
' This code was generated by a tool.
44
' GitVersion
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[<assembly: {0}>]
1+
[<assembly: {0}>]

src/GitVersion.Output/AssemblyInfo/Templates/VersionAssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//------------------------------------------------------------------------------
1+
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was generated by GitVersion.
44
//

src/GitVersion.Output/AssemblyInfo/Templates/VersionAssemblyInfo.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//------------------------------------------------------------------------------
1+
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was generated by GitVersion.
44
//

src/GitVersion.Output/AssemblyInfo/Templates/VersionAssemblyInfo.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
''------------------------------------------------------------------------------
1+
''------------------------------------------------------------------------------
22
'' <auto-generated>
33
'' This code was generated by GitVersion.
44
''

src/GitVersion.sln.DotSettings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<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">
1+
<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">
22

33

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

0 commit comments

Comments
 (0)