forked from dotnet/Nerdbank.GitVersioning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoGitContext.cs
More file actions
60 lines (41 loc) · 2.02 KB
/
NoGitContext.cs
File metadata and controls
60 lines (41 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// 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 NoGitContext : GitContext
{
private const string NotAGitRepoMessage = "Not a git repo";
public NoGitContext(string workingTreePath)
: base(workingTreePath, null)
{
this.VersionFile = new NoGitVersionFile(this);
}
/// <inheritdoc/>
public override VersionFile VersionFile { get; }
/// <inheritdoc/>
public override string? GitCommitId => null;
/// <inheritdoc/>
public override bool IsHead => false;
/// <inheritdoc/>
public override DateTimeOffset? GitCommitDate => null;
public override DateTimeOffset? GitCommitAuthorDate => null;
/// <inheritdoc/>
public override string? HeadCanonicalName => null;
/// <inheritdoc/>
public override IReadOnlyCollection<string>? HeadTags => null;
private string DebuggerDisplay => $"\"{this.WorkingTreePath}\" (no-git)";
/// <inheritdoc/>
public override void ApplyTag(string name) => throw new InvalidOperationException(NotAGitRepoMessage);
/// <inheritdoc/>
public override void Stage(string path) => throw new InvalidOperationException(NotAGitRepoMessage);
/// <inheritdoc/>
public override string GetShortUniqueCommitId(int minLength) => throw new InvalidOperationException(NotAGitRepoMessage);
/// <inheritdoc/>
public override bool TrySelectCommit(string committish) => throw new InvalidOperationException(NotAGitRepoMessage);
/// <inheritdoc/>
internal override int CalculateVersionHeight(VersionOptions? committedVersion, VersionOptions? workingVersion) => 0;
/// <inheritdoc/>
internal override Version GetIdAsVersion(VersionOptions? committedVersion, VersionOptions? workingVersion, int versionHeight) => throw new NotImplementedException();
}