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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,5 @@ node_modules

dogfood/
new-cli/log.txt

new-cli/logs/
1 change: 1 addition & 0 deletions new-cli/.idea/.idea.GitVersion/.idea/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions new-cli/.idea/.idea.GitVersion/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions new-cli/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<PackageVersion Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageVersion Include="Serilog.Sinks.Map" Version="2.0.0" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.25153.1" />
<PackageVersion Include="System.IO.Abstractions" Version="22.0.11" />
<PackageVersion Include="System.Text.Json" Version="9.0.2" />
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion new-cli/GitVersion.Common/GitVersion.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\src\GitVersion.Core\Core\Abstractions\IEnvironment.cs" Link="Infrastructure\%(Filename)%(Extension)" />
<Compile Include="..\..\src\GitVersion.Core\Core\Abstractions\IFileSystem.cs" Link="Infrastructure\%(Filename)%(Extension)" />
<Compile Include="..\..\src\GitVersion.Core\Core\Exceptions\WarningException.cs" Link="Exceptions\%(Filename)%(Extension)"/>
<Compile Include="..\..\src\GitVersion.Core\Core\RegexPatterns.cs" Link="%(Filename)%(Extension)" />
<Compile Include="..\..\src\GitVersion.Core\Extensions\DictionaryExtensions.cs" Link="%(Filename)%(Extension)" />
Expand Down
1 change: 1 addition & 0 deletions new-cli/GitVersion.Core/CoreModule.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.IO.Abstractions;
using GitVersion.Infrastructure;

namespace GitVersion;
Expand Down
4 changes: 1 addition & 3 deletions new-cli/GitVersion.Core/GitVersion.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
<PackageReference Include="Serilog.Sinks.Console" />
<PackageReference Include="Serilog.Sinks.File" />
<PackageReference Include="Serilog.Sinks.Map" />
<PackageReference Include="System.IO.Abstractions" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\src\GitVersion.Core\Core\Environment.cs">
<Link>Infrastructure\Environment.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Core\FileSystem.cs">
<Link>Infrastructure\FileSystem.cs</Link>
</Compile>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion new-cli/docs/calculate.rsp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
calculate -l c:\logs\log.txt --work-dir C:\Projects\OSS\GitTools\GitVersion --verbosity verbose
calculate -l ./logs/log.txt --work-dir . --verbosity verbose
2 changes: 1 addition & 1 deletion new-cli/docs/output-project.rsp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
output --output-dir C:\Projects\OSS\GitTools\GitVersion --input-file version.json project --project-file project.csproj
output --output-dir ./output --input-file version.json project --project-file project.csproj
2 changes: 1 addition & 1 deletion new-cli/docs/output-wix.rsp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
output --output-dir C:\Projects\OSS\GitTools\GitVersion --input-file version.json wix --wix-file project.wix
output --output-dir ./output --input-file version.json wix --wix-file project.wix
3 changes: 3 additions & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
<PackageVersion Include="NUnit.Analyzers" Version="4.6.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="5.0.0" />
<PackageVersion Include="Shouldly" Version="4.3.0" />
<PackageVersion Include="System.Collections.Immutable" Version="9.0.2" />
<PackageVersion Include="System.Drawing.Common" Version="9.0.2" />
<PackageVersion Include="System.IO.Abstractions" Version="22.0.11" />
<PackageVersion Include="System.Reflection.Metadata" Version="9.0.2" />
<PackageVersion Include="System.Security.Cryptography.Xml" Version="9.0.2" />
<PackageVersion Include="System.Text.Json" Version="9.0.2" />
<PackageVersion Include="YamlDotNet" Version="16.3.0" />
Expand Down
45 changes: 23 additions & 22 deletions src/GitVersion.App.Tests/ArgumentParserTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.IO.Abstractions;
using GitVersion.Configuration;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Helpers;
Expand Down Expand Up @@ -283,12 +284,12 @@ public void UpdateAssemblyInfoWithFilename()
using var repo = new EmptyRepositoryFixture();

var assemblyFile = PathHelper.Combine(repo.RepositoryPath, "CommonAssemblyInfo.cs");
using var file = File.Create(assemblyFile);
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 => Path.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
}

[Test]
Expand All @@ -297,16 +298,16 @@ public void UpdateAssemblyInfoWithMultipleFilenames()
using var repo = new EmptyRepositoryFixture();

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

var assemblyFile2 = PathHelper.Combine(repo.RepositoryPath, "VersionAssemblyInfo.cs");
using var file2 = File.Create(assemblyFile2);
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 => Path.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => Path.GetFileName(x).Equals("VersionAssemblyInfo.cs"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("VersionAssemblyInfo.cs"));
}

[Test]
Expand All @@ -315,16 +316,16 @@ public void UpdateProjectFilesWithMultipleFilenames()
using var repo = new EmptyRepositoryFixture();

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

var assemblyFile2 = PathHelper.Combine(repo.RepositoryPath, "VersionAssemblyInfo.csproj");
using var file2 = File.Create(assemblyFile2);
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 => Path.GetFileName(x).Equals("CommonAssemblyInfo.csproj"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => Path.GetFileName(x).Equals("VersionAssemblyInfo.csproj"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("CommonAssemblyInfo.csproj"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("VersionAssemblyInfo.csproj"));
}

[Test]
Expand All @@ -333,23 +334,23 @@ public void UpdateAssemblyInfoWithMultipleFilenamesMatchingGlobbing()
using var repo = new EmptyRepositoryFixture();

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

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

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

this.fileSystem.CreateDirectory(subdir);
this.fileSystem.Directory.CreateDirectory(subdir);
var assemblyFile3 = PathHelper.Combine(subdir, "LocalAssemblyInfo.cs");
using var file3 = File.Create(assemblyFile3);
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 => Path.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => Path.GetFileName(x).Equals("VersionAssemblyInfo.cs"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => Path.GetFileName(x).Equals("LocalAssemblyInfo.cs"));
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"));
}

[Test]
Expand All @@ -358,15 +359,15 @@ public void UpdateAssemblyInfoWithRelativeFilename()
using var repo = new EmptyRepositoryFixture();

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

var targetPath = PathHelper.Combine(repo.RepositoryPath, "subdir1", "subdir2");
this.fileSystem.CreateDirectory(targetPath);
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 => Path.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
}

[Test]
Expand Down Expand Up @@ -765,9 +766,9 @@ public void ThrowIfConfigurationFileDoesNotExist(string configFile) =>
public void EnsureConfigurationFileIsSet()
{
var configFile = PathHelper.GetTempPath() + Guid.NewGuid() + ".yaml";
File.WriteAllText(configFile, "next-version: 1.0.0");
this.fileSystem.File.WriteAllText(configFile, "next-version: 1.0.0");
var arguments = this.argumentParser.ParseArguments($"-config {configFile}");
arguments.ConfigurationFile.ShouldBe(configFile);
File.Delete(configFile);
this.fileSystem.File.Delete(configFile);
}
}
2 changes: 1 addition & 1 deletion src/GitVersion.App.Tests/GitVersion.App.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
<PackageReference Include="System.Collections.Immutable" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GitVersion.Configuration\GitVersion.Configuration.csproj" />
Expand All @@ -15,7 +16,6 @@
<Content Include="Approved\**\*.approved.txt" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\GitVersion.Core.Tests\Helpers\DirectoryHelper.cs" Link="Helpers\DirectoryHelper.cs" />
<Compile Include="..\GitVersion.Core.Tests\Helpers\ExecutableHelper.cs" Link="Helpers\ExecutableHelper.cs" />
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestConsoleAdapter.cs" Link="Helpers\TestConsoleAdapter.cs" />
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestEnvironment.cs" Link="Helpers\TestEnvironment.cs" />
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.App.Tests/Helpers/ProgramFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void WithEnv(params KeyValuePair<string, string>[] envs)

public Task<ExecutionResults> Run(string arg)
{
var args = arg.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
var args = arg.Split([' '], StringSplitOptions.RemoveEmptyEntries).ToArray();
return Run(args);
}

Expand Down
17 changes: 9 additions & 8 deletions src/GitVersion.App/ArgumentParser.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.IO.Abstractions;
using GitVersion.Agents;
using GitVersion.Extensions;
using GitVersion.Helpers;
Expand Down Expand Up @@ -106,15 +107,15 @@ private void ValidateConfigurationFile(Arguments arguments)
{
if (arguments.ConfigurationFile.IsNullOrWhiteSpace()) return;

if (Path.IsPathRooted(arguments.ConfigurationFile))
if (PathHelper.IsPathRooted(arguments.ConfigurationFile))
{
if (!this.fileSystem.Exists(arguments.ConfigurationFile)) throw new WarningException($"Could not find config file at '{arguments.ConfigurationFile}'");
arguments.ConfigurationFile = Path.GetFullPath(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);
}
else
{
var configFilePath = Path.GetFullPath(PathHelper.Combine(arguments.TargetPath, arguments.ConfigurationFile));
if (!this.fileSystem.Exists(configFilePath)) throw new WarningException($"Could not find config file at '{configFilePath}'");
var configFilePath = PathHelper.GetFullPath(PathHelper.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 @@ -155,7 +156,7 @@ private IEnumerable<string> ResolveFiles(string workingDirectory, ISet<string>?

foreach (var path in paths)
{
yield return Path.GetFullPath(PathHelper.Combine(workingDirectory, path));
yield return PathHelper.GetFullPath(PathHelper.Combine(workingDirectory, path));
}
}
}
Expand All @@ -166,7 +167,7 @@ private void ParseTargetPath(Arguments arguments, string? name, IReadOnlyList<st
{
EnsureArgumentValueCount(values);
arguments.TargetPath = value;
if (string.IsNullOrWhiteSpace(value) || !this.fileSystem.DirectoryExists(value))
if (string.IsNullOrWhiteSpace(value) || !this.fileSystem.Directory.Exists(value))
{
this.console.WriteLine($"The working directory '{value}' does not exist.");
}
Expand All @@ -181,7 +182,7 @@ private void ParseTargetPath(Arguments arguments, string? name, IReadOnlyList<st
{
if (name?.StartsWith('/') == true)
{
if (Path.DirectorySeparatorChar == '/' && name.IsValidPath())
if (PathHelper.DirectorySeparatorChar == '/' && name.IsValidPath())
{
arguments.TargetPath = name;
return;
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.App/ArgumentParserExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static bool ArgumentRequiresValue(this string argument, int argumentIndex
var argumentMightRequireValue = !booleanArguments.Contains(argument[1..], StringComparer.OrdinalIgnoreCase);

// If this is the first argument that might be a target path, the argument starts with slash, and we're on an OS that supports paths with slashes, the argument does not require a value.
if (argumentMightRequireValue && argumentIndex == 0 && argument.StartsWith('/') && Path.DirectorySeparatorChar == '/' && argument.IsValidPath())
if (argumentMightRequireValue && argumentIndex == 0 && argument.StartsWith('/') && PathHelper.DirectorySeparatorChar == '/' && argument.IsValidPath())
return false;

return argumentMightRequireValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
using System.IO.Abstractions;
using GitVersion.Extensions;
using GitVersion.Helpers;
using GitVersion.Logging;

namespace GitVersion.Logging;
namespace GitVersion;

internal class FileAppender : ILogAppender
{
private readonly IFileSystem fileSystem;
private readonly string filePath;

public FileAppender(string filePath)
public FileAppender(IFileSystem fileSystem, string filePath)
{
this.fileSystem = fileSystem.NotNull();
this.filePath = filePath;

var logFile = new FileInfo(Path.GetFullPath(filePath));
var logFile = this.fileSystem.FileInfo.New(PathHelper.GetFullPath(filePath));

logFile.Directory?.Create();
if (logFile.Exists) return;
Expand All @@ -30,9 +35,9 @@ public void WriteTo(LogLevel level, string message)
}
}

private static void WriteLogEntry(string logFilePath, string str)
private void WriteLogEntry(string logFilePath, string str)
{
var contents = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}\t\t{str}{PathHelper.NewLine}";
File.AppendAllText(logFilePath, contents);
this.fileSystem.File.AppendAllText(logFilePath, contents);
}
}
Loading