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
31 changes: 31 additions & 0 deletions src/GitVersionCore.Tests/NamedConfigFileLocatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,37 @@ public void ThrowsExceptionOnAmbiguousConfigFileLocation()
exception.Message.ShouldBe(expectedMessage);
}

[Test]
public void DoNotThrowWhenWorkingAndRepoPathsAreSame()
{
workingPath = DefaultRepoPath;
SetupConfigFileContent(string.Empty, path: workingPath);

Should.NotThrow(() => { configFileLocator.Verify(workingPath, repoPath); });
}

[Test]
[Platform(Exclude = "Linux,Unix")]
public void DoNotThrowWhenWorkingAndRepoPathsAreSame_WithDifferentCasing()
{
workingPath = DefaultRepoPath.ToLower();
SetupConfigFileContent(string.Empty, path: workingPath);

Should.NotThrow(() => { configFileLocator.Verify(workingPath, repoPath); });
}

[Test]
public void DoNotThrowWhenConfigFileIsInSubDirectoryOfRepoPath()
{
workingPath = DefaultRepoPath;

options = Options.Create(new Arguments { ConfigFile = "./src/my-config.yaml" });
configFileLocator = new NamedConfigFileLocator(fileSystem, log, options);
SetupConfigFileContent(string.Empty, path: workingPath);

Should.NotThrow(() => { configFileLocator.Verify(workingPath, repoPath); });
}

[Test]
public void NoWarnOnCustomYmlFile()
{
Expand Down
46 changes: 29 additions & 17 deletions src/GitVersionCore.Tests/TestFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,49 @@ namespace GitVersionCore.Tests
{
public class TestFileSystem : IFileSystem
{
private readonly Dictionary<string, byte[]> fileSystem = new Dictionary<string, byte[]>();
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);

public void Copy(string @from, string to, bool overwrite)
{
if (fileSystem.ContainsKey(to))
var fromPath = Path.GetFullPath(@from);
var toPath = Path.GetFullPath(to);
if (fileSystem.ContainsKey(toPath))
{
if (overwrite)
fileSystem.Remove(to);
fileSystem.Remove(toPath);
else
throw new IOException("File already exists");
}

if (!fileSystem.TryGetValue(from, out var source))
throw new FileNotFoundException($"The source file '{@from}' was not found", from);
if (!fileSystem.TryGetValue(fromPath, out var source))
throw new FileNotFoundException($"The source file '{fromPath}' was not found", from);

fileSystem.Add(to, source);
fileSystem.Add(toPath, source);
}

public void Move(string @from, string to)
{
var fromPath = Path.GetFullPath(@from);
Copy(from, to, false);
fileSystem.Remove(from);
fileSystem.Remove(fromPath);
}

public bool Exists(string file)
{
return fileSystem.ContainsKey(file);
var path = Path.GetFullPath(file);
return fileSystem.ContainsKey(path);
}

public void Delete(string path)
{
fileSystem.Remove(path);
var fullPath = Path.GetFullPath(path);
fileSystem.Remove(fullPath);
}

public string ReadAllText(string path)
public string ReadAllText(string file)
{
var path = Path.GetFullPath(file);
if (!fileSystem.TryGetValue(path, out var content))
throw new FileNotFoundException($"The file '{path}' was not found", path);

Expand All @@ -54,15 +61,17 @@ public string ReadAllText(string path)

public void WriteAllText(string file, string fileContents)
{
var encoding = fileSystem.ContainsKey(file)
? EncodingHelper.DetectEncoding(fileSystem[file]) ?? Encoding.UTF8
var path = Path.GetFullPath(file);
var encoding = fileSystem.ContainsKey(path)
? EncodingHelper.DetectEncoding(fileSystem[path]) ?? Encoding.UTF8
: Encoding.UTF8;
WriteAllText(file, fileContents, encoding);
WriteAllText(path, fileContents, encoding);
}

public void WriteAllText(string file, string fileContents, Encoding encoding)
{
fileSystem[file] = encoding.GetBytes(fileContents);
var path = Path.GetFullPath(file);
fileSystem[path] = encoding.GetBytes(fileContents);
}

public IEnumerable<string> DirectoryGetFiles(string directory, string searchPattern, SearchOption searchOption)
Expand All @@ -75,8 +84,9 @@ public Stream OpenWrite(string path)
return new TestStream(path, this);
}

public Stream OpenRead(string path)
public Stream OpenRead(string file)
{
var path = Path.GetFullPath(file);
if (fileSystem.ContainsKey(path))
{
var content = fileSystem[path];
Expand All @@ -86,8 +96,9 @@ public Stream OpenRead(string path)
throw new FileNotFoundException("File not found.", path);
}

public void CreateDirectory(string path)
public void CreateDirectory(string directory)
{
var path = Path.GetFullPath(directory);
if (fileSystem.ContainsKey(path))
{
fileSystem[path] = new byte[0];
Expand All @@ -98,8 +109,9 @@ public void CreateDirectory(string path)
}
}

public bool DirectoryExists(string path)
public bool DirectoryExists(string directory)
{
var path = Path.GetFullPath(directory);
return fileSystem.ContainsKey(path);
}

Expand Down
4 changes: 4 additions & 0 deletions src/GitVersionCore/Configuration/NamedConfigFileLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ private void WarnAboutAmbiguousConfigFileSelection(string workingDirectory, stri
var workingConfigFile = GetConfigFilePath(workingDirectory);
var projectRootConfigFile = GetConfigFilePath(projectRootDirectory);

var fileSystemCasingComparer = System.Environment.OSVersion.Platform == PlatformID.Unix ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
if (Path.GetFullPath(workingConfigFile).Equals(Path.GetFullPath(projectRootConfigFile), fileSystemCasingComparer))
return;

var hasConfigInWorkingDirectory = FileSystem.Exists(workingConfigFile);
var hasConfigInProjectRootDirectory = FileSystem.Exists(projectRootConfigFile);
if (hasConfigInProjectRootDirectory && hasConfigInWorkingDirectory)
Expand Down