Skip to content

Commit 229a08e

Browse files
committed
GH-2100 - /config doesn't show message when file doesn't exist
1 parent a030aa2 commit 229a08e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/GitVersionCore.Tests/NamedConfigFileLocatorTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,20 @@ public void NoWarnOnCustomYmlFileOutsideRepoPath()
136136
stringLogger.Length.ShouldBe(0);
137137
}
138138

139+
[Test]
140+
public void ThrowsExceptionOnCustomYmlFileDoesNotExist()
141+
{
142+
var sp = GetServiceProvider(arguments);
143+
configFileLocator = sp.GetService<IConfigFileLocator>();
144+
145+
var exception = Should.Throw<WarningException>(() => { configFileLocator.Verify(workingPath, repoPath); });
146+
147+
var workingPathFileConfig = Path.Combine(workingPath, arguments.ConfigFile);
148+
var repoPathFileConfig = Path.Combine(repoPath, arguments.ConfigFile);
149+
var expectedMessage = $"The configuration file was not found at '{workingPathFileConfig}' or '{repoPathFileConfig}'";
150+
exception.Message.ShouldBe(expectedMessage);
151+
}
152+
139153
private string SetupConfigFileContent(string text, string fileName = null, string path = null)
140154
{
141155
if (string.IsNullOrEmpty(fileName)) fileName = ((NamedConfigFileLocator)configFileLocator).FilePath;

src/GitVersionCore/Configuration/NamedConfigFileLocator.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ private void WarnAboutAmbiguousConfigFileSelection(string workingDirectory, stri
4646
{
4747
throw new WarningException($"Ambiguous config file selection from '{workingConfigFile}' and '{projectRootConfigFile}'");
4848
}
49+
50+
if (!hasConfigInProjectRootDirectory && !hasConfigInWorkingDirectory)
51+
{
52+
throw new WarningException($"The configuration file was not found at '{workingConfigFile}' or '{projectRootConfigFile}'");
53+
}
4954
}
5055
}
5156
}

0 commit comments

Comments
 (0)