Skip to content

Commit 6a952af

Browse files
author
Furkan Küçük
committed
The case insensitive kept for the default file names, for the custom config file left it to the OS
1 parent db7d460 commit 6a952af

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

src/GitVersion.Configuration/ConfigurationFileLocator.cs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,35 +40,46 @@ public void Verify(string? workingDirectory, string? projectRootDirectory)
4040

4141
public string? GetConfigurationFile(string? directoryPath)
4242
{
43-
string[] configurationFilePaths = string.IsNullOrWhiteSpace(this.ConfigurationFile)
44-
? this.SupportedConfigFileNames : [this.ConfigurationFile, .. this.SupportedConfigFileNames];
43+
string? customConfigurationFile = GetCustomConfigurationFilePathIfEligable(directoryPath);
44+
if (!string.IsNullOrWhiteSpace(customConfigurationFile))
45+
{
46+
return customConfigurationFile;
47+
}
4548

46-
foreach (var item in configurationFilePaths)
49+
if (string.IsNullOrWhiteSpace(directoryPath) || !fileSystem.Directory.Exists(directoryPath))
4750
{
48-
this.log.Debug($"Trying to find configuration file {item} at '{directoryPath}'");
51+
return null;
52+
}
4953

50-
string configurationFilePath;
51-
if (!PathHelper.IsPathRooted(item))
54+
string[] files = fileSystem.Directory.GetFiles(directoryPath);
55+
foreach (var fileName in this.SupportedConfigFileNames)
56+
{
57+
this.log.Debug($"Trying to find configuration file {fileName} at '{directoryPath}'");
58+
string? matchingFile = files.FirstOrDefault(file => string.Equals(PathHelper.GetFileName(file), fileName, StringComparison.OrdinalIgnoreCase));
59+
if (matchingFile != null)
5260
{
53-
if (string.IsNullOrEmpty(directoryPath))
54-
{
55-
this.log.Info($"The configuration file '{item}' is relative and no directory path known.");
56-
continue;
57-
}
58-
configurationFilePath = Path.Combine(directoryPath, item);
61+
this.log.Info($"Found configuration file at '{matchingFile}'");
62+
return matchingFile;
5963
}
60-
else
64+
}
65+
66+
return null;
67+
}
68+
69+
private string? GetCustomConfigurationFilePathIfEligable(string? directoryPath)
70+
{
71+
if (!string.IsNullOrWhiteSpace(this.ConfigurationFile))
72+
{
73+
string configurationFilePath = this.ConfigurationFile;
74+
if (!string.IsNullOrWhiteSpace(directoryPath))
6175
{
62-
configurationFilePath = item;
76+
configurationFilePath = Path.Combine(directoryPath, this.ConfigurationFile);
6377
}
6478

6579
if (fileSystem.File.Exists(configurationFilePath))
6680
{
67-
this.log.Info($"Found configuration file at '{configurationFilePath}'");
6881
return configurationFilePath;
6982
}
70-
71-
this.log.Debug($"Configuration file {configurationFilePath} not found at '{directoryPath}'");
7283
}
7384

7485
return null;

0 commit comments

Comments
 (0)