-
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #586 from m0sa/disabling
Add NBGV_GitEngine=Disabled option
- Loading branch information
Showing
22 changed files
with
987 additions
and
836 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/NerdBank.GitVersioning/DisabledGit/DisabledGitContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// 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. | ||
|
||
#nullable enable | ||
|
||
using System.Diagnostics; | ||
|
||
namespace Nerdbank.GitVersioning; | ||
|
||
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")] | ||
internal class DisabledGitContext : GitContext | ||
{ | ||
public DisabledGitContext(string workingTreePath) | ||
: base(workingTreePath, null) | ||
{ | ||
this.VersionFile = new DisabledGitVersionFile(this); | ||
} | ||
|
||
public override VersionFile VersionFile { get; } | ||
|
||
public override string? GitCommitId => null; | ||
|
||
public override bool IsHead => false; | ||
|
||
public override DateTimeOffset? GitCommitDate => null; | ||
|
||
public override string? HeadCanonicalName => null; | ||
|
||
private string DebuggerDisplay => $"\"{this.WorkingTreePath}\" (disabled-git)"; | ||
|
||
public override void ApplyTag(string name) => throw new NotSupportedException(); | ||
|
||
public override void Stage(string path) => throw new NotSupportedException(); | ||
|
||
public override string GetShortUniqueCommitId(int minLength) => "nerdbankdisabled"; | ||
|
||
public override bool TrySelectCommit(string committish) => true; | ||
|
||
internal override int CalculateVersionHeight(VersionOptions? committedVersion, VersionOptions? workingVersion) => 0; | ||
|
||
internal override Version GetIdAsVersion(VersionOptions? committedVersion, VersionOptions? workingVersion, int versionHeight) => Version0; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/NerdBank.GitVersioning/DisabledGit/DisabledGitVersionFile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 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. | ||
|
||
#nullable enable | ||
|
||
namespace Nerdbank.GitVersioning; | ||
|
||
internal class DisabledGitVersionFile : VersionFile | ||
{ | ||
public DisabledGitVersionFile(GitContext context) | ||
: base(context) | ||
{ | ||
} | ||
|
||
protected new DisabledGitContext Context => (DisabledGitContext)base.Context; | ||
|
||
protected override VersionOptions? GetVersionCore(out string? actualDirectory) | ||
{ | ||
actualDirectory = null; | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
test/Nerdbank.GitVersioning.Tests/BuildIntegrationDisabledTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
22 changes: 22 additions & 0 deletions
22
test/Nerdbank.GitVersioning.Tests/BuildIntegrationInProjectManagedTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 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 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 BuildIntegrationInProjectManagedTests : BuildIntegrationManagedTests | ||
{ | ||
public BuildIntegrationInProjectManagedTests(ITestOutputHelper logger) | ||
: base(logger) | ||
{ | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override void ApplyGlobalProperties(IDictionary<string, string> globalProperties) | ||
{ | ||
base.ApplyGlobalProperties(globalProperties); | ||
globalProperties["NBGV_CacheMode"] = "None"; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
test/Nerdbank.GitVersioning.Tests/BuildIntegrationLibGit2Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
24
test/Nerdbank.GitVersioning.Tests/BuildIntegrationManagedTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
protected 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; | ||
} |
Oops, something went wrong.