diff --git a/docs/input/docs/usage/cli/arguments.md b/docs/input/docs/usage/cli/arguments.md index 93cdd7445e..d6e3c94a04 100644 --- a/docs/input/docs/usage/cli/arguments.md +++ b/docs/input/docs/usage/cli/arguments.md @@ -42,9 +42,9 @@ GitVersion [path] E.g. /output json /format {SemVer} - will output `1.2.3+beta.4` /output json /format {Major}.{Minor} - will output `1.2` /l Path to logfile. - /config Path to config file (defaults to GitVersion.yml) + /config Path to config file (defaults to GitVersion.yml or GitVersion.yaml) /showconfig Outputs the effective GitVersion config (defaults + custom - from GitVersion.yml) in yaml format + from GitVersion.yml or GitVersion.yaml) in yaml format /overrideconfig Overrides GitVersion config values inline (semicolon- separated key value pairs e.g. /overrideconfig label-prefix=Foo) @@ -103,7 +103,7 @@ gitversion init Configuration utility for gitversion ## Override config -`/overrideconfig [key=value]` will override appropriate `key` from 'GitVersion.yml'. +`/overrideconfig [key=value]` will override appropriate `key` from 'GitVersion.yml' or 'GitVersion.yaml'. To specify multiple options add multiple `/overrideconfig [key=value]` entries: `/overrideconfig key1=value1 /overrideconfig key2=value2`. @@ -135,7 +135,7 @@ Following options are supported: Read more about [Configuration](/docs/reference/configuration). -Using `override-config` on the command line will not change the contents of the config file `GitVersion.yml`. +Using `override-config` on the command line will not change the contents of the config file `GitVersion.yml` or `GitVersion.yaml`. ### Example: How to override configuration option 'label-prefix' to use prefix 'custom' diff --git a/src/GitVersion.App/GitVersionExecutor.cs b/src/GitVersion.App/GitVersionExecutor.cs index 4df25cb89c..eb716e956a 100644 --- a/src/GitVersion.App/GitVersionExecutor.cs +++ b/src/GitVersion.App/GitVersionExecutor.cs @@ -143,7 +143,10 @@ private bool HandleNonMainCommand(GitVersionOptions gitVersionOptions, out int e this.log.Info("Working directory: " + workingDirectory); } - this.configurationFileLocator.Verify(gitVersionOptions, this.repositoryInfo); + if (gitVersionOptions.RepositoryInfo.TargetUrl.IsNullOrWhiteSpace()) + { + this.configurationFileLocator.Verify(workingDirectory, this.repositoryInfo.ProjectRootDirectory); + } if (gitVersionOptions.Init) { diff --git a/src/GitVersion.App/OverrideConfigurationOptionParser.cs b/src/GitVersion.App/OverrideConfigurationOptionParser.cs index d9a6a8ca60..c258fd93d3 100644 --- a/src/GitVersion.App/OverrideConfigurationOptionParser.cs +++ b/src/GitVersion.App/OverrideConfigurationOptionParser.cs @@ -17,7 +17,7 @@ internal class OverrideConfigurationOptionParser /// /// /// - /// Lookup keys are created from to match 'GitVersion.yml' + /// Lookup keys are created from to match 'GitVersion.yml' or 'GitVersion.yaml' file /// options as close as possible. /// private static ILookup GetSupportedProperties() => typeof(GitVersionConfiguration).GetProperties(BindingFlags.Public | BindingFlags.Instance) diff --git a/src/GitVersion.BuildAgents.Tests/Agents/BitBucketPipelinesTests.cs b/src/GitVersion.BuildAgents.Tests/Agents/BitBucketPipelinesTests.cs index a3f2413861..a717bb8cad 100644 --- a/src/GitVersion.BuildAgents.Tests/Agents/BitBucketPipelinesTests.cs +++ b/src/GitVersion.BuildAgents.Tests/Agents/BitBucketPipelinesTests.cs @@ -82,7 +82,7 @@ public void GetCurrentBranchShouldHandleBranches() var result = this.buildServer.GetCurrentBranch(false); // Assert - result.ShouldBe($"refs/heads/feature/my-work"); + result.ShouldBe("refs/heads/feature/my-work"); } [Test] diff --git a/src/GitVersion.Core.Tests/Configuration/ConfigurationFileLocatorTests.cs b/src/GitVersion.Core.Tests/Configuration/ConfigurationFileLocatorTests.cs index a5170ebd91..22aa017ec9 100644 --- a/src/GitVersion.Core.Tests/Configuration/ConfigurationFileLocatorTests.cs +++ b/src/GitVersion.Core.Tests/Configuration/ConfigurationFileLocatorTests.cs @@ -39,6 +39,9 @@ public void Setup() } [TestCase(ConfigurationFileLocator.DefaultFileName, ConfigurationFileLocator.DefaultFileName)] + [TestCase(ConfigurationFileLocator.DefaultFileName, ConfigurationFileLocator.DefaultAlternativeFileName)] + [TestCase(ConfigurationFileLocator.DefaultAlternativeFileName, ConfigurationFileLocator.DefaultFileName)] + [TestCase(ConfigurationFileLocator.DefaultAlternativeFileName, ConfigurationFileLocator.DefaultAlternativeFileName)] public void ThrowsExceptionOnAmbiguousConfigFileLocation(string repoConfigFile, string workingConfigFile) { var repositoryConfigFilePath = SetupConfigFileContent(string.Empty, repoConfigFile, this.repoPath); @@ -50,16 +53,17 @@ public void ThrowsExceptionOnAmbiguousConfigFileLocation(string repoConfigFile, exception.Message.ShouldBe(expectedMessage); } - [Test] - public void NoWarnOnGitVersionYmlFile() + [TestCase(ConfigurationFileLocator.DefaultFileName)] + [TestCase(ConfigurationFileLocator.DefaultAlternativeFileName)] + public void NoWarnOnGitVersionYmlFile(string configurationFile) { - SetupConfigFileContent(string.Empty, ConfigurationFileLocator.DefaultFileName, this.repoPath); + SetupConfigFileContent(string.Empty, configurationFile, this.repoPath); - Should.NotThrow(() => this.configurationProvider.ProvideInternal(this.repoPath)); + Should.NotThrow(() => this.configurationProvider.ProvideForDirectory(this.repoPath)); } [Test] - public void NoWarnOnNoGitVersionYmlFile() => Should.NotThrow(() => this.configurationProvider.ProvideInternal(this.repoPath)); + public void NoWarnOnNoGitVersionYmlFile() => Should.NotThrow(() => this.configurationProvider.ProvideForDirectory(this.repoPath)); private string SetupConfigFileContent(string text, string fileName, string path) { @@ -74,6 +78,7 @@ public class NamedConfigurationFileLocatorTests : TestBase { private const string DefaultRepoPath = @"c:\MyGitRepo"; private const string DefaultWorkingPath = @"c:\MyGitRepo\Working"; + private const string myConfigYaml = "my-config.yaml"; private string repoPath; private string workingPath; @@ -84,7 +89,7 @@ public class NamedConfigurationFileLocatorTests : TestBase [SetUp] public void Setup() { - this.gitVersionOptions = new GitVersionOptions { ConfigurationInfo = { ConfigurationFile = "my-config.yaml" } }; + this.gitVersionOptions = new GitVersionOptions { ConfigurationInfo = { ConfigurationFile = myConfigYaml } }; this.repoPath = DefaultRepoPath; this.workingPath = DefaultWorkingPath; @@ -167,7 +172,7 @@ public void NoWarnOnCustomYmlFile() var configurationProvider = (ConfigurationProvider)sp.GetRequiredService(); - configurationProvider.ProvideInternal(this.repoPath); + configurationProvider.ProvideForDirectory(this.repoPath); stringLogger.Length.ShouldBe(0); } @@ -188,7 +193,7 @@ public void NoWarnOnCustomYmlFileOutsideRepoPath() var configurationProvider = (ConfigurationProvider)sp.GetRequiredService(); - configurationProvider.ProvideInternal(this.repoPath); + configurationProvider.ProvideForDirectory(this.repoPath); stringLogger.Length.ShouldBe(0); } @@ -200,20 +205,24 @@ public void ThrowsExceptionOnCustomYmlFileDoesNotExist() var exception = Should.Throw(() => this.configFileLocator.Verify(this.workingPath, this.repoPath)); - var workingPathFileConfig = PathHelper.Combine(this.workingPath, this.gitVersionOptions.ConfigurationInfo.ConfigurationFile); - var repoPathFileConfig = PathHelper.Combine(this.repoPath, this.gitVersionOptions.ConfigurationInfo.ConfigurationFile); + var configurationFile = this.gitVersionOptions.ConfigurationInfo.ConfigurationFile; + var workingPathFileConfig = PathHelper.Combine(this.workingPath, configurationFile); + var repoPathFileConfig = PathHelper.Combine(this.repoPath, configurationFile); 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 (fileName.IsNullOrEmpty()) fileName = this.configFileLocator.FilePath; + if (fileName.IsNullOrEmpty()) + { + fileName = gitVersionOptions.ConfigurationInfo.ConfigurationFile; + } var filePath = fileName; if (!path.IsNullOrEmpty()) filePath = PathHelper.Combine(path, filePath); this.fileSystem.WriteAllText(filePath, text); - return filePath; + return filePath!; } private static IServiceProvider GetServiceProvider(GitVersionOptions gitVersionOptions, ILog? log = null) => diff --git a/src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.cs b/src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.cs index 5d5bb2fef5..6d78ea419f 100644 --- a/src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.cs +++ b/src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.cs @@ -33,7 +33,7 @@ public void Setup() [Test] public void OverwritesDefaultsWithProvidedConfig() { - var defaultConfig = this.configurationProvider.ProvideInternal(this.repoPath); + var defaultConfig = this.configurationProvider.ProvideForDirectory(this.repoPath); const string text = @" next-version: 2.0.0 branches: @@ -41,7 +41,7 @@ public void OverwritesDefaultsWithProvidedConfig() mode: ContinuousDeployment label: dev"; SetupConfigFileContent(text); - var configuration = this.configurationProvider.ProvideInternal(this.repoPath); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath); configuration.NextVersion.ShouldBe("2.0.0"); configuration.Branches.ShouldNotBeNull(); @@ -59,7 +59,7 @@ public void CanRemoveLabel() release: label: """""; SetupConfigFileContent(text); - var configuration = this.configurationProvider.ProvideInternal(this.repoPath); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath); configuration.NextVersion.ShouldBe("2.0.0"); configuration.Branches["release"].Label.ShouldBe(string.Empty); @@ -74,7 +74,7 @@ public void RegexIsRequired() bug: label: bugfix"; SetupConfigFileContent(text); - var ex = Should.Throw(() => this.configurationProvider.ProvideInternal(this.repoPath)); + var ex = Should.Throw(() => this.configurationProvider.ProvideForDirectory(this.repoPath)); ex.Message.ShouldBe($"Branch configuration 'bug' is missing required configuration 'regex'{System.Environment.NewLine}" + "See https://gitversion.net/docs/reference/configuration for more info"); } @@ -89,7 +89,7 @@ public void SourceBranchIsRequired() regex: 'bug[/-]' label: bugfix"; SetupConfigFileContent(text); - var ex = Should.Throw(() => this.configurationProvider.ProvideInternal(this.repoPath)); + var ex = Should.Throw(() => this.configurationProvider.ProvideForDirectory(this.repoPath)); ex.Message.ShouldBe($"Branch configuration 'bug' is missing required configuration 'source-branches'{System.Environment.NewLine}" + "See https://gitversion.net/docs/reference/configuration for more info"); } @@ -104,7 +104,7 @@ public void SourceBranchesValidationShouldFailWhenMatchingBranchConfigurationIsM label: bugfix source-branches: [notconfigured]"; SetupConfigFileContent(text); - var ex = Should.Throw(() => this.configurationProvider.ProvideInternal(this.repoPath)); + var ex = Should.Throw(() => this.configurationProvider.ProvideForDirectory(this.repoPath)); ex.Message.ShouldBe($"Branch configuration 'bug' defines these 'source-branches' that are not configured: '[notconfigured]'{System.Environment.NewLine}" + "See https://gitversion.net/docs/reference/configuration for more info"); } @@ -121,7 +121,7 @@ public void SourceBranchesValidationShouldSucceedForWellKnownBranches(string wel label: bugfix source-branches: [{wellKnownBranchKey}]"; SetupConfigFileContent(text); - var configuration = this.configurationProvider.ProvideInternal(this.repoPath); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath); configuration.Branches["bug"].SourceBranches.ShouldBe(new List { wellKnownBranchKey }); } @@ -137,7 +137,7 @@ public void CanProvideConfigForNewBranch() label: bugfix source-branches: []"; SetupConfigFileContent(text); - var configuration = this.configurationProvider.ProvideInternal(this.repoPath); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath); configuration.Branches["bug"].Regex.ShouldBe("bug[/-]"); configuration.Branches["bug"].Label.ShouldBe("bugfix"); @@ -148,7 +148,7 @@ public void NextVersionCanBeInteger() { const string text = "next-version: 2"; SetupConfigFileContent(text); - var configuration = this.configurationProvider.ProvideInternal(this.repoPath); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath); configuration.NextVersion.ShouldBe("2.0"); } @@ -158,7 +158,7 @@ public void NextVersionCanHaveEnormousMinorVersion() { const string text = "next-version: 2.118998723"; SetupConfigFileContent(text); - var configuration = this.configurationProvider.ProvideInternal(this.repoPath); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath); configuration.NextVersion.ShouldBe("2.118998723"); } @@ -168,7 +168,7 @@ public void NextVersionCanHavePatch() { const string text = "next-version: 2.12.654651698"; SetupConfigFileContent(text); - var configuration = this.configurationProvider.ProvideInternal(this.repoPath); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath); configuration.NextVersion.ShouldBe("2.12.654651698"); } @@ -177,7 +177,7 @@ public void NextVersionCanHavePatch() [MethodImpl(MethodImplOptions.NoInlining)] public void CanWriteOutEffectiveConfiguration() { - var configuration = this.configurationProvider.ProvideInternal(this.repoPath); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath); configuration.ToString().ShouldMatchApproved(); } @@ -192,7 +192,7 @@ public void CanUpdateAssemblyInformationalVersioningScheme() SetupConfigFileContent(text); - var configuration = this.configurationProvider.ProvideInternal(this.repoPath); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath); configuration.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor); configuration.AssemblyFileVersioningScheme.ShouldBe(AssemblyFileVersioningScheme.MajorMinorPatch); configuration.AssemblyInformationalFormat.ShouldBe("{NugetVersion}"); @@ -208,7 +208,7 @@ public void CanUpdateAssemblyInformationalVersioningSchemeWithMultipleVariables( SetupConfigFileContent(text); - var configuration = this.configurationProvider.ProvideInternal(this.repoPath); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath); configuration.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor); configuration.AssemblyFileVersioningScheme.ShouldBe(AssemblyFileVersioningScheme.MajorMinorPatch); configuration.AssemblyInformationalFormat.ShouldBe("{Major}.{Minor}.{Patch}"); @@ -227,7 +227,7 @@ public void CanUpdateAssemblyInformationalVersioningSchemeWithFullSemVer() SetupConfigFileContent(text); - var configuration = this.configurationProvider.ProvideInternal(this.repoPath); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath); configuration.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch); configuration.AssemblyFileVersioningScheme.ShouldBe(AssemblyFileVersioningScheme.MajorMinorPatch); configuration.AssemblyInformationalFormat.ShouldBe("{FullSemVer}"); @@ -238,7 +238,7 @@ public void CanReadDefaultDocument() { const string text = ""; SetupConfigFileContent(text); - var configuration = this.configurationProvider.ProvideInternal(this.repoPath); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath); configuration.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch); configuration.AssemblyFileVersioningScheme.ShouldBe(AssemblyFileVersioningScheme.MajorMinorPatch); configuration.AssemblyInformationalFormat.ShouldBe(null); @@ -280,12 +280,13 @@ public void NoWarnOnGitVersionYmlFile() }); this.configurationProvider = (ConfigurationProvider)sp.GetRequiredService(); - this.configurationProvider.ProvideInternal(this.repoPath); + this.configurationProvider.ProvideForDirectory(this.repoPath); stringLogger.Length.ShouldBe(0); } - private void SetupConfigFileContent(string text, string fileName = ConfigurationFileLocator.DefaultFileName) => SetupConfigFileContent(text, fileName, this.repoPath); + private void SetupConfigFileContent(string text, string fileName = ConfigurationFileLocator.DefaultFileName) + => SetupConfigFileContent(text, fileName, this.repoPath); private void SetupConfigFileContent(string text, string fileName, string path) { @@ -304,7 +305,7 @@ public void ShouldUseSpecifiedSourceBranchesForDevelop() source-branches: ['develop'] label: dev"; SetupConfigFileContent(text); - var configuration = this.configurationProvider.ProvideInternal(this.repoPath); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath); configuration.Branches["develop"].SourceBranches.ShouldBe(new List { "develop" }); } @@ -319,7 +320,7 @@ public void ShouldUseDefaultSourceBranchesWhenNotSpecifiedForDevelop() mode: ContinuousDeployment label: dev"; SetupConfigFileContent(text); - var configuration = this.configurationProvider.ProvideInternal(this.repoPath); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath); configuration.Branches["develop"].SourceBranches.ShouldBe(new List()); } @@ -335,7 +336,7 @@ public void ShouldUseSpecifiedSourceBranchesForFeature() source-branches: ['develop', 'release'] label: dev"; SetupConfigFileContent(text); - var configuration = this.configurationProvider.ProvideInternal(this.repoPath); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath); configuration.Branches["feature"].SourceBranches.ShouldBe(new List { "develop", "release" }); } @@ -350,7 +351,7 @@ public void ShouldUseDefaultSourceBranchesWhenNotSpecifiedForFeature() mode: ContinuousDeployment label: dev"; SetupConfigFileContent(text); - var configuration = this.configurationProvider.ProvideInternal(this.repoPath); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath); configuration.Branches["feature"].SourceBranches.ShouldBe( new List { "develop", MainBranch, "release", "feature", "support", "hotfix" }); @@ -368,7 +369,7 @@ public void ShouldNotOverrideAnythingWhenOverrideConfigIsEmpty() .WithNextVersion("1.2.3") .WithLabelPrefix("custom-label-prefix-from-yml") .Build(); - var overridenConfig = this.configurationProvider.ProvideInternal(this.repoPath); + var overridenConfig = this.configurationProvider.ProvideForDirectory(this.repoPath); overridenConfig.AssemblyVersioningScheme.ShouldBe(expectedConfig.AssemblyVersioningScheme); overridenConfig.AssemblyFileVersioningScheme.ShouldBe(expectedConfig.AssemblyFileVersioningScheme); @@ -401,7 +402,7 @@ public void ShouldUseDefaultTagPrefixWhenNotSetInConfigFile() { const string text = ""; SetupConfigFileContent(text); - var configuration = this.configurationProvider.ProvideInternal(this.repoPath); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath); configuration.LabelPrefix.ShouldBe(ConfigurationConstants.DefaultLabelPrefix); } @@ -411,7 +412,7 @@ public void ShouldUseTagPrefixFromConfigFileWhenProvided() { const string text = "label-prefix: custom-label-prefix-from-yml"; SetupConfigFileContent(text); - var configuration = this.configurationProvider.ProvideInternal(this.repoPath); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath); configuration.LabelPrefix.ShouldBe("custom-label-prefix-from-yml"); } @@ -425,7 +426,7 @@ public void ShouldOverrideTagPrefixWithOverrideConfigValue([Values] bool tagPref { { "label-prefix", "label-prefix-from-override-configuration" } }; - var configuration = this.configurationProvider.ProvideInternal(this.repoPath, overrideConfiguration); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath, overrideConfiguration); configuration.LabelPrefix.ShouldBe("label-prefix-from-override-configuration"); } @@ -440,7 +441,7 @@ public void ShouldNotOverrideDefaultTagPrefixWhenNotSetInOverrideConfig() { "next-version", "1.0.0" } }; - var configuration = this.configurationProvider.ProvideInternal(this.repoPath, overrideConfiguration); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath, overrideConfiguration); configuration.LabelPrefix.ShouldBe(ConfigurationConstants.DefaultLabelPrefix); } @@ -454,7 +455,7 @@ public void ShouldNotOverrideTagPrefixFromConfigFileWhenNotSetInOverrideConfig() { { "next-version", "1.0.0" } }; - var configuration = this.configurationProvider.ProvideInternal(this.repoPath, overrideConfiguration); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath, overrideConfiguration); configuration.LabelPrefix.ShouldBe("custom-label-prefix-from-yml"); } @@ -468,7 +469,7 @@ public void ShouldOverrideTagPrefixFromConfigFileWhenSetInOverrideConfig() { { "label-prefix", "custom-label-prefix-from-console" } }; - var configuration = this.configurationProvider.ProvideInternal(this.repoPath, overrideConfiguration); + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath, overrideConfiguration); configuration.LabelPrefix.ShouldBe("custom-label-prefix-from-console"); } diff --git a/src/GitVersion.Core.Tests/Configuration/Init/InitScenarios.cs b/src/GitVersion.Core.Tests/Configuration/Init/InitScenarios.cs index ea25577e2b..47b2d17dd3 100644 --- a/src/GitVersion.Core.Tests/Configuration/Init/InitScenarios.cs +++ b/src/GitVersion.Core.Tests/Configuration/Init/InitScenarios.cs @@ -30,6 +30,7 @@ public void CanSetNextVersion() var fileSystem = sp.GetRequiredService(); configurationProvider.Init(workingDirectory); - fileSystem.ReadAllText(PathHelper.Combine(workingDirectory, "GitVersion.yml")).ShouldMatchApproved(); + var configFile = PathHelper.Combine(workingDirectory, ConfigurationFileLocator.DefaultFileName); + fileSystem.ReadAllText(configFile).ShouldMatchApproved(); } } diff --git a/src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs b/src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs index cac6ef4c56..6d604d5b59 100644 --- a/src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs +++ b/src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs @@ -241,8 +241,9 @@ public void CacheFileIsMissing() logsMessages.ShouldContain("yml not found", Case.Insensitive, logsMessages); } - [Test] - public void ConfigChangeInvalidatesCache() + [TestCase(ConfigurationFileLocator.DefaultFileName)] + [TestCase(ConfigurationFileLocator.DefaultAlternativeFileName)] + public void ConfigChangeInvalidatesCache(string configFileName) { const string versionCacheFileContent = @" Major: 4 @@ -289,7 +290,7 @@ public void ConfigChangeInvalidatesCache() versionVariables = gitVersionCalculator.CalculateVersionVariables(); versionVariables.AssemblySemVer.ShouldBe("4.10.3.0"); - var configPath = PathHelper.Combine(fixture.RepositoryPath, ConfigurationFileLocator.DefaultFileName); + var configPath = PathHelper.Combine(fixture.RepositoryPath, configFileName); this.fileSystem.WriteAllText(configPath, "next-version: 5.0.0"); gitVersionCalculator = GetGitVersionCalculator(gitVersionOptions, fs: this.fileSystem); diff --git a/src/GitVersion.Core/Configuration/Abstractions/IConfigurationFileLocator.cs b/src/GitVersion.Core/Configuration/Abstractions/IConfigurationFileLocator.cs index fce68b6abf..3a716c613c 100644 --- a/src/GitVersion.Core/Configuration/Abstractions/IConfigurationFileLocator.cs +++ b/src/GitVersion.Core/Configuration/Abstractions/IConfigurationFileLocator.cs @@ -2,12 +2,8 @@ namespace GitVersion.Configuration; public interface IConfigurationFileLocator { - string FilePath { get; } - bool HasConfigFileAt(string workingDirectory); - string? GetConfigFilePath(string workingDirectory); - void Verify(GitVersionOptions gitVersionOptions, IGitRepositoryInfo repositoryInfo); - void Verify(string workingDirectory, string projectRootDirectory); - string? SelectConfigFilePath(GitVersionOptions gitVersionOptions, IGitRepositoryInfo repositoryInfo); - GitVersionConfiguration ReadConfig(string workingDirectory); - IReadOnlyDictionary? ReadOverrideConfiguration(string? workingDirectory); + bool TryGetConfigurationFile(string? workingDirectory, string? projectRootDirectory, out string? configFilePath); + GitVersionConfiguration ReadConfiguration(string? configFilePath); + IReadOnlyDictionary? ReadOverrideConfiguration(string? configFilePath); + void Verify(string? workingDirectory, string? projectRootDirectory); } diff --git a/src/GitVersion.Core/Configuration/ConfigurationExtensions.cs b/src/GitVersion.Core/Configuration/ConfigurationExtensions.cs index 441f97b34b..6d34762799 100644 --- a/src/GitVersion.Core/Configuration/ConfigurationExtensions.cs +++ b/src/GitVersion.Core/Configuration/ConfigurationExtensions.cs @@ -9,7 +9,7 @@ public static class ConfigurationExtensions public static EffectiveConfiguration GetEffectiveConfiguration(this GitVersionConfiguration configuration, IBranch branch) => GetEffectiveConfiguration(configuration, branch.NotNull().Name); - public static EffectiveConfiguration GetEffectiveConfiguration(this GitVersionConfiguration configuration, ReferenceName branchName) + private static EffectiveConfiguration GetEffectiveConfiguration(this GitVersionConfiguration configuration, ReferenceName branchName) { BranchConfiguration branchConfiguration = configuration.GetBranchConfiguration(branchName); return new EffectiveConfiguration(configuration, branchConfiguration); @@ -21,13 +21,7 @@ public static BranchConfiguration GetBranchConfiguration(this GitVersionConfigur public static BranchConfiguration GetBranchConfiguration(this GitVersionConfiguration configuration, ReferenceName branchName) { var branchConfiguration = GetBranchConfigurations(configuration, branchName.WithoutRemote).FirstOrDefault(); - branchConfiguration ??= new() - { - Name = branchName.WithoutRemote, - Regex = string.Empty, - Label = ConfigurationConstants.BranchNamePlaceholder, - Increment = IncrementStrategy.Inherit - }; + branchConfiguration ??= new() { Name = branchName.WithoutRemote, Regex = string.Empty, Label = ConfigurationConstants.BranchNamePlaceholder, Increment = IncrementStrategy.Inherit }; return branchConfiguration; } @@ -48,6 +42,7 @@ private static IEnumerable GetBranchConfigurations(GitVersi } } } + if (unknownBranchConfiguration != null) yield return unknownBranchConfiguration; } @@ -70,6 +65,7 @@ public static string GetBranchSpecificTag(this EffectiveConfiguration configurat { tagToUse = ConfigurationConstants.BranchNamePlaceholder; } + if (tagToUse.Contains(ConfigurationConstants.BranchNamePlaceholder)) { log.Info("Using branch name to calculate version tag"); @@ -80,13 +76,57 @@ public static string GetBranchSpecificTag(this EffectiveConfiguration configurat var branchNameTrimmed = branchName?.RegexReplace(configuration.BranchPrefixToTrim, string.Empty, RegexOptions.IgnoreCase); branchName = branchNameTrimmed.IsNullOrEmpty() ? branchName : branchNameTrimmed; } + branchName = branchName?.RegexReplace("[^a-zA-Z0-9-]", "-"); tagToUse = tagToUse.Replace(ConfigurationConstants.BranchNamePlaceholder, branchName); } + return tagToUse; } + public static (string GitDirectory, string WorkingTreeDirectory)? FindGitDir(this string path) + { + string? startingDir = path; + while (startingDir is not null) + { + var dirOrFilePath = Path.Combine(startingDir, ".git"); + if (Directory.Exists(dirOrFilePath)) + { + return (dirOrFilePath, Path.GetDirectoryName(dirOrFilePath)!); + } + + if (File.Exists(dirOrFilePath)) + { + string? relativeGitDirPath = ReadGitDirFromFile(dirOrFilePath); + if (!string.IsNullOrWhiteSpace(relativeGitDirPath)) + { + var fullGitDirPath = Path.GetFullPath(Path.Combine(startingDir, relativeGitDirPath)); + if (Directory.Exists(fullGitDirPath)) + { + return (fullGitDirPath, Path.GetDirectoryName(dirOrFilePath)!); + } + } + } + + startingDir = Path.GetDirectoryName(startingDir); + } + + return null; + } + + private static string? ReadGitDirFromFile(string fileName) + { + const string expectedPrefix = "gitdir: "; + var firstLineOfFile = File.ReadLines(fileName).FirstOrDefault(); + if (firstLineOfFile?.StartsWith(expectedPrefix) ?? false) + { + return firstLineOfFile[expectedPrefix.Length..]; // strip off the prefix, leaving just the path + } + + return null; + } + public static List> GetReleaseBranchConfiguration(this GitVersionConfiguration configuration) => configuration.Branches .Where(b => b.Value.IsReleaseBranch == true) diff --git a/src/GitVersion.Core/Configuration/ConfigurationFileLocator.cs b/src/GitVersion.Core/Configuration/ConfigurationFileLocator.cs index e3571c90ad..f5c5cbf5ec 100644 --- a/src/GitVersion.Core/Configuration/ConfigurationFileLocator.cs +++ b/src/GitVersion.Core/Configuration/ConfigurationFileLocator.cs @@ -8,81 +8,66 @@ namespace GitVersion.Configuration; public class ConfigurationFileLocator : IConfigurationFileLocator { public const string DefaultFileName = "GitVersion.yml"; + public const string DefaultAlternativeFileName = "GitVersion.yaml"; + private readonly IFileSystem fileSystem; + private readonly string? configurationFile; + public ConfigurationFileLocator(IFileSystem fileSystem, IOptions options) { this.fileSystem = fileSystem; - var configFile = options.Value.ConfigurationInfo.ConfigurationFile; - FilePath = !configFile.IsNullOrWhiteSpace() ? configFile : DefaultFileName; + this.configurationFile = options.Value.ConfigurationInfo.ConfigurationFile; } - public string FilePath { get; } - - public bool HasConfigFileAt(string workingDirectory) => this.fileSystem.Exists(PathHelper.Combine(workingDirectory, FilePath)); - - public string? GetConfigFilePath(string? workingDirectory) => workingDirectory != null ? PathHelper.Combine(workingDirectory, FilePath) : null; + public bool TryGetConfigurationFile(string? workingDirectory, string? projectRootDirectory, out string? configFilePath) + => + HasConfigurationFile(workingDirectory, out configFilePath) + || HasConfigurationFile(projectRootDirectory, out configFilePath); public void Verify(string? workingDirectory, string? projectRootDirectory) { - if (!Path.IsPathRooted(FilePath) && !this.fileSystem.PathsEqual(workingDirectory, projectRootDirectory)) - { + if (!Path.IsPathRooted(this.configurationFile) && !this.fileSystem.PathsEqual(workingDirectory, projectRootDirectory)) WarnAboutAmbiguousConfigFileSelection(workingDirectory, projectRootDirectory); - } - } - - public string? SelectConfigFilePath(GitVersionOptions gitVersionOptions, IGitRepositoryInfo repositoryInfo) - { - var workingDirectory = gitVersionOptions.WorkingDirectory; - var projectRootDirectory = repositoryInfo.ProjectRootDirectory; - - return GetConfigFilePath(HasConfigFileAt(workingDirectory) ? workingDirectory : projectRootDirectory); } - public GitVersionConfiguration ReadConfig(string workingDirectory) + public GitVersionConfiguration ReadConfiguration(string? configFilePath) { - var configFilePath = GetConfigFilePath(workingDirectory); + if (configFilePath == null || !this.fileSystem.Exists(configFilePath)) return new GitVersionConfiguration(); - if (configFilePath != null && this.fileSystem.Exists(configFilePath)) - { - var readAllText = this.fileSystem.ReadAllText(configFilePath); - var readConfig = ConfigurationSerializer.Read(new StringReader(readAllText)); + var readAllText = this.fileSystem.ReadAllText(configFilePath); + var readConfig = ConfigurationSerializer.Read(new StringReader(readAllText)); - VerifyReadConfig(readConfig); + VerifyReadConfig(readConfig); - return readConfig; - } - - return new GitVersionConfiguration(); + return readConfig; } - public IReadOnlyDictionary? ReadOverrideConfiguration(string? workingDirectory) + public IReadOnlyDictionary? ReadOverrideConfiguration(string? configFilePath) { - var configFilePath = GetConfigFilePath(workingDirectory); + if (configFilePath == null || !this.fileSystem.Exists(configFilePath)) return null; - Dictionary? configuration = null; - if (configFilePath != null && this.fileSystem.Exists(configFilePath)) - { - var readAllText = this.fileSystem.ReadAllText(configFilePath); + var readAllText = this.fileSystem.ReadAllText(configFilePath); - configuration = ConfigurationSerializer.Deserialize>(readAllText); - } - - return configuration; + return ConfigurationSerializer.Deserialize>(readAllText); } - public void Verify(GitVersionOptions gitVersionOptions, IGitRepositoryInfo repositoryInfo) + private bool HasConfigurationFile(string? workingDirectory, out string? path) { - if (!gitVersionOptions.RepositoryInfo.TargetUrl.IsNullOrWhiteSpace()) + bool HasConfigurationFileAt(string fileName, out string? configFile) { - // Assuming this is a dynamic repository. At this stage it's unsure whether we have - // any .git info so we need to skip verification - return; - } + configFile = null; + if (!this.fileSystem.Exists(PathHelper.Combine(workingDirectory, fileName))) return false; - var workingDirectory = gitVersionOptions.WorkingDirectory; - var projectRootDirectory = repositoryInfo.ProjectRootDirectory; + configFile = PathHelper.Combine(workingDirectory, fileName); + return true; + } - Verify(workingDirectory, projectRootDirectory); + path = null; + if (workingDirectory is null) return false; + return !this.configurationFile.IsNullOrWhiteSpace() + ? HasConfigurationFileAt(this.configurationFile, out path) + : HasConfigurationFileAt(DefaultFileName, out path) + || HasConfigurationFileAt(DefaultAlternativeFileName, out path); } private static void VerifyReadConfig(GitVersionConfiguration configuration) @@ -100,8 +85,8 @@ This is because mainline mode treats your entire git repository as an event sour private void WarnAboutAmbiguousConfigFileSelection(string? workingDirectory, string? projectRootDirectory) { - var workingConfigFile = GetConfigFilePath(workingDirectory); - var projectRootConfigFile = GetConfigFilePath(projectRootDirectory); + TryGetConfigurationFile(workingDirectory, null, out var workingConfigFile); + TryGetConfigurationFile(null, projectRootDirectory, out var projectRootConfigFile); var hasConfigInWorkingDirectory = workingConfigFile != null && this.fileSystem.Exists(workingConfigFile); var hasConfigInProjectRootDirectory = projectRootConfigFile != null && this.fileSystem.Exists(projectRootConfigFile); @@ -113,8 +98,12 @@ private void WarnAboutAmbiguousConfigFileSelection(string? workingDirectory, str if (!hasConfigInProjectRootDirectory && !hasConfigInWorkingDirectory) { - if (FilePath != DefaultFileName) + if (this.configurationFile != DefaultFileName && this.configurationFile != DefaultAlternativeFileName) + { + workingConfigFile = PathHelper.Combine(workingDirectory, this.configurationFile); + projectRootConfigFile = PathHelper.Combine(projectRootDirectory, this.configurationFile); throw new WarningException($"The configuration file was not found at '{workingConfigFile}' or '{projectRootConfigFile}'"); + } } } } diff --git a/src/GitVersion.Core/Configuration/ConfigurationProvider.cs b/src/GitVersion.Core/Configuration/ConfigurationProvider.cs index 2d321cab8f..030d5c1a8b 100644 --- a/src/GitVersion.Core/Configuration/ConfigurationProvider.cs +++ b/src/GitVersion.Core/Configuration/ConfigurationProvider.cs @@ -1,6 +1,7 @@ using GitVersion.Configuration.Init.Wizard; using GitVersion.Configuration.SupportedWorkflows; using GitVersion.Extensions; +using GitVersion.Helpers; using GitVersion.Logging; using Microsoft.Extensions.Options; using YamlDotNet.Core; @@ -29,19 +30,22 @@ public GitVersionConfiguration Provide(IReadOnlyDictionary? ove { var gitVersionOptions = this.options.Value; var workingDirectory = gitVersionOptions.WorkingDirectory; - var projectRootDirectory = FindGitDir(workingDirectory)?.WorkingTreeDirectory; + var projectRootDirectory = workingDirectory.FindGitDir()?.WorkingTreeDirectory; - var rootDirectory = this.configFileLocator.HasConfigFileAt(workingDirectory) ? workingDirectory : projectRootDirectory; - return ProvideInternal(rootDirectory, overrideConfiguration); + return this.configFileLocator.TryGetConfigurationFile(workingDirectory, projectRootDirectory, out var configFilePath) + ? ProvideConfiguration(configFilePath, overrideConfiguration) + : ProvideForDirectory(null, overrideConfiguration); } public void Init(string workingDirectory) { - var configFilePath = this.configFileLocator.GetConfigFilePath(workingDirectory); - var currentConfiguration = this.configFileLocator.ReadConfig(workingDirectory); + var gitVersionOptions = this.options.Value; + var fileName = gitVersionOptions.ConfigurationInfo.ConfigurationFile ?? ConfigurationFileLocator.DefaultFileName; + var configFilePath = PathHelper.Combine(workingDirectory, fileName); + var currentConfiguration = this.configFileLocator.ReadConfiguration(configFilePath); var configuration = this.configInitWizard.Run(currentConfiguration, workingDirectory); - if (configuration == null || configFilePath == null) return; + if (configuration == null) return; using var stream = this.fileSystem.OpenWrite(configFilePath); using var writer = new StreamWriter(stream); @@ -50,15 +54,23 @@ public void Init(string workingDirectory) stream.Flush(); } - internal GitVersionConfiguration ProvideInternal( - string? workingDirectory, IReadOnlyDictionary? overrideConfiguration = null) + internal GitVersionConfiguration ProvideForDirectory(string? workingDirectory, + IReadOnlyDictionary? overrideConfiguration = null) + { + this.configFileLocator.TryGetConfigurationFile(workingDirectory, null, out var configFilePath); + return ProvideConfiguration(configFilePath, overrideConfiguration); + } + + private GitVersionConfiguration ProvideConfiguration(string? configFile, + IReadOnlyDictionary? overrideConfiguration = null) { - var overrideConfigurationFromFile = this.configFileLocator.ReadOverrideConfiguration(workingDirectory); + var overrideConfigurationFromFile = this.configFileLocator.ReadOverrideConfiguration(configFile); var workflow = GetWorkflow(overrideConfiguration, overrideConfigurationFromFile); IConfigurationBuilder configurationBuilder = (workflow is null) - ? GitFlowConfigurationBuilder.New : ConfigurationBuilder.New; + ? GitFlowConfigurationBuilder.New + : ConfigurationBuilder.New; var overrideConfigurationFromWorkflow = WorkflowManager.GetOverrideConfiguration(workflow); foreach (var item in new[] { overrideConfigurationFromWorkflow, overrideConfigurationFromFile, overrideConfiguration }) @@ -74,7 +86,7 @@ internal GitVersionConfiguration ProvideInternal( { throw new WarningException( $"Could not build the configuration instance because following exception occurred: '{exception.Message}' " + - $"Please ensure that the /overrideconfig parameters are correct and the configuration file is in the correct format." + "Please ensure that the /overrideconfig parameters are correct and the configuration file is in the correct format." ); } } @@ -92,45 +104,4 @@ internal GitVersionConfiguration ProvideInternal( return workflow; } - - private static string? ReadGitDirFromFile(string fileName) - { - const string expectedPrefix = "gitdir: "; - var firstLineOfFile = File.ReadLines(fileName).FirstOrDefault(); - if (firstLineOfFile?.StartsWith(expectedPrefix) ?? false) - { - return firstLineOfFile[expectedPrefix.Length..]; // strip off the prefix, leaving just the path - } - - return null; - } - - private static (string GitDirectory, string WorkingTreeDirectory)? FindGitDir(string path) - { - string? startingDir = path; - while (startingDir is not null) - { - var dirOrFilePath = Path.Combine(startingDir, ".git"); - if (Directory.Exists(dirOrFilePath)) - { - return (dirOrFilePath, Path.GetDirectoryName(dirOrFilePath)!); - } - if (File.Exists(dirOrFilePath)) - { - string? relativeGitDirPath = ReadGitDirFromFile(dirOrFilePath); - if (!string.IsNullOrWhiteSpace(relativeGitDirPath)) - { - var fullGitDirPath = Path.GetFullPath(Path.Combine(startingDir, relativeGitDirPath)); - if (Directory.Exists(fullGitDirPath)) - { - return (fullGitDirPath, Path.GetDirectoryName(dirOrFilePath)!); - } - } - } - - startingDir = Path.GetDirectoryName(startingDir); - } - - return null; - } } diff --git a/src/GitVersion.Core/PublicAPI.Unshipped.txt b/src/GitVersion.Core/PublicAPI.Unshipped.txt index 23f6fe7fdd..472941d7ac 100644 --- a/src/GitVersion.Core/PublicAPI.Unshipped.txt +++ b/src/GitVersion.Core/PublicAPI.Unshipped.txt @@ -1,8 +1,4 @@ #nullable enable -const GitVersion.ReferenceName.LocalBranchPrefix = "refs/heads/" -> string! -const GitVersion.ReferenceName.RemotePrefix = "origin/" -> string! -const GitVersion.ReferenceName.RemoteTrackingBranchPrefix = "refs/remotes/" -> string! -const GitVersion.ReferenceName.TagPrefix = "refs/tags/" -> string! GitVersion.Agents.BuildAgentBase GitVersion.Agents.BuildAgentBase.BuildAgentBase(GitVersion.IEnvironment! environment, GitVersion.Logging.ILog! log) -> void GitVersion.Agents.BuildAgentBase.Environment.get -> GitVersion.IEnvironment! @@ -143,13 +139,9 @@ GitVersion.Configuration.ConfigurationException.ConfigurationException(string! m GitVersion.Configuration.ConfigurationExtensions GitVersion.Configuration.ConfigurationFileLocator GitVersion.Configuration.ConfigurationFileLocator.ConfigurationFileLocator(GitVersion.IFileSystem! fileSystem, Microsoft.Extensions.Options.IOptions! options) -> void -GitVersion.Configuration.ConfigurationFileLocator.FilePath.get -> string! -GitVersion.Configuration.ConfigurationFileLocator.GetConfigFilePath(string? workingDirectory) -> string? -GitVersion.Configuration.ConfigurationFileLocator.HasConfigFileAt(string! workingDirectory) -> bool -GitVersion.Configuration.ConfigurationFileLocator.ReadConfig(string! workingDirectory) -> GitVersion.Configuration.GitVersionConfiguration! -GitVersion.Configuration.ConfigurationFileLocator.ReadOverrideConfiguration(string? workingDirectory) -> System.Collections.Generic.IReadOnlyDictionary? -GitVersion.Configuration.ConfigurationFileLocator.SelectConfigFilePath(GitVersion.GitVersionOptions! gitVersionOptions, GitVersion.IGitRepositoryInfo! repositoryInfo) -> string? -GitVersion.Configuration.ConfigurationFileLocator.Verify(GitVersion.GitVersionOptions! gitVersionOptions, GitVersion.IGitRepositoryInfo! repositoryInfo) -> void +GitVersion.Configuration.ConfigurationFileLocator.ReadConfiguration(string? configFilePath) -> GitVersion.Configuration.GitVersionConfiguration! +GitVersion.Configuration.ConfigurationFileLocator.ReadOverrideConfiguration(string? configFilePath) -> System.Collections.Generic.IReadOnlyDictionary? +GitVersion.Configuration.ConfigurationFileLocator.TryGetConfigurationFile(string? workingDirectory, string? projectRootDirectory, out string? configFilePath) -> bool GitVersion.Configuration.ConfigurationFileLocator.Verify(string? workingDirectory, string? projectRootDirectory) -> void GitVersion.Configuration.ConfigurationModule GitVersion.Configuration.ConfigurationModule.ConfigurationModule() -> void @@ -238,14 +230,10 @@ GitVersion.Configuration.GitVersionConfiguration.UpdateBuildNumber.set -> void GitVersion.Configuration.GitVersionConfiguration.Workflow.get -> string? GitVersion.Configuration.GitVersionConfiguration.Workflow.set -> void GitVersion.Configuration.IConfigurationFileLocator -GitVersion.Configuration.IConfigurationFileLocator.FilePath.get -> string! -GitVersion.Configuration.IConfigurationFileLocator.GetConfigFilePath(string! workingDirectory) -> string? -GitVersion.Configuration.IConfigurationFileLocator.HasConfigFileAt(string! workingDirectory) -> bool -GitVersion.Configuration.IConfigurationFileLocator.ReadConfig(string! workingDirectory) -> GitVersion.Configuration.GitVersionConfiguration! -GitVersion.Configuration.IConfigurationFileLocator.ReadOverrideConfiguration(string? workingDirectory) -> System.Collections.Generic.IReadOnlyDictionary? -GitVersion.Configuration.IConfigurationFileLocator.SelectConfigFilePath(GitVersion.GitVersionOptions! gitVersionOptions, GitVersion.IGitRepositoryInfo! repositoryInfo) -> string? -GitVersion.Configuration.IConfigurationFileLocator.Verify(GitVersion.GitVersionOptions! gitVersionOptions, GitVersion.IGitRepositoryInfo! repositoryInfo) -> void -GitVersion.Configuration.IConfigurationFileLocator.Verify(string! workingDirectory, string! projectRootDirectory) -> void +GitVersion.Configuration.IConfigurationFileLocator.ReadConfiguration(string? configFilePath) -> GitVersion.Configuration.GitVersionConfiguration! +GitVersion.Configuration.IConfigurationFileLocator.ReadOverrideConfiguration(string? configFilePath) -> System.Collections.Generic.IReadOnlyDictionary? +GitVersion.Configuration.IConfigurationFileLocator.TryGetConfigurationFile(string? workingDirectory, string? projectRootDirectory, out string? configFilePath) -> bool +GitVersion.Configuration.IConfigurationFileLocator.Verify(string? workingDirectory, string? projectRootDirectory) -> void GitVersion.Configuration.IConfigurationProvider GitVersion.Configuration.IConfigurationProvider.Init(string! workingDirectory) -> void GitVersion.Configuration.IConfigurationProvider.Provide(System.Collections.Generic.IReadOnlyDictionary? overrideConfiguration = null) -> GitVersion.Configuration.GitVersionConfiguration! @@ -556,9 +544,9 @@ GitVersion.IncrementStrategy.Patch = 3 -> GitVersion.IncrementStrategy GitVersion.IncrementStrategyExtensions GitVersion.LockedFileException GitVersion.LockedFileException.LockedFileException() -> void +GitVersion.LockedFileException.LockedFileException(System.Exception! inner) -> void GitVersion.LockedFileException.LockedFileException(string? message) -> void GitVersion.LockedFileException.LockedFileException(string? message, System.Exception? innerException) -> void -GitVersion.LockedFileException.LockedFileException(System.Exception! inner) -> void GitVersion.Logging.ConsoleAdapter GitVersion.Logging.ConsoleAdapter.ConsoleAdapter() -> void GitVersion.Logging.ConsoleAdapter.ReadLine() -> string? @@ -720,7 +708,6 @@ GitVersion.OutputVariables.VersionVariablesJsonModel.WeightedPreReleaseNumber.ge GitVersion.OutputVariables.VersionVariablesJsonModel.WeightedPreReleaseNumber.set -> void GitVersion.OutputVariables.VersionVariablesJsonStringConverter GitVersion.OutputVariables.VersionVariablesJsonStringConverter.VersionVariablesJsonStringConverter() -> void -GitVersion.ReferenceName.IsLocalBranch.get -> bool GitVersion.RefSpecDirection GitVersion.RefSpecDirection.Fetch = 0 -> GitVersion.RefSpecDirection GitVersion.RefSpecDirection.Push = 1 -> GitVersion.RefSpecDirection @@ -730,6 +717,7 @@ GitVersion.ReferenceName.CompareTo(GitVersion.ReferenceName? other) -> int GitVersion.ReferenceName.Equals(GitVersion.ReferenceName? other) -> bool GitVersion.ReferenceName.EquivalentTo(string? name) -> bool GitVersion.ReferenceName.Friendly.get -> string! +GitVersion.ReferenceName.IsLocalBranch.get -> bool GitVersion.ReferenceName.IsPullRequest.get -> bool GitVersion.ReferenceName.IsRemoteBranch.get -> bool GitVersion.ReferenceName.IsTag.get -> bool @@ -989,7 +977,12 @@ const GitVersion.Configuration.ConfigurationConstants.SupportBranchKey = "suppor const GitVersion.Configuration.ConfigurationConstants.SupportBranchRegex = "^support[/-]" -> string! const GitVersion.Configuration.ConfigurationConstants.UnknownBranchKey = "unknown" -> string! const GitVersion.Configuration.ConfigurationConstants.UnknownBranchRegex = ".*" -> string! +const GitVersion.Configuration.ConfigurationFileLocator.DefaultAlternativeFileName = "GitVersion.yaml" -> string! const GitVersion.Configuration.ConfigurationFileLocator.DefaultFileName = "GitVersion.yml" -> string! +const GitVersion.ReferenceName.LocalBranchPrefix = "refs/heads/" -> string! +const GitVersion.ReferenceName.RemotePrefix = "origin/" -> string! +const GitVersion.ReferenceName.RemoteTrackingBranchPrefix = "refs/remotes/" -> string! +const GitVersion.ReferenceName.TagPrefix = "refs/tags/" -> string! const GitVersion.VersionCalculation.IncrementStrategyFinder.DefaultMajorPattern = "\\+semver:\\s?(breaking|major)" -> string! const GitVersion.VersionCalculation.IncrementStrategyFinder.DefaultMinorPattern = "\\+semver:\\s?(feature|minor)" -> string! const GitVersion.VersionCalculation.IncrementStrategyFinder.DefaultNoBumpPattern = "\\+semver:\\s?(none|skip)" -> string! @@ -1080,11 +1073,11 @@ readonly GitVersion.Configuration.Init.Wizard.ConfigInitWizardStep.StepFactory - static GitVersion.BranchCommit.operator !=(GitVersion.BranchCommit left, GitVersion.BranchCommit right) -> bool static GitVersion.BranchCommit.operator ==(GitVersion.BranchCommit left, GitVersion.BranchCommit right) -> bool static GitVersion.Configuration.BranchConfigurationBuilder.New.get -> GitVersion.Configuration.BranchConfigurationBuilder! +static GitVersion.Configuration.ConfigurationExtensions.FindGitDir(this string! path) -> (string! GitDirectory, string! WorkingTreeDirectory)? static GitVersion.Configuration.ConfigurationExtensions.GetBranchConfiguration(this GitVersion.Configuration.GitVersionConfiguration! configuration, GitVersion.IBranch! branch) -> GitVersion.Configuration.BranchConfiguration! static GitVersion.Configuration.ConfigurationExtensions.GetBranchConfiguration(this GitVersion.Configuration.GitVersionConfiguration! configuration, GitVersion.ReferenceName! branchName) -> GitVersion.Configuration.BranchConfiguration! static GitVersion.Configuration.ConfigurationExtensions.GetBranchSpecificTag(this GitVersion.Configuration.EffectiveConfiguration! configuration, GitVersion.Logging.ILog! log, string? branchFriendlyName, string? branchNameOverride) -> string! static GitVersion.Configuration.ConfigurationExtensions.GetEffectiveConfiguration(this GitVersion.Configuration.GitVersionConfiguration! configuration, GitVersion.IBranch! branch) -> GitVersion.Configuration.EffectiveConfiguration! -static GitVersion.Configuration.ConfigurationExtensions.GetEffectiveConfiguration(this GitVersion.Configuration.GitVersionConfiguration! configuration, GitVersion.ReferenceName! branchName) -> GitVersion.Configuration.EffectiveConfiguration! static GitVersion.Configuration.ConfigurationExtensions.GetFallbackBranchConfiguration(this GitVersion.Configuration.GitVersionConfiguration! configuration) -> GitVersion.Configuration.BranchConfiguration! static GitVersion.Configuration.ConfigurationExtensions.GetReleaseBranchConfiguration(this GitVersion.Configuration.GitVersionConfiguration! configuration) -> System.Collections.Generic.List>! static GitVersion.Configuration.ConfigurationExtensions.IsReleaseBranch(this GitVersion.Configuration.GitVersionConfiguration! configuration, GitVersion.IBranch! branch) -> bool diff --git a/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs b/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs index d14b4d76b1..2cc0e49917 100644 --- a/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs +++ b/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs @@ -17,8 +17,8 @@ public class GitVersionCacheKeyFactory : IGitVersionCacheKeyFactory private readonly IGitRepositoryInfo repositoryInfo; public GitVersionCacheKeyFactory(IFileSystem fileSystem, ILog log, - IOptions options, IConfigurationFileLocator configFileLocator, - IGitRepository gitRepository, IGitRepositoryInfo repositoryInfo) + IOptions options, IConfigurationFileLocator configFileLocator, + IGitRepository gitRepository, IGitRepositoryInfo repositoryInfo) { this.fileSystem = fileSystem.NotNull(); this.log = log.NotNull(); @@ -146,6 +146,7 @@ private string GetRepositorySnapshotHash() { return head.Name.Canonical; } + var hash = string.Join(":", head.Name.Canonical, head.Tip.Sha); return GetHash(hash); } @@ -168,11 +169,13 @@ private string GetConfigFileHash() { // will return the same hash even when configuration file will be moved // from workingDirectory to rootProjectDirectory. It's OK. Configuration essentially is the same. - var configFilePath = this.configFileLocator.SelectConfigFilePath(this.options.Value, this.repositoryInfo); - if (configFilePath == null || !this.fileSystem.Exists(configFilePath)) - { + var workingDirectory = this.options.Value.WorkingDirectory; + var projectRootDirectory = this.repositoryInfo.ProjectRootDirectory; + + if (!this.configFileLocator.TryGetConfigurationFile(workingDirectory, projectRootDirectory, out var configFilePath)) return string.Empty; - } + if (configFilePath == null) return string.Empty; + if (!this.fileSystem.Exists(configFilePath)) return string.Empty; var configFileContent = this.fileSystem.ReadAllText(configFilePath); return GetHash(configFileContent); @@ -190,6 +193,7 @@ private static string GetHash(string textToHash) { return string.Empty; } + var bytes = Encoding.UTF8.GetBytes(textToHash); var hashedBytes = SHA1.HashData(bytes); var hashedString = BitConverter.ToString(hashedBytes); diff --git a/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersion.cs b/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersion.cs index 8a79db849b..7081bc6a5f 100644 --- a/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersion.cs +++ b/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersion.cs @@ -301,7 +301,7 @@ public string ToString(string? format, IFormatProvider? formatProvider) public SemanticVersion IncrementVersion(VersionField incrementStrategy) { var incremented = new SemanticVersion(this); - if (incremented.PreReleaseTag.HasTag() != true) + if (!incremented.PreReleaseTag.HasTag()) { switch (incrementStrategy) { diff --git a/src/GitVersion.Core/VersionCalculation/VariableProvider.cs b/src/GitVersion.Core/VersionCalculation/VariableProvider.cs index 2bd074b57e..52b592c447 100644 --- a/src/GitVersion.Core/VersionCalculation/VariableProvider.cs +++ b/src/GitVersion.Core/VersionCalculation/VariableProvider.cs @@ -25,7 +25,7 @@ public VersionVariables GetVariablesFor(SemanticVersion semanticVersion, Effecti { semanticVersion = new SemanticVersion(semanticVersion); // Continuous Deployment always requires a pre-release tag unless the commit is tagged - if (semanticVersion.PreReleaseTag.HasTag() != true) + if (!semanticVersion.PreReleaseTag.HasTag()) { semanticVersion.PreReleaseTag.Name = configuration.GetBranchSpecificTag(this.log, semanticVersion.BuildMetaData.Branch, null); if (semanticVersion.PreReleaseTag.Name.IsNullOrEmpty()) diff --git a/src/GitVersion.LibGit2Sharp/Git/GitRepository.extended.cs b/src/GitVersion.LibGit2Sharp/Git/GitRepository.extended.cs index c7cb016e61..8eb35ecc5f 100644 --- a/src/GitVersion.LibGit2Sharp/Git/GitRepository.extended.cs +++ b/src/GitVersion.LibGit2Sharp/Git/GitRepository.extended.cs @@ -110,9 +110,8 @@ private DirectReference GetPullRequestReference(AuthenticationInfo auth, LibGit2 } } - return refs.First(); + return refs[0]; } - internal static string? Discover(string? path) => Repository.Discover(path); private static FetchOptions GetFetchOptions(AuthenticationInfo auth) => new() { CredentialsProvider = GetCredentialsProvider(auth) }; private static CloneOptions GetCloneOptions(AuthenticationInfo auth) => diff --git a/src/GitVersion.LibGit2Sharp/Git/GitRepositoryInfo.cs b/src/GitVersion.LibGit2Sharp/Git/GitRepositoryInfo.cs index 6dbfc7e066..65e8aaead9 100644 --- a/src/GitVersion.LibGit2Sharp/Git/GitRepositoryInfo.cs +++ b/src/GitVersion.LibGit2Sharp/Git/GitRepositoryInfo.cs @@ -63,7 +63,7 @@ public GitRepositoryInfo(IOptions options) { var gitDirectory = !DynamicGitRepositoryPath.IsNullOrWhiteSpace() ? DynamicGitRepositoryPath - : GitRepository.Discover(gitVersionOptions.WorkingDirectory); + : Repository.Discover(gitVersionOptions.WorkingDirectory); gitDirectory = gitDirectory?.TrimEnd('/', '\\'); if (gitDirectory.IsNullOrEmpty()) @@ -82,7 +82,7 @@ private string GetProjectRootDirectory() return gitVersionOptions.WorkingDirectory; } - var gitDirectory = GitRepository.Discover(gitVersionOptions.WorkingDirectory); + var gitDirectory = Repository.Discover(gitVersionOptions.WorkingDirectory); if (gitDirectory.IsNullOrEmpty()) throw new DirectoryNotFoundException("Cannot find the .git directory"); @@ -110,5 +110,4 @@ private static bool GitRepoHasMatchingRemote(string possiblePath, string targetU return false; } } - } diff --git a/src/GitVersion.MsBuild.Tests/Tasks/TestTaskBase.cs b/src/GitVersion.MsBuild.Tests/Tasks/TestTaskBase.cs index c7ccb7dd31..9b5e7b4e91 100644 --- a/src/GitVersion.MsBuild.Tests/Tasks/TestTaskBase.cs +++ b/src/GitVersion.MsBuild.Tests/Tasks/TestTaskBase.cs @@ -25,7 +25,7 @@ protected static MsBuildTaskFixtureResult ExecuteMsBuildTask(T task) where AddOverrides(task); var msbuildFixture = new MsBuildTaskFixture(fixture); var result = msbuildFixture.Execute(task); - if (result.Success == false) Console.WriteLine(result.Log); + if (!result.Success) Console.WriteLine(result.Log); return result; } @@ -38,7 +38,7 @@ protected static MsBuildExeFixtureResult ExecuteMsBuildExe(Action ExecuteMsBuildTaskInAzurePipeline ExecuteMsBuildTaskInGitHubActions("GITHUB_ENV", envFilePath) ); var result = msbuildFixture.Execute(task); - if (result.Success == false) + if (!result.Success) Console.WriteLine(result.Log); return result; } @@ -91,7 +91,7 @@ protected static MsBuildExeFixtureResult ExecuteMsBuildExeInAzurePipeline(Action msbuildFixture.WithEnv(env.ToArray()); var result = msbuildFixture.Execute(); - if (result.MsBuild.OverallSuccess == false) Console.WriteLine(result.Output); + if (!result.MsBuild.OverallSuccess) Console.WriteLine(result.Output); return result; } private static void AddOverrides(GitVersionTaskBase task) => diff --git a/src/GitVersion.Output/AssemblyInfo/ProjectFileUpdater.cs b/src/GitVersion.Output/AssemblyInfo/ProjectFileUpdater.cs index d75dce7ab8..7af1c15501 100644 --- a/src/GitVersion.Output/AssemblyInfo/ProjectFileUpdater.cs +++ b/src/GitVersion.Output/AssemblyInfo/ProjectFileUpdater.cs @@ -133,7 +133,7 @@ public bool CanUpdateProjectFile(XElement xmlRoot) } var lastGenerateAssemblyInfoElement = propertyGroups.SelectMany(s => s.Elements("GenerateAssemblyInfo")).LastOrDefault(); - if (lastGenerateAssemblyInfoElement != null && (bool)lastGenerateAssemblyInfoElement == false) + if (lastGenerateAssemblyInfoElement != null && !(bool)lastGenerateAssemblyInfoElement) { this.log.Warning("Project file specifies false: versions set in this project file will not affect the output artifacts."); return false;