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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void EmptyOnFetchDisabledBuildServerMeansNoFetchIsTrue()
arguments.NoFetch.ShouldBe(true);
}

private class MockBuildAgent : ICurrentBuildAgent
private sealed class MockBuildAgent : ICurrentBuildAgent
{
public bool IsDefault => false;
public bool CanApplyToCurrentContext() => throw new NotImplementedException();
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.App.Tests/ExecCmdLineArgumentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void WorkingDirectoryWithoutCommitsFailsWithInformativeMessage()
public void WorkingDirectoryDoesNotExistFailsWithInformativeMessage()
{
var workingDirectory = FileSystemHelper.Path.Combine(FileSystemHelper.Path.GetCurrentDirectory(), Guid.NewGuid().ToString("N"));
var executable = ExecutableHelper.GetDotNetExecutable();
var executable = ExecutableHelper.DotNetExecutable;

var output = new StringBuilder();
var args = ExecutableHelper.GetExecutableArgs($" /targetpath {workingDirectory} ");
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.App.Tests/Helpers/ExecutableHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace GitVersion.App.Tests.Helpers;

public static class ExecutableHelper
{
public static string GetDotNetExecutable() => "dotnet";
public const string DotNetExecutable = "dotnet";

public static string GetExecutableArgs(string args) => $"{FileSystemHelper.Path.Combine(GetExeDirectory(), "gitversion.dll")} {args}";

Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.App.Tests/Helpers/GitVersionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private static ExecutionResults ExecuteIn(ArgumentBuilder arguments,
params KeyValuePair<string, string?>[] environments
)
{
var executable = ExecutableHelper.GetDotNetExecutable();
var executable = ExecutableHelper.DotNetExecutable;
var output = new StringBuilder();

var environmentalVariables = new Dictionary<string, string?>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using System.IO.Abstractions;
using GitVersion.Agents;
using GitVersion.Configuration;
Expand Down Expand Up @@ -34,7 +35,7 @@ public void BuildNumberIsFullSemVer()
BuildMetaData = new SemanticVersionBuildMetaData("5")
{
Sha = "commitSha",
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z", CultureInfo.InvariantCulture)
}
};

Expand All @@ -49,7 +50,7 @@ public void BuildNumberIsFullSemVer()
writes.ShouldNotContain(x => x != null && x.StartsWith("Set Build Number for "));
}

private class BuildAgent(IEnvironment environment, ILog log, IFileSystem fileSystem) : BuildAgentBase(environment, log, fileSystem)
private sealed class BuildAgent(IEnvironment environment, ILog log, IFileSystem fileSystem) : BuildAgentBase(environment, log, fileSystem)
{
protected override string EnvironmentVariable => throw new NotImplementedException();

Expand Down
3 changes: 2 additions & 1 deletion src/GitVersion.BuildAgents.Tests/Agents/CodeBuildTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using System.IO.Abstractions;
using GitVersion.Agents;
using GitVersion.Configuration;
Expand Down Expand Up @@ -81,7 +82,7 @@ private void AssertVariablesAreWrittenToFile(string file)
BuildMetaData = new SemanticVersionBuildMetaData("5")
{
Sha = "commitSha",
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z", CultureInfo.InvariantCulture)
}
};

Expand Down
7 changes: 3 additions & 4 deletions src/GitVersion.BuildAgents.Tests/Agents/DroneTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ namespace GitVersion.BuildAgents.Tests;
public class DroneTests : TestBase
{
private IEnvironment environment = null!;
private IServiceProvider sp = null!;
private Drone buildServer = null!;

[SetUp]
public void SetUp()
{
this.sp = ConfigureServices(services => services.AddSingleton<Drone>());
this.environment = this.sp.GetRequiredService<IEnvironment>();
this.buildServer = this.sp.GetRequiredService<Drone>();
var sp = ConfigureServices(services => services.AddSingleton<Drone>());
this.environment = sp.GetRequiredService<IEnvironment>();
this.buildServer = sp.GetRequiredService<Drone>();
this.environment.SetEnvironmentVariable("DRONE", "true");
}

Expand Down
3 changes: 2 additions & 1 deletion src/GitVersion.BuildAgents.Tests/Agents/GitLabCiTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using System.IO.Abstractions;
using GitVersion.Agents;
using GitVersion.Configuration;
Expand Down Expand Up @@ -121,7 +122,7 @@ private void AssertVariablesAreWrittenToFile(string file)
BuildMetaData = new SemanticVersionBuildMetaData("5")
{
Sha = "commitSha",
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z", CultureInfo.InvariantCulture)
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/GitVersion.BuildAgents.Tests/Agents/JenkinsTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using System.IO.Abstractions;
using GitVersion.Agents;
using GitVersion.Configuration;
Expand Down Expand Up @@ -134,7 +135,7 @@ private void AssertVariablesAreWrittenToFile(string file)
Minor = 2,
Patch = 3,
PreReleaseTag = "beta1",
BuildMetaData = new SemanticVersionBuildMetaData("5") { Sha = "commitSha", CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z") }
BuildMetaData = new SemanticVersionBuildMetaData("5") { Sha = "commitSha", CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z", CultureInfo.InvariantCulture) }
};

var variableProvider = this.sp.GetRequiredService<IVariableProvider>();
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.Core.Tests/CommitDateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class CommitDateTests : TestBase
[TestCase("yyyy-MM", "2017-10")]
public void CommitDateFormatTest(string format, string expectedOutcome)
{
var date = new DateTime(2017, 10, 6);
var date = new DateTime(2017, 10, 6, 0, 0, 0, DateTimeKind.Utc);
var semanticVersionBuildMetaData = new SemanticVersionBuildMetaData(
new SemanticVersion(1, 2, 2),
"950d2f830f5a2af12a6779a48d20dcbb02351f25",
Expand Down
5 changes: 0 additions & 5 deletions src/GitVersion.Core.Tests/Core/DynamicRepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ public class DynamicRepositoryTests : TestBase
[SetUp]
public void SetUp() => this.workDirectory = FileSystemHelper.Path.Combine(FileSystemHelper.Path.GetTempPathLegacy(), "GV");

[TearDown]
public void TearDown()
{
}

// Note: use same name twice to see if changing commits works on same (cached) repository
[NonParallelizable]
[TestCase("GV_main", "https://github.com/GitTools/GitVersion", MainBranch, "2dc142a4a4df77db61a00d9fb7510b18b3c2c85a", "5.8.2-47")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace GitVersion.Tests;
[TestFixture]
public class GitVersionTaskDirectoryTests : TestBase
{
private string gitDirectory = null!;
private string workDirectory = null!;
private IFileSystem fileSystem = null!;

Expand All @@ -17,8 +16,8 @@ public void SetUp()
var sp = ConfigureServices();
this.fileSystem = sp.GetRequiredService<IFileSystem>();
this.workDirectory = FileSystemHelper.Path.Combine(FileSystemHelper.Path.GetTempPath(), Guid.NewGuid().ToString());
this.gitDirectory = Repository.Init(this.workDirectory).TrimEnd(FileSystemHelper.Path.DirectorySeparatorChar);
Assert.That(this.gitDirectory, Is.Not.Null);
var gitDirectory = Repository.Init(this.workDirectory).TrimEnd(FileSystemHelper.Path.DirectorySeparatorChar);
Assert.That(gitDirectory, Is.Not.Null);
}

[TearDown]
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.Core.Tests/Formatting/DateFormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void TryFormat_ValidDateFormats_ReturnsExpectedResult(string input, strin
{
// For UTC datetime strings, parse as UTC to ensure consistent behavior across timezones
DateTime date;
if (input.EndsWith("Z"))
if (input.EndsWith('Z'))
{
date = DateTime.Parse(input, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
}
Expand Down
17 changes: 3 additions & 14 deletions src/GitVersion.Core.Tests/Helpers/GitVersionContextBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

namespace GitVersion.Tests;

public class GitVersionContextBuilder : IDisposable
public sealed class GitVersionContextBuilder : IDisposable
{
private IGitRepository? repository;
private EmptyRepositoryFixture? emptyRepositoryFixture;
private IReadOnlyDictionary<object, object?>? overrideConfiguration;
private Action<IServiceCollection>? overrideServices;
public IServiceProvider? ServicesProvider;
public IServiceProvider? ServicesProvider { get; private set; }

public GitVersionContextBuilder WithRepository(IGitRepository gitRepository)
{
Expand Down Expand Up @@ -58,7 +58,7 @@ public void Build()
this.emptyRepositoryFixture = new();
var options = Options.Create(new GitVersionOptions { WorkingDirectory = this.emptyRepositoryFixture.RepositoryPath, ConfigurationInfo = { OverrideConfiguration = this.overrideConfiguration } });

this.ServicesProvider = ConfigureServices(services =>
ServicesProvider = ConfigureServices(services =>
{
services.AddSingleton(options);
services.AddSingleton(repo);
Expand Down Expand Up @@ -93,17 +93,6 @@ private static ServiceProvider ConfigureServices(Action<IServiceCollection>? ove

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

private void Dispose(bool disposing)
{
if (!disposing)
{
return;
}

this.repository?.Dispose();
this.emptyRepositoryFixture?.Dispose();
}
Expand Down
4 changes: 4 additions & 0 deletions src/GitVersion.Core.Tests/Helpers/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ public class TestBase
{
public const string MainBranch = "main";

protected TestBase()
{
}

protected static IServiceProvider ConfigureServices(Action<IServiceCollection>? overrideServices = null)
{
var services = new ServiceCollection()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private static List<ICommit> GetParents(bool isMergeCommit) =>
? [new MockCommit(), new MockCommit()]
: [new MockCommit()];

private class MockCommit : ICommit
private sealed class MockCommit : ICommit
{
public bool Equals(ICommit? other) => throw new NotImplementedException();
public int CompareTo(ICommit? other) => throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void ProvidesVariablesInContinuousDeliveryModeForPreRelease()
VersionSourceSha = "versionSourceSha",
Sha = "commitSha",
ShortSha = "commitShortSha",
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z", CultureInfo.InvariantCulture)
}
};

Expand All @@ -68,7 +68,7 @@ public void ProvidesVariablesInContinuousDeploymentModeForPreRelease()
Sha = "commitSha",
ShortSha = "commitShortSha",
VersionSourceDistance = 5,
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z", CultureInfo.InvariantCulture)
}
};

Expand All @@ -92,7 +92,7 @@ public void ProvidesVariablesInContinuousDeliveryModeForStable()
VersionSourceSha = "versionSourceSha",
Sha = "commitSha",
ShortSha = "commitShortSha",
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z", CultureInfo.InvariantCulture)
}
};

Expand All @@ -118,7 +118,7 @@ public void ProvidesVariablesInContinuousDeploymentModeForStable()
Sha = "commitSha",
ShortSha = "commitShortSha",
VersionSourceDistance = 5,
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z", CultureInfo.InvariantCulture)
}
};

Expand All @@ -144,7 +144,7 @@ public void ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommi
VersionSourceDistance = 5,
Sha = "commitSha",
ShortSha = "commitShortSha",
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z", CultureInfo.InvariantCulture)
}
};

Expand All @@ -169,7 +169,7 @@ public void ProvidesVariablesInContinuousDeploymentModeWithTagNamePattern()
Branch = "pull/2/merge",
Sha = "commitSha",
ShortSha = "commitShortSha",
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z", CultureInfo.InvariantCulture)
}
};

Expand All @@ -194,7 +194,7 @@ public void ProvidesVariablesInContinuousDeploymentModeWithTagSetToBranchName()
Branch = "feature",
Sha = "commitSha",
ShortSha = "commitShortSha",
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z", CultureInfo.InvariantCulture)
}
};

Expand All @@ -219,7 +219,7 @@ public void ProvidesVariablesInContinuousDeliveryModeForFeatureBranch()
VersionSourceSha = "versionSourceSha",
Sha = "commitSha",
ShortSha = "commitShortSha",
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z", CultureInfo.InvariantCulture)
}
};

Expand All @@ -244,7 +244,7 @@ public void ProvidesVariablesInContinuousDeliveryModeForFeatureBranchWithCustomA
VersionSourceSha = "versionSourceSha",
Sha = "commitSha",
ShortSha = "commitShortSha",
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z", CultureInfo.InvariantCulture)
}
};

Expand Down Expand Up @@ -281,7 +281,7 @@ public void ProvidesVariablesInContinuousDeploymentModeForMainBranchWithEmptyLab
Sha = "commitSha",
ShortSha = "commitShortSha",
VersionSourceDistance = 5,
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z", CultureInfo.InvariantCulture)
}
};

Expand Down
14 changes: 4 additions & 10 deletions src/GitVersion.Core/Core/RepositoryStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,9 @@ public IEnumerable<IBranch> GetSourceBranches(
break;
}

foreach (var commit in commitBranch.Branch.Commits.Where(element => element.When >= item.Commit.When))
if (commitBranch.Branch.Commits.Any(element => element.When >= item.Commit.When && element.Equals(item.Commit)))
{
if (commit.Equals(item.Commit))
{
commitBranches.Remove(item);
}
commitBranches.Remove(item);
}
}
}
Expand All @@ -172,12 +169,9 @@ public IEnumerable<IBranch> GetSourceBranches(
continue;
}

foreach (var item in branchGrouping)
foreach (var item in branchGrouping.Where(returnedBranches.Add))
{
if (returnedBranches.Add(item))
{
yield return item;
}
yield return item;
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/GitVersion.Output.Tests/Output/WixFileTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using System.IO.Abstractions;
using GitVersion.Configuration;
using GitVersion.Helpers;
Expand Down Expand Up @@ -36,7 +37,7 @@ public void UpdateWixVersionFile()
VersionSourceSha = "versionSourceSha",
Sha = "commitSha",
ShortSha = "commitShortSha",
CommitDate = DateTimeOffset.Parse("2019-02-20 23:59:59Z")
CommitDate = DateTimeOffset.Parse("2019-02-20 23:59:59Z", CultureInfo.InvariantCulture)
}
};

Expand Down Expand Up @@ -77,7 +78,7 @@ public void UpdateWixVersionFileWhenFileAlreadyExists()
VersionSourceSha = "versionSourceSha",
Sha = "commitSha",
ShortSha = "commitShortSha",
CommitDate = DateTimeOffset.Parse("2019-02-20 23:59:59Z")
CommitDate = DateTimeOffset.Parse("2019-02-20 23:59:59Z", CultureInfo.InvariantCulture)
}
};

Expand Down
Loading