Skip to content

Commit

Permalink
Fix build breaks and move test classes into their own files
Browse files Browse the repository at this point in the history
  • Loading branch information
AArnott committed Apr 17, 2023
1 parent 23fc344 commit 3d67583
Show file tree
Hide file tree
Showing 16 changed files with 1,044 additions and 1,013 deletions.
2 changes: 1 addition & 1 deletion src/NerdBank.GitVersioning/Commands/CloudCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void SetBuildVariables(string projectDirectory, IEnumerable<string> metad
activeCloudBuild = CloudBuild.SupportedCloudBuilds[matchingIndex];
}

using var context = GitContext.Create(projectDirectory, writable: alwaysUseLibGit2);
using var context = GitContext.Create(projectDirectory, engine: alwaysUseLibGit2 ? GitContext.Engine.ReadWrite : GitContext.Engine.ReadOnly);
var oracle = new VersionOracle(context, cloudBuild: activeCloudBuild);
if (metadata is not null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/NerdBank.GitVersioning/ReleaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ private LibGit2Context GetRepository(string projectDirectory)
{
// open git repo and use default configuration (in order to commit we need a configured user name and email
// which is most likely configured on a user/system level rather than the repo level.
var context = GitContext.Create(projectDirectory, writable: true);
var context = GitContext.Create(projectDirectory, engine: GitContext.Engine.ReadWrite);
if (!context.IsRepository)
{
this.stderr.WriteLine($"No git repository found above directory '{projectDirectory}'.");
Expand Down
10 changes: 5 additions & 5 deletions src/nbgv/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ private static async Task<int> OnInstallCommand(string path, string version, str
return (int)ExitCodes.NoGitRepo;
}

using var context = GitContext.Create(searchPath, writable: true);
using var context = GitContext.Create(searchPath, engine: GitContext.Engine.ReadWrite);
if (!context.IsRepository)
{
Console.Error.WriteLine("No git repo found at or above: \"{0}\"", searchPath);
Expand Down Expand Up @@ -417,7 +417,7 @@ private static Task<int> OnGetVersionCommand(string project, string[] metadata,

string searchPath = GetSpecifiedOrCurrentDirectoryPath(project);

using var context = GitContext.Create(searchPath, writable: AlwaysUseLibGit2);
using var context = GitContext.Create(searchPath, engine: AlwaysUseLibGit2 ? GitContext.Engine.ReadWrite : GitContext.Engine.ReadOnly);
if (!context.IsRepository)
{
Console.Error.WriteLine("No git repo found at or above: \"{0}\"", searchPath);
Expand Down Expand Up @@ -500,7 +500,7 @@ private static Task<int> OnSetVersionCommand(string project, string version)
};

string searchPath = GetSpecifiedOrCurrentDirectoryPath(project);
using var context = GitContext.Create(searchPath, writable: true);
using var context = GitContext.Create(searchPath, engine: GitContext.Engine.ReadWrite);
VersionOptions existingOptions = context.VersionFile.GetVersion(out string actualDirectory);
string versionJsonPath;
if (existingOptions is not null)
Expand Down Expand Up @@ -540,7 +540,7 @@ private static Task<int> OnTagCommand(string project, string versionOrRef)

string searchPath = GetSpecifiedOrCurrentDirectoryPath(project);

using var context = (LibGit2Context)GitContext.Create(searchPath, writable: true);
using var context = (LibGit2Context)GitContext.Create(searchPath, engine: GitContext.Engine.ReadWrite);
if (context is null)
{
Console.Error.WriteLine("No git repo found at or above: \"{0}\"", searchPath);
Expand Down Expand Up @@ -639,7 +639,7 @@ private static Task<int> OnGetCommitsCommand(string project, bool quiet, string

string searchPath = GetSpecifiedOrCurrentDirectoryPath(project);

using var context = (LibGit2Context)GitContext.Create(searchPath, writable: true);
using var context = (LibGit2Context)GitContext.Create(searchPath, engine: GitContext.Engine.ReadWrite);
if (!context.IsRepository)
{
Console.Error.WriteLine("No git repo found at or above: \"{0}\"", searchPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public class GetVersionBenchmarks
[Benchmark(Baseline = true)]
public void GetVersionLibGit2()
{
using var context = GitContext.Create(GetPath(this.ProjectDirectory), writable: true);
using var context = GitContext.Create(GetPath(this.ProjectDirectory), engine: GitContext.Engine.ReadWrite);
var oracle = new VersionOracle(context, cloudBuild: null);
this.Version = oracle.Version;
}

[Benchmark]
public void GetVersionManaged()
{
using var context = GitContext.Create(GetPath(this.ProjectDirectory), writable: false);
using var context = GitContext.Create(GetPath(this.ProjectDirectory), engine: GitContext.Engine.ReadOnly);
var oracle = new VersionOracle(context, cloudBuild: null);
this.Version = oracle.Version;
}
Expand Down
24 changes: 24 additions & 0 deletions test/Nerdbank.GitVersioning.Tests/BuildIntegrationDisabledTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) .NET Foundation and Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Nerdbank.GitVersioning;
using Xunit;
using Xunit.Abstractions;

[Trait("Engine", EngineString)]
[Collection("Build")] // msbuild sets current directory in the process, so we can't have it be concurrent with other build tests.
public class BuildIntegrationDisabledTests : BuildIntegrationTests
{
private const string EngineString = "Disabled";

public BuildIntegrationDisabledTests(ITestOutputHelper logger)
: base(logger)
{
}

protected override GitContext CreateGitContext(string path, string committish = null)
=> GitContext.Create(path, committish, GitContext.Engine.Disabled);

protected override void ApplyGlobalProperties(IDictionary<string, string> globalProperties)
=> globalProperties["NBGV_GitEngine"] = EngineString;
}
24 changes: 24 additions & 0 deletions test/Nerdbank.GitVersioning.Tests/BuildIntegrationLibGit2Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) .NET Foundation and Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Nerdbank.GitVersioning;
using Xunit;
using Xunit.Abstractions;

[Trait("Engine", EngineString)]
[Collection("Build")] // msbuild sets current directory in the process, so we can't have it be concurrent with other build tests.
public class BuildIntegrationLibGit2Tests : SomeGitBuildIntegrationTests
{
private const string EngineString = "LibGit2";

public BuildIntegrationLibGit2Tests(ITestOutputHelper logger)
: base(logger)
{
}

protected override GitContext CreateGitContext(string path, string committish = null)
=> GitContext.Create(path, committish, GitContext.Engine.ReadWrite);

protected override void ApplyGlobalProperties(IDictionary<string, string> globalProperties)
=> globalProperties["NBGV_GitEngine"] = EngineString;
}
24 changes: 24 additions & 0 deletions test/Nerdbank.GitVersioning.Tests/BuildIntegrationManagedTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) .NET Foundation and Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Nerdbank.GitVersioning;
using Xunit;
using Xunit.Abstractions;

[Trait("Engine", EngineString)]
[Collection("Build")] // msbuild sets current directory in the process, so we can't have it be concurrent with other build tests.
public class BuildIntegrationManagedTests : SomeGitBuildIntegrationTests
{
private const string EngineString = "Managed";

public BuildIntegrationManagedTests(ITestOutputHelper logger)
: base(logger)
{
}

protected override GitContext CreateGitContext(string path, string committish = null)
=> GitContext.Create(path, committish, GitContext.Engine.ReadOnly);

protected override void ApplyGlobalProperties(IDictionary<string, string> globalProperties)
=> globalProperties["NBGV_GitEngine"] = EngineString;
}
Loading

0 comments on commit 3d67583

Please sign in to comment.