diff --git a/docs/configuration.md b/docs/configuration.md index 26f9cf2eec..9e4059ba34 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -4,6 +4,8 @@ GitVersion 3.0 is mainly powered by configuration and no longer has branching st ## Configuration tool If you run `GitVersion init` you will be launched into a configuration tool, it can help you configure GitVersion the way you want it. +Once complete, the `init` command will create a `GitVersion.yml` file in the working directory. It can be the root repository directory or any subdirectory in case you have a single repository for more than one project or are restricted to commit into a subdirectory. + **Note:** GitVersion ships with internal default configuration which works with GitHubFlow and GitFlow, probably with others too. The *develop* branch is set to `ContinuousDeployment` mode by default as we have found that is generally what is needed when using GitFlow. diff --git a/docs/usage/command-line.md b/docs/usage/command-line.md index 01e7636731..d29b18ec18 100644 --- a/docs/usage/command-line.md +++ b/docs/usage/command-line.md @@ -54,4 +54,14 @@ Will result in command line argument error ### Example: When AssemblyInfo.cs and AssemblyVersionInfo.cs already exist `GitVersion.exe /updateassemblyinfo AssemblyInfo.cs AssemblyVersionInfo.cs` -Will iterate through each file and update known attributes (`AssemblyVersion`, `AssemblyFileVersion`, `AssemblyInformationalVersion`). \ No newline at end of file +Will iterate through each file and update known attributes (`AssemblyVersion`, `AssemblyFileVersion`, `AssemblyInformationalVersion`). + +## Override config +`/overrideconfig [key=value]` will override appropriate key from 'GitVersion.yml'. + +At the moment only `tag-prefix` option is supported. Read more about [Configuration](/configuration/). + +It will not change config file 'GitVersion.yml'. + +### Example: How to override configuration option 'tag-prefix' to use prefix 'custom' +`GitVersion.exe /output json /overrideconfig tag-prefix=custom` \ No newline at end of file diff --git a/src/GitVersionCore.Tests/ConfigProviderTests.cs b/src/GitVersionCore.Tests/ConfigProviderTests.cs index a9136a2bc7..643c505c67 100644 --- a/src/GitVersionCore.Tests/ConfigProviderTests.cs +++ b/src/GitVersionCore.Tests/ConfigProviderTests.cs @@ -1,25 +1,31 @@ +using GitVersion; +using GitVersion.Helpers; +using NUnit.Framework; +using Shouldly; using System; +using System.ComponentModel; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; -using GitVersion; -using GitVersion.Helpers; -using NUnit.Framework; -using Shouldly; using YamlDotNet.Serialization; [TestFixture] public class ConfigProviderTests { + private const string DefaultRepoPath = "c:\\MyGitRepo"; + private const string DefaultWorkingPath = "c:\\MyGitRepo\\Working"; + string repoPath; + string workingPath; IFileSystem fileSystem; [SetUp] public void Setup() { fileSystem = new TestFileSystem(); - repoPath = "c:\\MyGitRepo"; + repoPath = DefaultRepoPath; + workingPath = DefaultWorkingPath; } [Test] @@ -112,7 +118,7 @@ public void CanProvideConfigForNewBranch() tag: bugfix"; SetupConfigFileContent(text); var config = ConfigurationProvider.Provide(repoPath, fileSystem); - + config.Branches["bug[/-]"].Tag.ShouldBe("bugfix"); } @@ -145,10 +151,10 @@ public void NextVersionCanHavePatch() config.NextVersion.ShouldBe("2.12.654651698"); } - + [Test] - [Category("NoMono")] - [Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] + [NUnit.Framework.Category("NoMono")] + [NUnit.Framework.Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] [MethodImpl(MethodImplOptions.NoInlining)] public void CanWriteOutEffectiveConfiguration() { @@ -228,18 +234,52 @@ public void VerifyAliases() propertiesMissingAlias.ShouldBeEmpty(); } - [Test] - public void WarnOnExistingGitVersionConfigYamlFile() + [TestCase(DefaultRepoPath)] + [TestCase(DefaultWorkingPath)] + public void WarnOnExistingGitVersionConfigYamlFile(string path) { - SetupConfigFileContent(string.Empty, "GitVersionConfig.yaml"); + SetupConfigFileContent(string.Empty, ConfigurationProvider.ObsoleteConfigFileName, path); - var s = string.Empty; - Action action = info => { s = info; }; + var logOutput = string.Empty; + Action action = info => { logOutput = info; }; Logger.SetLoggers(action, action, action); - ConfigurationProvider.Provide(repoPath, fileSystem); + ConfigurationProvider.Verify(workingPath, repoPath, fileSystem); - s.Contains("'GitVersionConfig.yaml' is deprecated, use 'GitVersion.yml' instead.").ShouldBe(true); + var configFileDeprecatedWarning = string.Format("{0}' is deprecated, use '{1}' instead", ConfigurationProvider.ObsoleteConfigFileName, ConfigurationProvider.DefaultConfigFileName); + logOutput.Contains(configFileDeprecatedWarning).ShouldBe(true); + } + + [TestCase(DefaultRepoPath)] + [TestCase(DefaultWorkingPath)] + public void WarnOnAmbiguousConfigFilesAtTheSameProjectRootDirectory(string path) + { + SetupConfigFileContent(string.Empty, ConfigurationProvider.ObsoleteConfigFileName, path); + SetupConfigFileContent(string.Empty, ConfigurationProvider.DefaultConfigFileName, path); + + var logOutput = string.Empty; + Action action = info => { logOutput = info; }; + Logger.SetLoggers(action, action, action); + + ConfigurationProvider.Verify(workingPath, repoPath, fileSystem); + + var configFileDeprecatedWarning = string.Format("Ambiguous config files at '{0}'", path); + logOutput.Contains(configFileDeprecatedWarning).ShouldBe(true); + } + + [TestCase(ConfigurationProvider.DefaultConfigFileName, ConfigurationProvider.DefaultConfigFileName)] + [TestCase(ConfigurationProvider.DefaultConfigFileName, ConfigurationProvider.ObsoleteConfigFileName)] + [TestCase(ConfigurationProvider.ObsoleteConfigFileName, ConfigurationProvider.DefaultConfigFileName)] + [TestCase(ConfigurationProvider.ObsoleteConfigFileName, ConfigurationProvider.ObsoleteConfigFileName)] + public void ThrowsExceptionOnAmbiguousConfigFileLocation(string repoConfigFile, string workingConfigFile) + { + var repositoryConfigFilePath = SetupConfigFileContent(string.Empty, repoConfigFile, repoPath); + var workingDirectoryConfigFilePath = SetupConfigFileContent(string.Empty, workingConfigFile, workingPath); + + WarningException exception = Should.Throw(() => { ConfigurationProvider.Verify(workingPath, repoPath, fileSystem); }); + + var expecedMessage = string.Format("Ambiguous config file selection from '{0}' and '{1}'", workingDirectoryConfigFilePath, repositoryConfigFilePath); + exception.Message.ShouldBe(expecedMessage); } [Test] @@ -256,8 +296,16 @@ public void NoWarnOnGitVersionYmlFile() s.Length.ShouldBe(0); } - void SetupConfigFileContent(string text, string fileName = "GitVersion.yml") + string SetupConfigFileContent(string text, string fileName = ConfigurationProvider.DefaultConfigFileName) { - fileSystem.WriteAllText(Path.Combine(repoPath, fileName), text); + return SetupConfigFileContent(text, fileName, repoPath); + } + + string SetupConfigFileContent(string text, string fileName, string path) + { + var fullPath = Path.Combine(path, fileName); + fileSystem.WriteAllText(fullPath, text); + + return fullPath; } -} \ No newline at end of file +} diff --git a/src/GitVersionCore.Tests/ExecuteCoreTests.cs b/src/GitVersionCore.Tests/ExecuteCoreTests.cs index 85852b6a3c..48b6b4647b 100644 --- a/src/GitVersionCore.Tests/ExecuteCoreTests.cs +++ b/src/GitVersionCore.Tests/ExecuteCoreTests.cs @@ -1,11 +1,11 @@ -using System; -using System.IO; -using System.Text; -using GitTools.Testing; +using GitTools.Testing; using GitVersion; using GitVersion.Helpers; using NUnit.Framework; using Shouldly; +using System; +using System.IO; +using System.Text; [TestFixture] public class ExecuteCoreTests @@ -60,6 +60,59 @@ public void CacheFileExistsOnDisk() info.ShouldContain("Deserializing version variables from cache file", () => info); } + + [Test] + public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDynamicallyCalculatedWithoutSavingInCache() + { + const string versionCacheFileContent = @" +Major: 4 +Minor: 10 +Patch: 3 +PreReleaseTag: test.19 +PreReleaseTagWithDash: -test.19 +PreReleaseLabel: test +PreReleaseNumber: 19 +BuildMetaData: +BuildMetaDataPadded: +FullBuildMetaData: Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f +MajorMinorPatch: 4.10.3 +SemVer: 4.10.3-test.19 +LegacySemVer: 4.10.3-test19 +LegacySemVerPadded: 4.10.3-test0019 +AssemblySemVer: 4.10.3.0 +FullSemVer: 4.10.3-test.19 +InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f +BranchName: feature/test +Sha: dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f +NuGetVersionV2: 4.10.3-test0019 +NuGetVersion: 4.10.3-test0019 +CommitsSinceVersionSource: 19 +CommitsSinceVersionSourcePadded: 0019 +CommitDate: 2015-11-10 +"; + + var versionAndBranchFinder = new ExecuteCore(fileSystem); + + RepositoryScope(versionAndBranchFinder, (fixture, vv) => + { + fileSystem.WriteAllText(vv.FileName, versionCacheFileContent); + + var gitPreparer = new GitPreparer(null, null, null, false, fixture.RepositoryPath); + var cacheDirectory = GitVersionCache.GetCacheDirectory(gitPreparer); + + var cacheDirectoryTimestamp = fileSystem.GetLastDirectoryWrite(cacheDirectory); + + vv = versionAndBranchFinder.ExecuteGitVersion(null, null, null, null, false, fixture.RepositoryPath, null, new Config() { TagPrefix = "prefix" }); + + vv.AssemblySemVer.ShouldBe("0.1.0.0"); + + var cachedDirectoryTimestampAfter = fileSystem.GetLastDirectoryWrite(cacheDirectory); + cachedDirectoryTimestampAfter.ShouldBe(cacheDirectoryTimestamp, () => "Cache was updated when override config was set"); + }); + + // TODO info.ShouldContain("Override config from command line", () => info); + } + [Test] public void CacheFileIsMissing() { diff --git a/src/GitVersionCore.Tests/TestFileSystem.cs b/src/GitVersionCore.Tests/TestFileSystem.cs index 2828223d03..f78d9c890c 100644 --- a/src/GitVersionCore.Tests/TestFileSystem.cs +++ b/src/GitVersionCore.Tests/TestFileSystem.cs @@ -101,4 +101,9 @@ public long GetLastDirectoryWrite(string path) { return 1; } + + public bool PathsEqual(string path, string otherPath) + { + return path == otherPath; + } } \ No newline at end of file diff --git a/src/GitVersionCore.Tests/VersionFilters/MinDateVersionFilterTests.cs b/src/GitVersionCore.Tests/VersionFilters/MinDateVersionFilterTests.cs index 8a5b7c9c7d..abff9c2d23 100644 --- a/src/GitVersionCore.Tests/VersionFilters/MinDateVersionFilterTests.cs +++ b/src/GitVersionCore.Tests/VersionFilters/MinDateVersionFilterTests.cs @@ -1,10 +1,9 @@ -using System; -using GitVersion; +using GitVersion; using GitVersion.VersionCalculation.BaseVersionCalculators; using GitVersion.VersionFilters; -using LibGit2Sharp; using NUnit.Framework; using Shouldly; +using System; namespace GitVersionCore.Tests.VersionFilters { @@ -14,7 +13,6 @@ public class MinDateVersionFilterTests [Test] public void VerifyNullGuard() { - var commit = new MockCommit(); var dummy = DateTimeOffset.UtcNow.AddSeconds(1.0); var sut = new MinDateVersionFilter(dummy); @@ -51,8 +49,7 @@ public void WhenShaMismatchShouldNotExclude() [Test] public void ExcludeShouldAcceptVersionWithNullCommit() { - Commit nullCommit = null; - var version = new BaseVersion("dummy", false, new SemanticVersion(1), nullCommit, string.Empty); + var version = new BaseVersion("dummy", false, new SemanticVersion(1), null, string.Empty); var futureDate = DateTimeOffset.UtcNow.AddYears(1); var sut = new MinDateVersionFilter(futureDate); diff --git a/src/GitVersionCore.Tests/VersionFilters/ShaVersionFilterTests.cs b/src/GitVersionCore.Tests/VersionFilters/ShaVersionFilterTests.cs index 120fd6dd9d..8dbaa0e327 100644 --- a/src/GitVersionCore.Tests/VersionFilters/ShaVersionFilterTests.cs +++ b/src/GitVersionCore.Tests/VersionFilters/ShaVersionFilterTests.cs @@ -2,7 +2,6 @@ using GitVersion; using GitVersion.VersionCalculation.BaseVersionCalculators; using GitVersion.VersionFilters; -using LibGit2Sharp; using NUnit.Framework; using Shouldly; @@ -54,8 +53,7 @@ public void WhenShaMismatchShouldNotExclude() [Test] public void ExcludeShouldAcceptVersionWithNullCommit() { - Commit nullCommit = null; - var version = new BaseVersion("dummy", false, new SemanticVersion(1), nullCommit, string.Empty); + var version = new BaseVersion("dummy", false, new SemanticVersion(1), null, string.Empty); var sut = new ShaVersionFilter(new[] { "mismatched" }); string reason; diff --git a/src/GitVersionCore/Configuration/ConfigurationProvider.cs b/src/GitVersionCore/Configuration/ConfigurationProvider.cs index dc6ecf4741..2241308c4b 100644 --- a/src/GitVersionCore/Configuration/ConfigurationProvider.cs +++ b/src/GitVersionCore/Configuration/ConfigurationProvider.cs @@ -1,16 +1,45 @@ namespace GitVersion { - using System.Collections.Generic; + using GitVersion.Configuration.Init.Wizard; + using GitVersion.Helpers; + using System.ComponentModel; using System.IO; using System.Linq; using System.Text; - using GitVersion.Configuration.Init.Wizard; - using GitVersion.Helpers; public class ConfigurationProvider { internal const string DefaultTagPrefix = "[vV]"; + public const string DefaultConfigFileName = "GitVersion.yml"; + public const string ObsoleteConfigFileName = "GitVersionConfig.yaml"; + + public static Config Provide(GitPreparer gitPreparer, IFileSystem fileSystem, bool applyDefaults = true, Config overrideConfig = null) + { + var workingDirectory = gitPreparer.WorkingDirectory; + var projectRootDirectory = gitPreparer.GetProjectRootDirectory(); + + if (HasConfigFileAt(workingDirectory, fileSystem)) + { + return Provide(workingDirectory, fileSystem, applyDefaults, overrideConfig); + } + + return Provide(projectRootDirectory, fileSystem, applyDefaults, overrideConfig); + } + + public static string SelectConfigFilePath(GitPreparer gitPreparer, IFileSystem fileSystem) + { + var workingDirectory = gitPreparer.WorkingDirectory; + var projectRootDirectory = gitPreparer.GetProjectRootDirectory(); + + if (HasConfigFileAt(workingDirectory, fileSystem)) + { + return GetConfigFilePath(workingDirectory, fileSystem); + } + + return GetConfigFilePath(projectRootDirectory, fileSystem); + } + public static Config Provide(string workingDirectory, IFileSystem fileSystem, bool applyDefaults = true, Config overrideConfig = null) { var readConfig = ReadConfig(workingDirectory, fileSystem); @@ -70,31 +99,28 @@ public static void ApplyOverridesTo(Config config, Config overrideConfig) static void MigrateBranches(Config config) { - // Map of current names and previous names - var dict = new Dictionary - { - { "hotfix(es)?[/-]", new [] { "hotfix[/-]" }}, - { "features?[/-]", new [] { "feature[/-]", "feature(s)?[/-]" }}, - { "releases?[/-]", new [] { "release[/-]" }}, - { "dev(elop)?(ment)?$", new [] { "develop" }} - }; + MigrateObsoleteBranches(config, "hotfix(es)?[/-]", "hotfix[/-]"); + MigrateObsoleteBranches(config, "features?[/-]", "feature[/-]", "feature(s)?[/-]"); + MigrateObsoleteBranches(config, "releases?[/-]", "release[/-]"); + MigrateObsoleteBranches(config, "dev(elop)?(ment)?$", "develop"); + } - foreach (var mapping in dict) + static void MigrateObsoleteBranches(Config config, string newBranch, params string[] obsoleteBranches) + { + foreach (var obsoleteBranch in obsoleteBranches) { - foreach (var source in mapping.Value) + if (!config.Branches.ContainsKey(obsoleteBranch)) { - if (config.Branches.ContainsKey(source)) - { - // found one, rename - var bc = config.Branches[source]; - config.Branches.Remove(source); - config.Branches[mapping.Key] = bc; // re-add with new name - } + continue; } + + // found one, rename + var bc = config.Branches[obsoleteBranch]; + config.Branches.Remove(obsoleteBranch); + config.Branches[newBranch] = bc; // re-add with new name } } - static BranchConfig GetOrCreateBranchDefaults(Config config, string branch) { if (!config.Branches.ContainsKey(branch)) @@ -139,9 +165,9 @@ static Config ReadConfig(string workingDirectory, IFileSystem fileSystem) return new Config(); } - public static string GetEffectiveConfigAsString(string gitDirectory, IFileSystem fileSystem) + public static string GetEffectiveConfigAsString(string workingDirectory, IFileSystem fileSystem) { - var config = Provide(gitDirectory, fileSystem); + var config = Provide(workingDirectory, fileSystem); var stringBuilder = new StringBuilder(); using (var stream = new StringWriter(stringBuilder)) { @@ -151,25 +177,94 @@ public static string GetEffectiveConfigAsString(string gitDirectory, IFileSystem return stringBuilder.ToString(); } - static string GetConfigFilePath(string workingDirectory, IFileSystem fileSystem) + public static void Verify(GitPreparer gitPreparer, IFileSystem fileSystem) + { + var workingDirectory = gitPreparer.WorkingDirectory; + var projectRootDirectory = gitPreparer.GetProjectRootDirectory(); + + Verify(workingDirectory, projectRootDirectory, fileSystem); + } + + public static void Verify(string workingDirectory, string projectRootDirectory, IFileSystem fileSystem) + { + if (fileSystem.PathsEqual(workingDirectory, projectRootDirectory)) + { + WarnAboutObsoleteConfigFile(workingDirectory, fileSystem); + return; + } + + WarnAboutObsoleteConfigFile(workingDirectory, fileSystem); + WarnAboutObsoleteConfigFile(projectRootDirectory, fileSystem); + + WarnAboutAmbiguousConfigFileSelection(workingDirectory, projectRootDirectory, fileSystem); + } + + private static void WarnAboutAmbiguousConfigFileSelection(string workingDirectory, string projectRootDirectory, IFileSystem fileSystem) { - var ymlPath = Path.Combine(workingDirectory, "GitVersion.yml"); + var workingConfigFile = GetConfigFilePath(workingDirectory, fileSystem); + var projectRootConfigFile = GetConfigFilePath(projectRootDirectory, fileSystem); + + bool hasConfigInWorkingDirectory = fileSystem.Exists(workingConfigFile); + bool hasConfigInProjectRootDirectory = fileSystem.Exists(projectRootConfigFile); + if (hasConfigInProjectRootDirectory && hasConfigInWorkingDirectory) + { + throw new WarningException(string.Format("Ambiguous config file selection from '{0}' and '{1}'", workingConfigFile, projectRootConfigFile)); + } + } + + public static string GetConfigFilePath(string workingDirectory, IFileSystem fileSystem) + { + var ymlPath = Path.Combine(workingDirectory, DefaultConfigFileName); if (fileSystem.Exists(ymlPath)) { return ymlPath; } - var deprecatedPath = Path.Combine(workingDirectory, "GitVersionConfig.yaml"); + var deprecatedPath = Path.Combine(workingDirectory, ObsoleteConfigFileName); if (fileSystem.Exists(deprecatedPath)) { - Logger.WriteWarning("'GitVersionConfig.yaml' is deprecated, use 'GitVersion.yml' instead."); - return deprecatedPath; } return ymlPath; } + public static bool HasConfigFileAt(string workingDirectory, IFileSystem fileSystem) + { + var defaultConfigFilePath = Path.Combine(workingDirectory, DefaultConfigFileName); + if (fileSystem.Exists(defaultConfigFilePath)) + { + return true; + } + + var deprecatedConfigFilePath = Path.Combine(workingDirectory, ObsoleteConfigFileName); + if (fileSystem.Exists(deprecatedConfigFilePath)) + { + return true; + } + + return false; + } + + static bool WarnAboutObsoleteConfigFile(string workingDirectory, IFileSystem fileSystem) + { + var deprecatedConfigFilePath = Path.Combine(workingDirectory, ObsoleteConfigFileName); + if (!fileSystem.Exists(deprecatedConfigFilePath)) + { + return false; + } + + var defaultConfigFilePath = Path.Combine(workingDirectory, DefaultConfigFileName); + if (fileSystem.Exists(defaultConfigFilePath)) + { + Logger.WriteWarning(string.Format("Ambiguous config files at '{0}': '{1}' (deprecated) and '{2}'. Will be used '{2}'", workingDirectory, ObsoleteConfigFileName, DefaultConfigFileName)); + return true; + } + + Logger.WriteWarning(string.Format("'{0}' is deprecated, use '{1}' instead.", deprecatedConfigFilePath, DefaultConfigFileName)); + return true; + } + public static void Init(string workingDirectory, IFileSystem fileSystem, IConsole console) { var configFilePath = GetConfigFilePath(workingDirectory, fileSystem); @@ -186,4 +281,4 @@ public static void Init(string workingDirectory, IFileSystem fileSystem, IConsol } } } -} \ No newline at end of file +} diff --git a/src/GitVersionCore/ExecuteCore.cs b/src/GitVersionCore/ExecuteCore.cs index 3a009a28cb..75ceacf136 100644 --- a/src/GitVersionCore/ExecuteCore.cs +++ b/src/GitVersionCore/ExecuteCore.cs @@ -1,12 +1,10 @@ namespace GitVersion { + using GitVersion.Helpers; + using LibGit2Sharp; using System; using System.ComponentModel; - using System.IO; using System.Linq; - using GitVersion.Helpers; - - using LibGit2Sharp; public class ExecuteCore { @@ -16,7 +14,7 @@ public class ExecuteCore public ExecuteCore(IFileSystem fileSystem) { if (fileSystem == null) throw new ArgumentNullException("fileSystem"); - + this.fileSystem = fileSystem; gitVersionCache = new GitVersionCache(fileSystem); } @@ -51,25 +49,24 @@ public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicReposi // TODO Link to wiki article throw new Exception(string.Format("Failed to prepare or find the .git directory in path '{0}'.", workingDirectory)); } - - using (var repo = GetRepository(dotGitDirectory)) + + var cacheKey = GitVersionCacheKeyFactory.Create(fileSystem, gitPreparer, overrideConfig); + var versionVariables = gitVersionCache.LoadVersionVariablesFromDiskCache(gitPreparer, cacheKey); + if (versionVariables == null) { - var versionVariables = gitVersionCache.LoadVersionVariablesFromDiskCache(repo, dotGitDirectory); - if (versionVariables == null) + versionVariables = ExecuteInternal(targetBranch, commitId, gitPreparer, buildServer, overrideConfig); + + try { - versionVariables = ExecuteInternal(targetBranch, commitId, repo, gitPreparer, projectRoot, buildServer, overrideConfig: overrideConfig); - try - { - gitVersionCache.WriteVariablesToDiskCache(repo, dotGitDirectory, versionVariables); - } - catch (AggregateException e) - { - Logger.WriteWarning(string.Format("One or more exceptions during cache write:{0}{1}", Environment.NewLine, e)); - } + gitVersionCache.WriteVariablesToDiskCache(gitPreparer, cacheKey, versionVariables); + } + catch (AggregateException e) + { + Logger.WriteWarning(string.Format("One or more exceptions during cache write:{0}{1}", Environment.NewLine, e)); } - - return versionVariables; } + + return versionVariables; } public bool TryGetVersion(string directory, out VersionVariables versionVariables, bool noFetch, Authentication authentication) @@ -100,15 +97,18 @@ static string ResolveCurrentBranch(IBuildServer buildServer, string targetBranch return currentBranch; } - VersionVariables ExecuteInternal(string targetBranch, string commitId, IRepository repo, GitPreparer gitPreparer, string projectRoot, IBuildServer buildServer, Config overrideConfig = null) + VersionVariables ExecuteInternal(string targetBranch, string commitId, GitPreparer gitPreparer, IBuildServer buildServer, Config overrideConfig = null) { var versionFinder = new GitVersionFinder(); - var configuration = ConfigurationProvider.Provide(projectRoot, fileSystem, overrideConfig: overrideConfig); + var configuration = ConfigurationProvider.Provide(gitPreparer, fileSystem, overrideConfig: overrideConfig); - var gitVersionContext = new GitVersionContext(repo, configuration, commitId : commitId); - var semanticVersion = versionFinder.FindVersion(gitVersionContext); + return gitPreparer.WithRepository(repo => + { + var gitVersionContext = new GitVersionContext(repo, configuration, commitId: commitId); + var semanticVersion = versionFinder.FindVersion(gitVersionContext); - return VariableProvider.GetVariablesFor(semanticVersion, gitVersionContext.Configuration, gitVersionContext.IsCurrentCommitTagged); + return VariableProvider.GetVariablesFor(semanticVersion, gitVersionContext.Configuration, gitVersionContext.IsCurrentCommitTagged); + }); } IRepository GetRepository(string gitDirectory) diff --git a/src/GitVersionCore/GitPreparer.cs b/src/GitVersionCore/GitPreparer.cs index e130e8ccd6..4bda46e1a9 100644 --- a/src/GitVersionCore/GitPreparer.cs +++ b/src/GitVersionCore/GitPreparer.cs @@ -14,6 +14,7 @@ public class GitPreparer bool noFetch; string targetPath; + public GitPreparer(string targetPath) : this(null, null, null, false, targetPath) { } public GitPreparer(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, bool noFetch, string targetPath) { this.targetUrl = targetUrl; @@ -29,6 +30,11 @@ public GitPreparer(string targetUrl, string dynamicRepositoryLocation, Authentic this.targetPath = targetPath.TrimEnd('/', '\\'); } + public string WorkingDirectory + { + get { return targetPath; } + } + public bool IsDynamicGitRepository { get { return !string.IsNullOrWhiteSpace(DynamicGitRepositoryPath); } @@ -52,6 +58,14 @@ public void Initialise(bool normaliseGitDirectory, string currentBranch) DynamicGitRepositoryPath = CreateDynamicRepository(tempRepositoryPath, authentication, targetUrl, currentBranch, noFetch); } + public TResult WithRepository(Func action) + { + using (IRepository repo = new Repository(GetDotGitDirectory())) + { + return action(repo); + } + } + static string CalculateTemporaryRepositoryPath(string targetUrl, string dynamicRepositoryLocation) { var userTemp = dynamicRepositoryLocation ?? Path.GetTempPath(); diff --git a/src/GitVersionCore/GitVersionCache.cs b/src/GitVersionCore/GitVersionCache.cs index 890b432ac9..99307c2ab6 100644 --- a/src/GitVersionCore/GitVersionCache.cs +++ b/src/GitVersionCore/GitVersionCache.cs @@ -1,13 +1,10 @@ namespace GitVersion { + using GitVersion.Helpers; using System; using System.Collections.Generic; using System.IO; using System.Linq; - using System.Security.Cryptography; - using System.Text; - using GitVersion.Helpers; - using LibGit2Sharp; using YamlDotNet.Serialization; public class GitVersionCache @@ -19,9 +16,11 @@ public GitVersionCache(IFileSystem fileSystem) this.fileSystem = fileSystem; } - public void WriteVariablesToDiskCache(IRepository repo, string gitDir, VersionVariables variablesFromCache) + public void WriteVariablesToDiskCache(GitPreparer gitPreparer, GitVersionCacheKey cacheKey, VersionVariables variablesFromCache) { - var cacheFileName = GetCacheFileName(GetKey(repo, gitDir), GetCacheDir(gitDir)); + var cacheDir = PrepareCacheDirectory(gitPreparer); + var cacheFileName = GetCacheFileName(cacheKey, cacheDir); + variablesFromCache.FileName = cacheFileName; Dictionary dictionary; @@ -49,78 +48,65 @@ public void WriteVariablesToDiskCache(IRepository repo, string gitDir, VersionVa retryOperation.Execute(); } - public VersionVariables LoadVersionVariablesFromDiskCache(IRepository repo, string gitDir) + public static string GetCacheDirectory(GitPreparer gitPreparer) + { + var gitDir = gitPreparer.GetDotGitDirectory(); + var cacheDir = Path.Combine(gitDir, "gitversion_cache"); + return cacheDir; + } + + private string PrepareCacheDirectory(GitPreparer gitPreparer) + { + var cacheDir = GetCacheDirectory(gitPreparer); + + // If the cacheDir already exists, CreateDirectory just won't do anything (it won't fail). @asbjornu + fileSystem.CreateDirectory(cacheDir); + + return cacheDir; + } + + public VersionVariables LoadVersionVariablesFromDiskCache(GitPreparer gitPreparer, GitVersionCacheKey key) { using (Logger.IndentLog("Loading version variables from disk cache")) { - // If the cacheDir already exists, CreateDirectory just won't do anything (it won't fail). @asbjornu + var cacheDir = PrepareCacheDirectory(gitPreparer); + + var cacheFileName = GetCacheFileName(key, cacheDir); + if (!fileSystem.Exists(cacheFileName)) + { + Logger.WriteInfo("Cache file " + cacheFileName + " not found."); + return null; + } - var cacheDir = GetCacheDir(gitDir); - fileSystem.CreateDirectory(cacheDir); - var cacheFileName = GetCacheFileName(GetKey(repo, gitDir), cacheDir); - VersionVariables vv = null; - if (fileSystem.Exists(cacheFileName)) + using (Logger.IndentLog("Deserializing version variables from cache file " + cacheFileName)) { - using (Logger.IndentLog("Deserializing version variables from cache file " + cacheFileName)) + try + { + var loadedVariables = VersionVariables.FromFile(cacheFileName, fileSystem); + return loadedVariables; + } + catch (Exception ex) { + Logger.WriteWarning("Unable to read cache file " + cacheFileName + ", deleting it."); + Logger.WriteInfo(ex.ToString()); try { - vv = VersionVariables.FromFile(cacheFileName, fileSystem); + fileSystem.Delete(cacheFileName); } - catch (Exception ex) + catch (Exception deleteEx) { - Logger.WriteWarning("Unable to read cache file " + cacheFileName + ", deleting it."); - Logger.WriteInfo(ex.ToString()); - try - { - fileSystem.Delete(cacheFileName); - } - catch (Exception deleteEx) - { - Logger.WriteWarning(string.Format("Unable to delete corrupted version cache file {0}. Got {1} exception.", cacheFileName, deleteEx.GetType().FullName)); - } + Logger.WriteWarning(string.Format("Unable to delete corrupted version cache file {0}. Got {1} exception.", cacheFileName, deleteEx.GetType().FullName)); } + + return null; } } - else - { - Logger.WriteInfo("Cache file " + cacheFileName + " not found."); - } - - return vv; } } - string GetKey(IRepository repo, string gitDir) - { - // Maybe using timestamp in .git/refs directory is enough? - var ticks = fileSystem.GetLastDirectoryWrite(Path.Combine(gitDir, "refs")); - var configPath = Path.Combine(repo.GetRepositoryDirectory(), "GitVersionConfig.yaml"); - var configText = fileSystem.Exists(configPath) ? fileSystem.ReadAllText(configPath) : null; - var configHash = configText != null ? GetHash(configText) : null; - return string.Join(":", gitDir, repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks, configHash); - } - - static string GetCacheFileName(string key, string cacheDir) + static string GetCacheFileName(GitVersionCacheKey key, string cacheDir) { - var cacheKey = GetHash(key); - return string.Concat(Path.Combine(cacheDir, cacheKey), ".yml"); - } - - static string GetCacheDir(string gitDir) - { - return Path.Combine(gitDir, "gitversion_cache"); - } - - static string GetHash(string textToHash) - { - using (var sha1 = SHA1.Create()) - { - var bytes = Encoding.UTF8.GetBytes(textToHash); - var hashedBytes = sha1.ComputeHash(bytes); - var hashedString = BitConverter.ToString(hashedBytes); - return hashedString.Replace("-", ""); - } + return Path.Combine(cacheDir, string.Concat(key.Value, ".yml")); } } -} \ No newline at end of file +} diff --git a/src/GitVersionCore/GitVersionCacheKey.cs b/src/GitVersionCore/GitVersionCacheKey.cs new file mode 100644 index 0000000000..00239ff271 --- /dev/null +++ b/src/GitVersionCore/GitVersionCacheKey.cs @@ -0,0 +1,19 @@ +namespace GitVersion +{ + using System; + + public class GitVersionCacheKey + { + public GitVersionCacheKey(string value) + { + if (string.IsNullOrEmpty(value)) + { + throw new ArgumentNullException("value"); + } + + Value = value; + } + + public string Value { get; private set; } + } +} \ No newline at end of file diff --git a/src/GitVersionCore/GitVersionCacheKeyFactory.cs b/src/GitVersionCore/GitVersionCacheKeyFactory.cs new file mode 100644 index 0000000000..5ab9de84a6 --- /dev/null +++ b/src/GitVersionCore/GitVersionCacheKeyFactory.cs @@ -0,0 +1,94 @@ +namespace GitVersion +{ + using GitVersion.Helpers; + using System; + using System.IO; + using System.Security.Cryptography; + using System.Text; + + public class GitVersionCacheKeyFactory + { + public static GitVersionCacheKey Create(IFileSystem fileSystem, GitPreparer gitPreparer, Config overrideConfig) + { + var gitSystemHash = GetGitSystemHash(gitPreparer, fileSystem); + var configFileHash = GetConfigFileHash(fileSystem, gitPreparer); + var repositorySnapshotHash = GetRepositorySnapshotHash(gitPreparer); + var overrideConfigHash = GetOverrideConfigHash(overrideConfig); + + var compositeHash = GetHash(gitSystemHash, configFileHash, repositorySnapshotHash, overrideConfigHash); + return new GitVersionCacheKey(compositeHash); + } + + private static string GetGitSystemHash(GitPreparer gitPreparer, IFileSystem fileSystem) + { + var dotGitDirectory = gitPreparer.GetDotGitDirectory(); + + // Maybe using timestamp in .git/refs directory is enough? + var lastGitRefsChangedTicks = fileSystem.GetLastDirectoryWrite(Path.Combine(dotGitDirectory, "refs")); + + return GetHash(dotGitDirectory, lastGitRefsChangedTicks.ToString()); + } + + private static string GetRepositorySnapshotHash(GitPreparer gitPreparer) + { + var repositorySnapshot = gitPreparer.WithRepository(repo => string.Join(":", repo.Head.CanonicalName, repo.Head.Tip.Sha)); + return GetHash(repositorySnapshot); + } + + private static string GetOverrideConfigHash(Config overrideConfig) + { + if (overrideConfig == null) + { + return string.Empty; + } + + // Doesn't depend on command line representation and + // includes possible changes in default values of Config per se. + var stringBuilder = new StringBuilder(); + using (var stream = new StringWriter(stringBuilder)) + { + ConfigSerialiser.Write(overrideConfig, stream); + stream.Flush(); + } + var configContent = stringBuilder.ToString(); + + return GetHash(configContent); + } + + private static string GetConfigFileHash(IFileSystem fileSystem, GitPreparer gitPreparer) + { + // will return the same hash even when config file will be moved + // from workingDirectory to rootProjectDirectory. It's OK. Config essentially is the same. + var configFilePath = ConfigurationProvider.SelectConfigFilePath(gitPreparer, fileSystem); + if (!fileSystem.Exists(configFilePath)) + { + return string.Empty; + } + + var configFileContent = fileSystem.ReadAllText(configFilePath); + return GetHash(configFileContent); + } + + static string GetHash(params string[] textsToHash) + { + var textToHash = string.Join(":", textsToHash); + return GetHash(textToHash); + } + + static string GetHash(string textToHash) + { + if (string.IsNullOrEmpty(textToHash)) + { + return string.Empty; + } + + using (var sha1 = SHA1.Create()) + { + var bytes = Encoding.UTF8.GetBytes(textToHash); + var hashedBytes = sha1.ComputeHash(bytes); + var hashedString = BitConverter.ToString(hashedBytes); + return hashedString.Replace("-", ""); + } + } + } +} diff --git a/src/GitVersionCore/GitVersionContext.cs b/src/GitVersionCore/GitVersionContext.cs index 1ede21235a..d9c7533c6a 100644 --- a/src/GitVersionCore/GitVersionContext.cs +++ b/src/GitVersionCore/GitVersionContext.cs @@ -1,8 +1,8 @@ namespace GitVersion { + using LibGit2Sharp; using System; using System.Linq; - using LibGit2Sharp; /// /// Contextual information about where GitVersion is being run @@ -111,7 +111,6 @@ void CalculateEffectiveConfiguration() var commitMessageVersionBump = currentBranchConfig.Value.CommitMessageIncrementing ?? configuration.CommitMessageIncrementing.Value; - var versionFilter = Configuration = new EffectiveConfiguration( assemblyVersioningScheme, assemblyInformationalFormat, versioningMode, gitTagPrefix, tag, nextVersion, incrementStrategy, currentBranchConfig.Key, diff --git a/src/GitVersionCore/GitVersionCore.csproj b/src/GitVersionCore/GitVersionCore.csproj index bb4f327897..42b7adbf28 100644 --- a/src/GitVersionCore/GitVersionCore.csproj +++ b/src/GitVersionCore/GitVersionCore.csproj @@ -120,6 +120,8 @@ + + diff --git a/src/GitVersionCore/Helpers/FileSystem.cs b/src/GitVersionCore/Helpers/FileSystem.cs index 93b9cbbba6..9bc62b5cdf 100644 --- a/src/GitVersionCore/Helpers/FileSystem.cs +++ b/src/GitVersionCore/Helpers/FileSystem.cs @@ -1,11 +1,14 @@ namespace GitVersion.Helpers { + using System; using System.Collections.Generic; using System.IO; using System.Linq; public class FileSystem : IFileSystem { + private static readonly bool runningOnMono = Type.GetType("Mono.Runtime") != null; + public void Copy(string @from, string to, bool overwrite) { File.Copy(from, to, overwrite); @@ -70,5 +73,17 @@ public long GetLastDirectoryWrite(string path) .Max() .Ticks; } + + public bool PathsEqual(string path, string otherPath) + { + var comparison = runningOnMono + ? StringComparison.InvariantCulture + : StringComparison.InvariantCultureIgnoreCase; + + return string.Equals( + Path.GetFullPath(path).TrimEnd('\\').TrimEnd('/'), + Path.GetFullPath(otherPath).TrimEnd('\\').TrimEnd('/'), + comparison); + } } } \ No newline at end of file diff --git a/src/GitVersionCore/Helpers/IFileSystem.cs b/src/GitVersionCore/Helpers/IFileSystem.cs index ea4e7863b4..edd1dc78ce 100644 --- a/src/GitVersionCore/Helpers/IFileSystem.cs +++ b/src/GitVersionCore/Helpers/IFileSystem.cs @@ -17,5 +17,7 @@ public interface IFileSystem void CreateDirectory(string path); bool DirectoryExists(string path); long GetLastDirectoryWrite(string path); + + bool PathsEqual(string path, string otherPath); } } \ No newline at end of file diff --git a/src/GitVersionExe.Tests/ArgumentParserTests.cs b/src/GitVersionExe.Tests/ArgumentParserTests.cs index bc0d23eada..e84714450d 100644 --- a/src/GitVersionExe.Tests/ArgumentParserTests.cs +++ b/src/GitVersionExe.Tests/ArgumentParserTests.cs @@ -1,9 +1,9 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; using GitVersion; using NUnit.Framework; using Shouldly; +using System; +using System.Collections.Generic; +using System.ComponentModel; [TestFixture] public class ArgumentParserTests @@ -199,7 +199,7 @@ public void update_assembly_info_false(string command) public void create_mulitple_assembly_info_protected(string command) { var exception = Assert.Throws(() => ArgumentParser.ParseArguments(command)); - exception.Message.ShouldBe("Can't specify multiple assembly info files when using -ensureassemblyinfo switch, either use a single assembly info file or do not specify -ensureassemblyinfo and create assembly info files manually"); + exception.Message.ShouldBe("Can't specify multiple assembly info files when using /ensureassemblyinfo switch, either use a single assembly info file or do not specify /ensureassemblyinfo and create assembly info files manually"); } [Test] @@ -220,6 +220,37 @@ public void update_assembly_info_with_multiple_filenames() arguments.UpdateAssemblyInfoFileName.ShouldContain("VersionAssemblyInfo.cs"); } + [Test] + public void overrideconfig_with_no_options() + { + var arguments = ArgumentParser.ParseArguments("/overrideconfig"); + arguments.HasOverrideConfig.ShouldBe(false); + arguments.OverrideConfig.ShouldNotBeNull(); + } + + [Test] + public void overrideconfig_with_single_tagprefix_option() + { + var arguments = ArgumentParser.ParseArguments("/overrideconfig tag-prefix=sample"); + arguments.HasOverrideConfig.ShouldBe(true); + arguments.OverrideConfig.TagPrefix.ShouldBe("sample"); + } + + [TestCase("tag-prefix=sample;tag-prefix=other")] + [TestCase("tag-prefix=sample;param2=other")] + public void overrideconfig_with_several_options(string options) + { + var exception = Assert.Throws(() => ArgumentParser.ParseArguments(string.Format("/overrideconfig {0}", options))); + exception.Message.ShouldContain("Can't specify multiple /overrideconfig options"); + } + + [TestCase("tag-prefix=sample=asdf")] + public void overrideconfig_with_invalid_option(string options) + { + var exception = Assert.Throws(() => ArgumentParser.ParseArguments(string.Format("/overrideconfig {0}", options))); + exception.Message.ShouldContain("Could not parse /overrideconfig option"); + } + [Test] public void update_assembly_info_with_relative_filename() { @@ -248,7 +279,7 @@ public void ensure_assembly_info_false() var arguments = ArgumentParser.ParseArguments("-ensureAssemblyInfo false"); arguments.EnsureAssemblyInfo.ShouldBe(false); } - + [Test] public void dynamicRepoLocation() { diff --git a/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs b/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs index ce25086ece..a425e5edb0 100644 --- a/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs +++ b/src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.IO; using System.Text; using GitTools; diff --git a/src/GitVersionExe/ArgumentParser.cs b/src/GitVersionExe/ArgumentParser.cs index 2f00922a4a..133f03009d 100644 --- a/src/GitVersionExe/ArgumentParser.cs +++ b/src/GitVersionExe/ArgumentParser.cs @@ -263,25 +263,43 @@ public static Arguments ParseArguments(List commandLineArguments) if (arguments.UpdateAssemblyInfoFileName.Count > 1 && arguments.EnsureAssemblyInfo) { - throw new WarningException("Can't specify multiple assembly info files when using -ensureassemblyinfo switch, either use a single assembly info file or do not specify -ensureassemblyinfo and create assembly info files manually"); + throw new WarningException("Can't specify multiple assembly info files when using /ensureassemblyinfo switch, either use a single assembly info file or do not specify /ensureassemblyinfo and create assembly info files manually"); } continue; } if (name.IsSwitch("overrideconfig")) { - foreach (var item in value.Split(';')) + var keyValueOptions = (value ?? "").Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); + if (keyValueOptions.Length == 0) + { + continue; + } + + arguments.HasOverrideConfig = true; + + if (keyValueOptions.Length > 1) { - var configOverride = item.Split('='); + throw new WarningException("Can't specify multiple /overrideconfig options: currently supported only 'tag-prefix' option"); + } + + // key=value + foreach (var keyValueOption in keyValueOptions) + { + var keyAndValue = keyValueOption.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries); + if (keyAndValue.Length != 2) + { + throw new WarningException(string.Format("Could not parse /overrideconfig option: {0}. Ensure it is in format 'key=value'", keyValueOption)); + } - switch (configOverride[0]) + var optionKey = keyAndValue[0].ToLowerInvariant(); + switch (optionKey) { case "tag-prefix": - if (1 < configOverride.Length) - { - arguments.OverrideConfig.TagPrefix = configOverride[1]; - } + arguments.OverrideConfig.TagPrefix = keyAndValue[1]; break; + default: + throw new WarningException(string.Format("Could not parse /overrideconfig option: {0}. Currently supported only 'tag-prefix' option", optionKey)); } } diff --git a/src/GitVersionExe/Arguments.cs b/src/GitVersionExe/Arguments.cs index 605f7ab413..97ba34ece9 100644 --- a/src/GitVersionExe/Arguments.cs +++ b/src/GitVersionExe/Arguments.cs @@ -15,6 +15,7 @@ public Arguments() public Authentication Authentication; public Config OverrideConfig; + public bool HasOverrideConfig { get; set; } public string TargetPath; @@ -30,7 +31,7 @@ public Arguments() public string ShowVariable; public OutputType Output; - + public string Proj; public string ProjArgs; public string Exec; diff --git a/src/GitVersionExe/HelpWriter.cs b/src/GitVersionExe/HelpWriter.cs index b1041f04ee..53a0d3ef1b 100644 --- a/src/GitVersionExe/HelpWriter.cs +++ b/src/GitVersionExe/HelpWriter.cs @@ -24,8 +24,8 @@ path The directory containing .git. If not defined current directory /showvariable Used in conjuntion with /output json, will output just a particular variable. eg /output json /showvariable SemVer - will output `1.2.3+beta.4` /l Path to logfile. - /showconfig Outputs the effective GitVersion config (defaults + custom from GitVersion.yaml) in yaml format - /overrideconfig Overrides GitVersion config values inline (semicolon-separated key value pairs e.g. /overrideconfig:tag-prefix=Foo) + /showconfig Outputs the effective GitVersion config (defaults + custom from GitVersion.yml) in yaml format + /overrideconfig Overrides GitVersion config values inline (semicolon-separated key value pairs e.g. /overrideconfig tag-prefix=Foo) Currently supported config overrides: tag-prefix # AssemblyInfo updating diff --git a/src/GitVersionExe/Program.cs b/src/GitVersionExe/Program.cs index f9268cf655..e0bad33be3 100644 --- a/src/GitVersionExe/Program.cs +++ b/src/GitVersionExe/Program.cs @@ -1,5 +1,6 @@ namespace GitVersion { + using GitVersion.Helpers; using System; using System.Collections.Generic; using System.ComponentModel; @@ -7,7 +8,6 @@ namespace GitVersion using System.IO; using System.Linq; using System.Text; - using GitVersion.Helpers; class Program { @@ -64,7 +64,6 @@ static int VerifyArgumentsAndRun() } ConfigureLogging(arguments); - if (!Directory.Exists(arguments.TargetPath)) { Logger.WriteWarning(string.Format("The working directory '{0}' does not exist.", arguments.TargetPath)); @@ -73,6 +72,7 @@ static int VerifyArgumentsAndRun() { Logger.WriteInfo("Working directory: " + arguments.TargetPath); } + VerifyConfiguration(arguments, fileSystem); if (arguments.Init) { @@ -124,6 +124,11 @@ static int VerifyArgumentsAndRun() return 0; } + private static void VerifyConfiguration(Arguments arguments, IFileSystem fileSystem) + { + var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.NoFetch, arguments.TargetPath); + ConfigurationProvider.Verify(gitPreparer, fileSystem); + } static void ConfigureLogging(Arguments arguments) { @@ -185,4 +190,4 @@ static List GetArgumentsWithoutExeName() .ToList(); } } -} \ No newline at end of file +} diff --git a/src/GitVersionExe/SpecifiedArgumentRunner.cs b/src/GitVersionExe/SpecifiedArgumentRunner.cs index ce966a56fb..55f3909679 100644 --- a/src/GitVersionExe/SpecifiedArgumentRunner.cs +++ b/src/GitVersionExe/SpecifiedArgumentRunner.cs @@ -1,16 +1,16 @@ namespace GitVersion { + using GitTools; + using GitVersion.Helpers; using System; using System.Collections.Generic; using System.Linq; - using GitTools; - using GitVersion.Helpers; using WarningException = System.ComponentModel.WarningException; class SpecifiedArgumentRunner { private static readonly bool runningOnMono = Type.GetType("Mono.Runtime") != null; - public static readonly string BuildTool = runningOnMono? "xbuild" : @"c:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe"; + public static readonly string BuildTool = runningOnMono ? "xbuild" : @"c:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe"; public static void Run(Arguments arguments, IFileSystem fileSystem) { @@ -23,10 +23,10 @@ public static void Run(Arguments arguments, IFileSystem fileSystem) var dynamicRepositoryLocation = arguments.DynamicRepositoryLocation; var targetBranch = arguments.TargetBranch; var commitId = arguments.CommitId; - var overrideConfig = arguments.OverrideConfig; + var overrideConfig = arguments.HasOverrideConfig ? arguments.OverrideConfig : null; var executeCore = new ExecuteCore(fileSystem); - var variables = executeCore.ExecuteGitVersion(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId, overrideConfig: overrideConfig); + var variables = executeCore.ExecuteGitVersion(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId, overrideConfig); if (arguments.Output == OutputType.BuildServer) {