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
1 change: 1 addition & 0 deletions new-cli/GitVersion.Common/GitVersion.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Polly" />
<PackageReference Include="System.IO.Abstractions" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\src\GitVersion.Core\Core\Abstractions\IEnvironment.cs" Link="Infrastructure\%(Filename)%(Extension)" />
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.App.Tests/ArgumentParserOnBuildServerTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using GitVersion.Agents;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Extensions;
using GitVersion.OutputVariables;
using Microsoft.Extensions.DependencyInjection;

Expand All @@ -15,8 +16,7 @@ public void SetUp()
{
var sp = ConfigureServices(services =>
{
services.AddSingleton<IArgumentParser, ArgumentParser>();
services.AddSingleton<IGlobbingResolver, GlobbingResolver>();
services.AddModule(new GitVersionAppModule());
services.AddSingleton<ICurrentBuildAgent, MockBuildAgent>();
});
this.argumentParser = sp.GetRequiredService<IArgumentParser>();
Expand Down
49 changes: 23 additions & 26 deletions src/GitVersion.App.Tests/ArgumentParserTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.IO.Abstractions;
using GitVersion.Configuration;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Extensions;
using GitVersion.Helpers;
using GitVersion.Logging;
using GitVersion.VersionCalculation;
Expand All @@ -18,11 +19,7 @@ public class ArgumentParserTests : TestBase
[SetUp]
public void SetUp()
{
var sp = ConfigureServices(services =>
{
services.AddSingleton<IArgumentParser, ArgumentParser>();
services.AddSingleton<IGlobbingResolver, GlobbingResolver>();
});
var sp = ConfigureServices(services => services.AddModule(new GitVersionAppModule()));
this.environment = sp.GetRequiredService<IEnvironment>();
this.argumentParser = sp.GetRequiredService<IArgumentParser>();
this.fileSystem = sp.GetRequiredService<IFileSystem>();
Expand Down Expand Up @@ -283,91 +280,91 @@ public void UpdateAssemblyInfoWithFilename()
{
using var repo = new EmptyRepositoryFixture();

var assemblyFile = PathHelper.Combine(repo.RepositoryPath, "CommonAssemblyInfo.cs");
var assemblyFile = FileSystemHelper.Path.Combine(repo.RepositoryPath, "CommonAssemblyInfo.cs");
using var file = this.fileSystem.File.Create(assemblyFile);

var arguments = this.argumentParser.ParseArguments($"-targetpath {repo.RepositoryPath} -updateAssemblyInfo CommonAssemblyInfo.cs");
arguments.UpdateAssemblyInfo.ShouldBe(true);
arguments.UpdateAssemblyInfoFileName.Count.ShouldBe(1);
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => FileSystemHelper.Path.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
}

[Test]
public void UpdateAssemblyInfoWithMultipleFilenames()
{
using var repo = new EmptyRepositoryFixture();

var assemblyFile1 = PathHelper.Combine(repo.RepositoryPath, "CommonAssemblyInfo.cs");
var assemblyFile1 = FileSystemHelper.Path.Combine(repo.RepositoryPath, "CommonAssemblyInfo.cs");
using var file = this.fileSystem.File.Create(assemblyFile1);

var assemblyFile2 = PathHelper.Combine(repo.RepositoryPath, "VersionAssemblyInfo.cs");
var assemblyFile2 = FileSystemHelper.Path.Combine(repo.RepositoryPath, "VersionAssemblyInfo.cs");
using var file2 = this.fileSystem.File.Create(assemblyFile2);

var arguments = this.argumentParser.ParseArguments($"-targetpath {repo.RepositoryPath} -updateAssemblyInfo CommonAssemblyInfo.cs VersionAssemblyInfo.cs");
arguments.UpdateAssemblyInfo.ShouldBe(true);
arguments.UpdateAssemblyInfoFileName.Count.ShouldBe(2);
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("VersionAssemblyInfo.cs"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => FileSystemHelper.Path.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => FileSystemHelper.Path.GetFileName(x).Equals("VersionAssemblyInfo.cs"));
}

[Test]
public void UpdateProjectFilesWithMultipleFilenames()
{
using var repo = new EmptyRepositoryFixture();

var assemblyFile1 = PathHelper.Combine(repo.RepositoryPath, "CommonAssemblyInfo.csproj");
var assemblyFile1 = FileSystemHelper.Path.Combine(repo.RepositoryPath, "CommonAssemblyInfo.csproj");
using var file = this.fileSystem.File.Create(assemblyFile1);

var assemblyFile2 = PathHelper.Combine(repo.RepositoryPath, "VersionAssemblyInfo.csproj");
var assemblyFile2 = FileSystemHelper.Path.Combine(repo.RepositoryPath, "VersionAssemblyInfo.csproj");
using var file2 = this.fileSystem.File.Create(assemblyFile2);

var arguments = this.argumentParser.ParseArguments($"-targetpath {repo.RepositoryPath} -updateProjectFiles CommonAssemblyInfo.csproj VersionAssemblyInfo.csproj");
arguments.UpdateProjectFiles.ShouldBe(true);
arguments.UpdateAssemblyInfoFileName.Count.ShouldBe(2);
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("CommonAssemblyInfo.csproj"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("VersionAssemblyInfo.csproj"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => FileSystemHelper.Path.GetFileName(x).Equals("CommonAssemblyInfo.csproj"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => FileSystemHelper.Path.GetFileName(x).Equals("VersionAssemblyInfo.csproj"));
}

[Test]
public void UpdateAssemblyInfoWithMultipleFilenamesMatchingGlobbing()
{
using var repo = new EmptyRepositoryFixture();

var assemblyFile1 = PathHelper.Combine(repo.RepositoryPath, "CommonAssemblyInfo.cs");
var assemblyFile1 = FileSystemHelper.Path.Combine(repo.RepositoryPath, "CommonAssemblyInfo.cs");
using var file = this.fileSystem.File.Create(assemblyFile1);

var assemblyFile2 = PathHelper.Combine(repo.RepositoryPath, "VersionAssemblyInfo.cs");
var assemblyFile2 = FileSystemHelper.Path.Combine(repo.RepositoryPath, "VersionAssemblyInfo.cs");
using var file2 = this.fileSystem.File.Create(assemblyFile2);

var subdir = PathHelper.Combine(repo.RepositoryPath, "subdir");
var subdir = FileSystemHelper.Path.Combine(repo.RepositoryPath, "subdir");

this.fileSystem.Directory.CreateDirectory(subdir);
var assemblyFile3 = PathHelper.Combine(subdir, "LocalAssemblyInfo.cs");
var assemblyFile3 = FileSystemHelper.Path.Combine(subdir, "LocalAssemblyInfo.cs");
using var file3 = this.fileSystem.File.Create(assemblyFile3);

var arguments = this.argumentParser.ParseArguments($"-targetpath {repo.RepositoryPath} -updateAssemblyInfo **/*AssemblyInfo.cs");
arguments.UpdateAssemblyInfo.ShouldBe(true);
arguments.UpdateAssemblyInfoFileName.Count.ShouldBe(3);
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("VersionAssemblyInfo.cs"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("LocalAssemblyInfo.cs"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => FileSystemHelper.Path.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => FileSystemHelper.Path.GetFileName(x).Equals("VersionAssemblyInfo.cs"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => FileSystemHelper.Path.GetFileName(x).Equals("LocalAssemblyInfo.cs"));
}

[Test]
public void UpdateAssemblyInfoWithRelativeFilename()
{
using var repo = new EmptyRepositoryFixture();

var assemblyFile = PathHelper.Combine(repo.RepositoryPath, "CommonAssemblyInfo.cs");
var assemblyFile = FileSystemHelper.Path.Combine(repo.RepositoryPath, "CommonAssemblyInfo.cs");
using var file = this.fileSystem.File.Create(assemblyFile);

var targetPath = PathHelper.Combine(repo.RepositoryPath, "subdir1", "subdir2");
var targetPath = FileSystemHelper.Path.Combine(repo.RepositoryPath, "subdir1", "subdir2");
this.fileSystem.Directory.CreateDirectory(targetPath);

var arguments = this.argumentParser.ParseArguments($"-targetpath {targetPath} -updateAssemblyInfo ..\\..\\CommonAssemblyInfo.cs");
arguments.UpdateAssemblyInfo.ShouldBe(true);
arguments.UpdateAssemblyInfoFileName.Count.ShouldBe(1);
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => FileSystemHelper.Path.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
}

[Test]
Expand Down Expand Up @@ -765,7 +762,7 @@ public void ThrowIfConfigurationFileDoesNotExist(string configFile) =>
[Test]
public void EnsureConfigurationFileIsSet()
{
var configFile = PathHelper.GetTempPath() + Guid.NewGuid() + ".yaml";
var configFile = FileSystemHelper.Path.GetTempPath() + Guid.NewGuid() + ".yaml";
this.fileSystem.File.WriteAllText(configFile, "next-version: 1.0.0");
var arguments = this.argumentParser.ParseArguments($"-config {configFile}");
arguments.ConfigurationFile.ShouldBe(configFile);
Expand Down
7 changes: 4 additions & 3 deletions src/GitVersion.App.Tests/ExecCmdLineArgumentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public void CheckBuildServerVerbosityConsole(string verbosityArg, string expecte
[Test]
public void WorkingDirectoryWithoutGitFolderFailsWithInformativeMessage()
{
var result = GitVersionHelper.ExecuteIn(Path.GetTempPath(), null, false);
var workingDirectory = FileSystemHelper.Path.GetTempPathLegacy();
var result = GitVersionHelper.ExecuteIn(workingDirectory, null, false);

result.ExitCode.ShouldNotBe(0);
result.Output.ShouldNotBeNull();
Expand Down Expand Up @@ -84,7 +85,7 @@ public void WorkingDirectoryWithoutCommitsFailsWithInformativeMessage()
[Test]
public void WorkingDirectoryDoesNotExistFailsWithInformativeMessage()
{
var workingDirectory = PathHelper.Combine(PathHelper.GetCurrentDirectory(), Guid.NewGuid().ToString("N"));
var workingDirectory = FileSystemHelper.Path.Combine(FileSystemHelper.Path.GetCurrentDirectory(), Guid.NewGuid().ToString("N"));
var executable = ExecutableHelper.GetDotNetExecutable();

var output = new StringBuilder();
Expand All @@ -96,7 +97,7 @@ public void WorkingDirectoryDoesNotExistFailsWithInformativeMessage()
null,
executable,
args,
PathHelper.GetCurrentDirectory());
FileSystemHelper.Path.GetCurrentDirectory());

exitCode.ShouldNotBe(0);
var outputString = output.ToString();
Expand Down
8 changes: 4 additions & 4 deletions src/GitVersion.App.Tests/Helpers/GitVersionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static ExecutionResults ExecuteIn(
bool logToFile = true,
params KeyValuePair<string, string?>[] environments)
{
var logFile = workingDirectory is not null && logToFile ? PathHelper.Combine(workingDirectory, "log.txt") : null;
var logFile = workingDirectory is not null && logToFile ? FileSystemHelper.Path.Combine(workingDirectory, "log.txt") : null;
var args = new ArgumentBuilder(workingDirectory, arguments, logFile);
return ExecuteIn(args, environments);
}
Expand Down Expand Up @@ -50,7 +50,7 @@ private static ExecutionResults ExecuteIn(ArgumentBuilder arguments,
Console.WriteLine("Executing: {0} {1}", executable, args);
Console.WriteLine();

var workingDirectory = arguments.WorkingDirectory ?? PathHelper.GetCurrentDirectory();
var workingDirectory = arguments.WorkingDirectory ?? FileSystemHelper.Path.GetCurrentDirectory();

exitCode = ProcessHelper.Run(
s => output.AppendLine(s),
Expand All @@ -77,12 +77,12 @@ private static ExecutionResults ExecuteIn(ArgumentBuilder arguments,
Console.WriteLine();
Console.WriteLine("-------------------------------------------------------");

if (arguments.LogFile.IsNullOrWhiteSpace() || !File.Exists(arguments.LogFile))
if (arguments.LogFile.IsNullOrWhiteSpace() || !FileSystemHelper.File.Exists(arguments.LogFile))
{
return new(exitCode, output.ToString());
}

var logContents = File.ReadAllText(arguments.LogFile);
var logContents = FileSystemHelper.File.ReadAllText(arguments.LogFile);
Console.WriteLine("Log from gitversion tool");
Console.WriteLine("-------------------------------------------------------");
Console.WriteLine(logContents);
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.App.Tests/JsonOutputOnBuildServerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public void BeingOnBuildServerWithOutputJsonAndOutputFileDoesNotFail(string outp
result.OutputVariables.ShouldNotBeNull();
result.OutputVariables.FullSemVer.ShouldBeEquivalentTo(expectedVersion);

var filePath = PathHelper.Combine(fixture.LocalRepositoryFixture.RepositoryPath, fileName);
var json = File.ReadAllText(filePath);
var filePath = FileSystemHelper.Path.Combine(fixture.LocalRepositoryFixture.RepositoryPath, fileName);
var json = FileSystemHelper.File.ReadAllText(filePath);

var outputVariables = json.ToGitVersionVariables();
outputVariables.ShouldNotBeNull();
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.App.Tests/PullRequestInBuildAgentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public async Task VerifyBitBucketPipelinesPullRequest(string pullRequestRef)
private static async Task VerifyPullRequestVersionIsCalculatedProperly(string pullRequestRef, Dictionary<string, string> env)
{
using var fixture = new EmptyRepositoryFixture();
var remoteRepositoryPath = PathHelper.GetRepositoryTempPath();
var remoteRepositoryPath = FileSystemHelper.Path.GetRepositoryTempPath();
RepositoryFixtureBase.Init(remoteRepositoryPath);
using (var remoteRepository = new Repository(remoteRepositoryPath))
{
Expand Down Expand Up @@ -184,7 +184,7 @@ private static async Task VerifyPullRequestVersionIsCalculatedProperly(string pu
result.OutputVariables.FullSemVer.ShouldBe("1.0.4-PullRequest5.3");

// Cleanup repository files
DirectoryHelper.DeleteDirectory(remoteRepositoryPath);
FileSystemHelper.Directory.DeleteDirectory(remoteRepositoryPath);
}

private static readonly object[] PrMergeRefInputs =
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.App.Tests/TagCheckoutInBuildAgentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task VerifyTagCheckoutOnGitHubActions()
private static async Task VerifyTagCheckoutVersionIsCalculatedProperly(Dictionary<string, string> env)
{
using var fixture = new EmptyRepositoryFixture();
var remoteRepositoryPath = PathHelper.GetRepositoryTempPath();
var remoteRepositoryPath = FileSystemHelper.Path.GetRepositoryTempPath();
RepositoryFixtureBase.Init(remoteRepositoryPath);
using (var remoteRepository = new Repository(remoteRepositoryPath))
{
Expand Down Expand Up @@ -66,6 +66,6 @@ private static async Task VerifyTagCheckoutVersionIsCalculatedProperly(Dictionar
result.OutputVariables.FullSemVer.ShouldBe("0.2.0");

// Cleanup repository files
DirectoryHelper.DeleteDirectory(remoteRepositoryPath);
FileSystemHelper.Directory.DeleteDirectory(remoteRepositoryPath);
}
}
6 changes: 3 additions & 3 deletions src/GitVersion.App.Tests/UpdateWixVersionFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void WixVersionFileCreationTest()
fixture.MakeACommit();

GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: " /updatewixversionfile");
Assert.That(File.Exists(PathHelper.Combine(fixture.RepositoryPath, this.wixVersionFileName)), Is.True);
Assert.That(FileSystemHelper.File.Exists(FileSystemHelper.Path.Combine(fixture.RepositoryPath, this.wixVersionFileName)), Is.True);
}

[Test]
Expand All @@ -36,7 +36,7 @@ public void WixVersionFileVarCountTest()

GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: " /updatewixversionfile");

var gitVersionVarsInWix = GetGitVersionVarsInWixFile(PathHelper.Combine(fixture.RepositoryPath, this.wixVersionFileName));
var gitVersionVarsInWix = GetGitVersionVarsInWixFile(FileSystemHelper.Path.Combine(fixture.RepositoryPath, this.wixVersionFileName));
var gitVersionVars = GitVersionVariables.AvailableVariables;

Assert.That(gitVersionVarsInWix, Has.Count.EqualTo(gitVersionVars.Count()));
Expand All @@ -55,7 +55,7 @@ public void WixVersionFileContentTest()

GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: " /updatewixversionfile");

var gitVersionVarsInWix = GetGitVersionVarsInWixFile(PathHelper.Combine(fixture.RepositoryPath, this.wixVersionFileName));
var gitVersionVarsInWix = GetGitVersionVarsInWixFile(FileSystemHelper.Path.Combine(fixture.RepositoryPath, this.wixVersionFileName));
var gitVersionVars = GitVersionVariables.AvailableVariables;

foreach (var variable in gitVersionVars)
Expand Down
17 changes: 8 additions & 9 deletions src/GitVersion.App/ArgumentParser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.IO.Abstractions;
using GitVersion.Agents;
using GitVersion.Extensions;
using GitVersion.FileSystemGlobbing;
using GitVersion.Helpers;
using GitVersion.Logging;
using GitVersion.OutputVariables;
Expand Down Expand Up @@ -107,14 +108,14 @@ private void ValidateConfigurationFile(Arguments arguments)
{
if (arguments.ConfigurationFile.IsNullOrWhiteSpace()) return;

if (PathHelper.IsPathRooted(arguments.ConfigurationFile))
if (FileSystemHelper.Path.IsPathRooted(arguments.ConfigurationFile))
{
if (!this.fileSystem.File.Exists(arguments.ConfigurationFile)) throw new WarningException($"Could not find config file at '{arguments.ConfigurationFile}'");
arguments.ConfigurationFile = PathHelper.GetFullPath(arguments.ConfigurationFile);
arguments.ConfigurationFile = FileSystemHelper.Path.GetFullPath(arguments.ConfigurationFile);
}
else
{
var configFilePath = PathHelper.GetFullPath(PathHelper.Combine(arguments.TargetPath, arguments.ConfigurationFile));
var configFilePath = FileSystemHelper.Path.GetFullPath(FileSystemHelper.Path.Combine(arguments.TargetPath, arguments.ConfigurationFile));
if (!this.fileSystem.File.Exists(configFilePath)) throw new WarningException($"Could not find config file at '{configFilePath}'");
arguments.ConfigurationFile = configFilePath;
}
Expand Down Expand Up @@ -152,11 +153,9 @@ private IEnumerable<string> ResolveFiles(string workingDirectory, ISet<string>?

foreach (var file in assemblyInfoFiles)
{
var paths = this.globbingResolver.Resolve(workingDirectory, file);

foreach (var path in paths)
foreach (var path in this.globbingResolver.Resolve(workingDirectory, file))
{
yield return PathHelper.GetFullPath(PathHelper.Combine(workingDirectory, path));
yield return path;
}
}
}
Expand All @@ -182,7 +181,7 @@ private void ParseTargetPath(Arguments arguments, string? name, IReadOnlyList<st
{
if (name?.StartsWith('/') == true)
{
if (PathHelper.DirectorySeparatorChar == '/' && name.IsValidPath())
if (FileSystemHelper.Path.DirectorySeparatorChar == '/' && name.IsValidPath())
{
arguments.TargetPath = name;
return;
Expand Down Expand Up @@ -379,7 +378,7 @@ private static void ParseShowVariable(Arguments arguments, string? value, string

if (versionVariable == null)
{
var message = $"{name} requires a valid version variable. Available variables are:{PathHelper.NewLine}" +
var message = $"{name} requires a valid version variable. Available variables are:{FileSystemHelper.Path.NewLine}" +
string.Join(", ", availableVariables.Select(x => string.Concat("'", x, "'")));
throw new WarningException(message);
}
Expand Down
Loading