diff --git a/src/GitVersionCore.Tests/NamedConfigFileLocatorTests.cs b/src/GitVersionCore.Tests/NamedConfigFileLocatorTests.cs index 21bbc291e9..d0d0010a51 100644 --- a/src/GitVersionCore.Tests/NamedConfigFileLocatorTests.cs +++ b/src/GitVersionCore.Tests/NamedConfigFileLocatorTests.cs @@ -136,6 +136,20 @@ public void NoWarnOnCustomYmlFileOutsideRepoPath() stringLogger.Length.ShouldBe(0); } + [Test] + public void ThrowsExceptionOnCustomYmlFileDoesNotExist() + { + var sp = GetServiceProvider(arguments); + configFileLocator = sp.GetService(); + + var exception = Should.Throw(() => { configFileLocator.Verify(workingPath, repoPath); }); + + var workingPathFileConfig = Path.Combine(workingPath, arguments.ConfigFile); + var repoPathFileConfig = Path.Combine(repoPath, arguments.ConfigFile); + 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 (string.IsNullOrEmpty(fileName)) fileName = ((NamedConfigFileLocator)configFileLocator).FilePath; diff --git a/src/GitVersionCore/Configuration/NamedConfigFileLocator.cs b/src/GitVersionCore/Configuration/NamedConfigFileLocator.cs index 09c994c502..5b3899c8dc 100644 --- a/src/GitVersionCore/Configuration/NamedConfigFileLocator.cs +++ b/src/GitVersionCore/Configuration/NamedConfigFileLocator.cs @@ -46,6 +46,11 @@ private void WarnAboutAmbiguousConfigFileSelection(string workingDirectory, stri { throw new WarningException($"Ambiguous config file selection from '{workingConfigFile}' and '{projectRootConfigFile}'"); } + + if (!hasConfigInProjectRootDirectory && !hasConfigInWorkingDirectory) + { + throw new WarningException($"The configuration file was not found at '{workingConfigFile}' or '{projectRootConfigFile}'"); + } } } }