Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions src/GitVersionCore.Tests/ConfigProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,6 @@ public void Setup()
ShouldlyConfiguration.ShouldMatchApprovedDefaults.LocateTestMethodUsingAttribute<TestAttribute>();
}

[Test]
public void CanReadOldDocument()
{
const string text = @"
assemblyVersioningScheme: MajorMinor
develop-branch-tag: alpha
release-branch-tag: rc
branches:
master:
mode: ContinuousDeployment
dev(elop)?(ment)?$:
mode: ContinuousDeployment
tag: dev
release[/-]:
mode: continuousDeployment
tag: rc
";
SetupConfigFileContent(text);
var error = Should.Throw<OldConfigurationException>(() => configProvider.Provide(repoPath));
error.Message.ShouldContainWithoutWhitespace(@"GitVersion configuration file contains old configuration, please fix the following errors:
GitVersion branch configs no longer are keyed by regexes, update:
dev(elop)?(ment)?$ -> develop
release[/-] -> release
assemblyVersioningScheme has been replaced by assembly-versioning-scheme
develop-branch-tag has been replaced by branch specific configuration.See https://gitversion.net/docs/configuration/#branch-configuration
release-branch-tag has been replaced by branch specific configuration.See https://gitversion.net/docs/configuration/#branch-configuration");
}

[Test]
public void OverwritesDefaultsWithProvidedConfig()
{
Expand Down
83 changes: 4 additions & 79 deletions src/GitVersionCore.Tests/DefaultConfigFileLocatorTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System;
using System.IO;
using NUnit.Framework;
using Shouldly;
using GitVersion.Configuration;
using GitVersion.Exceptions;
using GitVersion;
using GitVersion.Logging;
using GitVersionCore.Tests.Helpers;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
Expand All @@ -22,6 +20,7 @@ public class DefaultConfigFileLocatorTests : TestBase
private string workingPath;
private IFileSystem fileSystem;
private IConfigProvider configurationProvider;
private IConfigFileLocator configFileLocator;

[SetUp]
public void Setup()
Expand All @@ -37,56 +36,20 @@ public void Setup()

fileSystem = sp.GetService<IFileSystem>();
configurationProvider = sp.GetService<IConfigProvider>();
configFileLocator = sp.GetService<IConfigFileLocator>();

ShouldlyConfiguration.ShouldMatchApprovedDefaults.LocateTestMethodUsingAttribute<TestAttribute>();
}

[TestCase(DefaultRepoPath)]
[TestCase(DefaultWorkingPath)]
public void WarnOnExistingGitVersionConfigYamlFile(string path)
{
SetupConfigFileContent(string.Empty, DefaultConfigFileLocator.ObsoleteFileName, path);

var output = WithDefaultConfigFileLocator(configFileLocator =>
{
configFileLocator.Verify(workingPath, repoPath);
});

var configFileDeprecatedWarning = $"{DefaultConfigFileLocator.ObsoleteFileName}' is deprecated, use '{DefaultConfigFileLocator.DefaultFileName}' instead";
output.Contains(configFileDeprecatedWarning).ShouldBe(true);
}

[TestCase(DefaultRepoPath)]
[TestCase(DefaultWorkingPath)]
public void WarnOnAmbiguousConfigFilesAtTheSameProjectRootDirectory(string path)
{
SetupConfigFileContent(string.Empty, DefaultConfigFileLocator.ObsoleteFileName, path);
SetupConfigFileContent(string.Empty, DefaultConfigFileLocator.DefaultFileName, path);

var output = WithDefaultConfigFileLocator(configFileLocator =>
{
configFileLocator.Verify(workingPath, repoPath);
});

var configFileDeprecatedWarning = $"Ambiguous config files at '{path}'";
output.Contains(configFileDeprecatedWarning).ShouldBe(true);
}

[TestCase(DefaultConfigFileLocator.DefaultFileName, DefaultConfigFileLocator.DefaultFileName)]
[TestCase(DefaultConfigFileLocator.DefaultFileName, DefaultConfigFileLocator.ObsoleteFileName)]
[TestCase(DefaultConfigFileLocator.ObsoleteFileName, DefaultConfigFileLocator.DefaultFileName)]
[TestCase(DefaultConfigFileLocator.ObsoleteFileName, DefaultConfigFileLocator.ObsoleteFileName)]
public void ThrowsExceptionOnAmbiguousConfigFileLocation(string repoConfigFile, string workingConfigFile)
{
var repositoryConfigFilePath = SetupConfigFileContent(string.Empty, repoConfigFile, repoPath);
var workingDirectoryConfigFilePath = SetupConfigFileContent(string.Empty, workingConfigFile, workingPath);

var exception = Should.Throw<WarningException>(() =>
{
WithDefaultConfigFileLocator(configFileLocator =>
{
configFileLocator.Verify(workingPath, repoPath);
});
configFileLocator.Verify(workingPath, repoPath);
});

var expecedMessage = $"Ambiguous config file selection from '{workingDirectoryConfigFilePath}' and '{repositoryConfigFilePath}'";
Expand All @@ -98,31 +61,7 @@ public void NoWarnOnGitVersionYmlFile()
{
SetupConfigFileContent(string.Empty, DefaultConfigFileLocator.DefaultFileName, repoPath);

var output = WithDefaultConfigFileLocator(configFileLocator =>
{
configurationProvider.Provide(repoPath);
});

output.Length.ShouldBe(0);
}

[Test]
public void WarnOnObsoleteIsDevelopBranchConfigurationSetting()
{
const string text = @"
assembly-versioning-scheme: MajorMinorPatch
branches:
master:
tag: beta
is-develop: true";

var exception = Should.Throw<OldConfigurationException>(() =>
{
LegacyConfigNotifier.Notify(new StringReader(text));
});

const string expectedMessage = "'is-develop' is deprecated, use 'tracks-release-branches' instead.";
exception.Message.ShouldContain(expectedMessage);
Should.NotThrow(() => { configurationProvider.Provide(repoPath); });
}

private string SetupConfigFileContent(string text, string fileName, string path)
Expand All @@ -132,19 +71,5 @@ private string SetupConfigFileContent(string text, string fileName, string path)

return fullPath;
}

private string WithDefaultConfigFileLocator(Action<IConfigFileLocator> action)
{
var stringLogger = string.Empty;
void Action(string info) => stringLogger = info;

var logAppender = new TestLogAppender(Action);
var log = new Log(logAppender);

var configFileLocator = new DefaultConfigFileLocator(fileSystem, log);
action(configFileLocator);

return stringLogger;
}
}
}
2 changes: 1 addition & 1 deletion src/GitVersionCore.Tests/GitVersionExecutorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public void ConfigChangeInvalidatesCache()
versionVariables = gitVersionCalculator.CalculateVersionVariables();
versionVariables.AssemblySemVer.ShouldBe("4.10.3.0");

var configPath = Path.Combine(fixture.RepositoryPath, "GitVersionConfig.yaml");
var configPath = Path.Combine(fixture.RepositoryPath, DefaultConfigFileLocator.DefaultFileName);
fileSystem.WriteAllText(configPath, "next-version: 5.0");

versionVariables = gitVersionCalculator.CalculateVersionVariables();
Expand Down
8 changes: 5 additions & 3 deletions src/GitVersionCore.Tests/Helpers/TestFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ namespace GitVersionCore.Tests.Helpers
{
public class TestFileSystem : IFileSystem
{
private static IEqualityComparer<string> fileSystemCasingComparer = System.Environment.OSVersion.Platform == PlatformID.Unix ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase;
private readonly Dictionary<string, byte[]> fileSystem = new Dictionary<string, byte[]>(fileSystemCasingComparer);
private readonly Dictionary<string, byte[]> fileSystem = new Dictionary<string, byte[]>(StringComparerUtils.OsDependentComparer);

public void Copy(string @from, string to, bool overwrite)
{
Expand Down Expand Up @@ -122,7 +121,10 @@ public long GetLastDirectoryWrite(string path)

public bool PathsEqual(string path, string otherPath)
{
return path == otherPath;
return string.Equals(
Path.GetFullPath(path).TrimEnd('\\').TrimEnd('/'),
Path.GetFullPath(otherPath).TrimEnd('\\').TrimEnd('/'),
StringComparerUtils.OsDependentComparison);
}
}
}
1 change: 0 additions & 1 deletion src/GitVersionCore.Tests/NamedConfigFileLocatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public void DoNotThrowWhenWorkingAndRepoPathsAreSame()
}

[Test]
[Platform(Exclude = "Linux,Unix")]
public void DoNotThrowWhenWorkingAndRepoPathsAreSame_WithDifferentCasing()
{
workingPath = DefaultRepoPath.ToLower();
Expand Down
13 changes: 2 additions & 11 deletions src/GitVersionCore/Configuration/ConfigFileLocator.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
using System;
using System.IO;
using GitVersion.Logging;

namespace GitVersion.Configuration
{
public abstract class ConfigFileLocator : IConfigFileLocator
{
protected readonly IFileSystem FileSystem;
protected readonly ILog Log;

protected ConfigFileLocator(IFileSystem fileSystem, ILog log)
protected ConfigFileLocator(IFileSystem fileSystem)
{
FileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
Log = log ?? throw new ArgumentNullException(nameof(log));
}

public abstract bool HasConfigFileAt(string workingDirectory);
Expand All @@ -26,12 +23,7 @@ public string SelectConfigFilePath(IGitPreparer gitPreparer)
var workingDirectory = gitPreparer.GetWorkingDirectory();
var projectRootDirectory = gitPreparer.GetProjectRootDirectory();

if (HasConfigFileAt(workingDirectory))
{
return GetConfigFilePath(workingDirectory);
}

return GetConfigFilePath(projectRootDirectory);
return GetConfigFilePath(HasConfigFileAt(workingDirectory) ? workingDirectory : projectRootDirectory);
}

public Config ReadConfig(string workingDirectory)
Expand All @@ -41,7 +33,6 @@ public Config ReadConfig(string workingDirectory)
if (FileSystem.Exists(configFilePath))
{
var readAllText = FileSystem.ReadAllText(configFilePath);
LegacyConfigNotifier.Notify(new StringReader(readAllText));
return ConfigSerializer.Read(new StringReader(readAllText));
}

Expand Down
9 changes: 3 additions & 6 deletions src/GitVersionCore/Configuration/ConfigFileLocatorFactory.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
using System;
using GitVersion.Logging;
using Microsoft.Extensions.Options;

namespace GitVersion.Configuration
{
public class ConfigFileLocatorFactory : IConfigFileLocatorFactory
{
private readonly IFileSystem fileSystem;
private readonly ILog log;
private readonly IOptions<Arguments> options;

public ConfigFileLocatorFactory(IFileSystem fileSystem, ILog log, IOptions<Arguments> options)
public ConfigFileLocatorFactory(IFileSystem fileSystem, IOptions<Arguments> options)
{
this.fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
this.log = log ?? throw new ArgumentNullException(nameof(log));
this.options = options ?? throw new ArgumentNullException(nameof(options));
}

public IConfigFileLocator Create()
{
return string.IsNullOrWhiteSpace(options.Value.ConfigFile)
? new DefaultConfigFileLocator(fileSystem, log) as IConfigFileLocator
: new NamedConfigFileLocator(fileSystem, log, options);
? new DefaultConfigFileLocator(fileSystem) as IConfigFileLocator
: new NamedConfigFileLocator(fileSystem, options);
}
}
}
42 changes: 1 addition & 41 deletions src/GitVersionCore/Configuration/DefaultConfigFileLocator.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
using System.IO;
using GitVersion.Exceptions;
using GitVersion.Logging;

namespace GitVersion.Configuration
{
public class DefaultConfigFileLocator : ConfigFileLocator
{
public DefaultConfigFileLocator(IFileSystem fileSystem, ILog log) : base(fileSystem, log)
public DefaultConfigFileLocator(IFileSystem fileSystem) : base(fileSystem)
{

}

public const string DefaultFileName = "GitVersion.yml";

public const string ObsoleteFileName = "GitVersionConfig.yaml";

public override bool HasConfigFileAt(string workingDirectory)
{
var defaultConfigFilePath = Path.Combine(workingDirectory, DefaultFileName);
Expand All @@ -23,12 +19,6 @@ public override bool HasConfigFileAt(string workingDirectory)
return true;
}

var deprecatedConfigFilePath = Path.Combine(workingDirectory, ObsoleteFileName);
if (FileSystem.Exists(deprecatedConfigFilePath))
{
return true;
}

return false;
}

Expand All @@ -40,26 +30,16 @@ public override string GetConfigFilePath(string workingDirectory)
return ymlPath;
}

var deprecatedPath = Path.Combine(workingDirectory, ObsoleteFileName);
if (FileSystem.Exists(deprecatedPath))
{
return deprecatedPath;
}

return ymlPath;
}

public override void Verify(string workingDirectory, string projectRootDirectory)
{
if (FileSystem.PathsEqual(workingDirectory, projectRootDirectory))
{
WarnAboutObsoleteConfigFile(workingDirectory);
return;
}

WarnAboutObsoleteConfigFile(workingDirectory);
WarnAboutObsoleteConfigFile(projectRootDirectory);

WarnAboutAmbiguousConfigFileSelection(workingDirectory, projectRootDirectory);
}

Expand All @@ -75,25 +55,5 @@ private void WarnAboutAmbiguousConfigFileSelection(string workingDirectory, stri
throw new WarningException($"Ambiguous config file selection from '{workingConfigFile}' and '{projectRootConfigFile}'");
}
}

private void WarnAboutObsoleteConfigFile(string workingDirectory)
{
var deprecatedConfigFilePath = Path.Combine(workingDirectory, ObsoleteFileName);
if (!FileSystem.Exists(deprecatedConfigFilePath))
{
return;
}

var defaultConfigFilePath = Path.Combine(workingDirectory, DefaultFileName);
if (FileSystem.Exists(defaultConfigFilePath))
{
Log.Warning(string.Format("Ambiguous config files at '{0}': '{1}' (deprecated) and '{2}'. Will be used '{2}'", workingDirectory, ObsoleteFileName, DefaultFileName));
return;
}

Log.Warning($"'{deprecatedConfigFilePath}' is deprecated, use '{DefaultFileName}' instead.");
}

}

}
2 changes: 1 addition & 1 deletion src/GitVersionCore/Configuration/IConfigFileLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ public interface IConfigFileLocator
{
bool HasConfigFileAt(string workingDirectory);
string GetConfigFilePath(string workingDirectory);
void Verify(IGitPreparer gitPreparer);
void Verify(string workingDirectory, string projectRootDirectory);
string SelectConfigFilePath(IGitPreparer gitPreparer);
Config ReadConfig(string workingDirectory);
void Verify(IGitPreparer gitPreparer);
}
}
16 changes: 0 additions & 16 deletions src/GitVersionCore/Configuration/LegacyBranchConfig.cs

This file was deleted.

Loading