Skip to content

Commit 0862cf8

Browse files
committed
#2484 - show warning if the configuration file is not found
1 parent a3a3f75 commit 0862cf8

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

src/GitVersion.App.Tests/ArgumentParserTests.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,8 @@ private static IEnumerable<TestCaseData> OverrideConfigWithSingleOptionTestData(
531531
public void OverrideConfigWithMultipleOptions(string options, GitVersionConfiguration expected)
532532
{
533533
var arguments = this.argumentParser.ParseArguments(options);
534-
ConfigurationHelper configruationHelper = new(arguments.OverrideConfiguration);
535-
configruationHelper.Configuration.ShouldBeEquivalentTo(expected);
534+
ConfigurationHelper configurationHelper = new(arguments.OverrideConfiguration);
535+
configurationHelper.Configuration.ShouldBeEquivalentTo(expected);
536536
}
537537

538538
private static IEnumerable<TestCaseData> OverrideConfigWithMultipleOptionsTestData()
@@ -740,4 +740,19 @@ public void EnsureFormatIsSet()
740740
var arguments = this.argumentParser.ParseArguments("-format {Major}.{Minor}.{Patch}");
741741
arguments.Format.ShouldBe("{Major}.{Minor}.{Patch}");
742742
}
743+
744+
[TestCase("custom-config.yaml")]
745+
[TestCase(@"c:\custom-config.yaml")]
746+
public void ThrowIfConfigurationFileDoesNotExist(string configFile) =>
747+
Should.Throw<WarningException>(() => _ = this.argumentParser.ParseArguments($"-config {configFile}"));
748+
749+
[Test]
750+
public void EnsureConfigurationFileIsSet()
751+
{
752+
var configFile = Path.GetTempPath() + Guid.NewGuid() + ".yaml";
753+
File.WriteAllText(configFile, "next-version: 1.0.0");
754+
var arguments = this.argumentParser.ParseArguments($"-config {configFile}");
755+
arguments.ConfigurationFile.ShouldBe(configFile);
756+
File.Delete(configFile);
757+
}
743758
}

src/GitVersion.App/ArgumentParser.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,28 @@ public Arguments ParseArguments(string[] commandLineArguments)
106106
if (!arguments.EnsureAssemblyInfo) arguments.UpdateAssemblyInfoFileName = ResolveFiles(arguments.TargetPath, arguments.UpdateAssemblyInfoFileName).ToHashSet();
107107
arguments.NoFetch = arguments.NoFetch || this.buildAgent.PreventFetch();
108108

109+
ValidateConfigurationFile(arguments);
110+
109111
return arguments;
110112
}
111113

114+
private static void ValidateConfigurationFile(Arguments arguments)
115+
{
116+
if (arguments.ConfigurationFile.IsNullOrWhiteSpace()) return;
117+
118+
if (Path.IsPathRooted(arguments.ConfigurationFile))
119+
{
120+
if (!File.Exists(arguments.ConfigurationFile)) throw new WarningException($"Could not find config file at '{arguments.ConfigurationFile}'");
121+
arguments.ConfigurationFile = Path.GetFullPath(arguments.ConfigurationFile);
122+
}
123+
else
124+
{
125+
var configFilePath = Path.GetFullPath(Path.Combine(arguments.TargetPath, arguments.ConfigurationFile));
126+
if (!File.Exists(configFilePath)) throw new WarningException($"Could not find config file at '{configFilePath}'");
127+
arguments.ConfigurationFile = configFilePath;
128+
}
129+
}
130+
112131
private void ParseSwitchArguments(Arguments arguments, NameValueCollection switchesAndValues, int i)
113132
{
114133
var name = switchesAndValues.AllKeys[i];

src/GitVersion.Core/VersionCalculation/BaseVersionCalculators/TrackReleaseBranchesVersionStrategy.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ namespace GitVersion.VersionCalculation;
2323
public class TrackReleaseBranchesVersionStrategy : VersionStrategyBase
2424
{
2525
private readonly VersionInBranchNameVersionStrategy releaseVersionStrategy;
26-
private readonly TaggedCommitVersionStrategy taggedCommitVersionStrategy;
2726

2827
private readonly IRepositoryStore repositoryStore;
2928

@@ -32,7 +31,6 @@ public TrackReleaseBranchesVersionStrategy(IRepositoryStore repositoryStore, Laz
3231
{
3332
this.repositoryStore = repositoryStore.NotNull();
3433
this.releaseVersionStrategy = new VersionInBranchNameVersionStrategy(repositoryStore, versionContext);
35-
this.taggedCommitVersionStrategy = new TaggedCommitVersionStrategy(repositoryStore, versionContext);
3634
}
3735

3836
public override IEnumerable<BaseVersion> GetBaseVersions(EffectiveBranchConfiguration configuration) =>

0 commit comments

Comments
 (0)