Skip to content

Commit

Permalink
Make .git folder optional so tool can be run on any folder (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz authored Jan 7, 2025
1 parent 20a4d81 commit b19b0c8
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/Elastic.Markdown/IO/GitConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,21 @@ namespace Elastic.Markdown.IO;

public record GitConfiguration
{
[JsonPropertyName("branch")] public required string Branch { get; init; }
[JsonPropertyName("remote")] public required string Remote { get; init; }
[JsonPropertyName("ref")] public required string Ref { get; init; }
private static GitConfiguration Unavailable { get; } = new()
{
Branch = "unavailable",
Remote = "unavailable",
Ref = "unavailable"
};

[JsonPropertyName("branch")]
public required string Branch { get; init; }

[JsonPropertyName("remote")]
public required string Remote { get; init; }

[JsonPropertyName("ref")]
public required string Ref { get; init; }

// manual read because libgit2sharp is not yet AOT ready
public static GitConfiguration Create(IFileSystem fileSystem)
Expand All @@ -26,7 +38,7 @@ public static GitConfiguration Create(IFileSystem fileSystem)

var gitConfig = Git(".git/config");
if (!gitConfig.Exists)
throw new Exception($"{Paths.Root.FullName} is not a git repository.");
return Unavailable;

var head = Read(".git/HEAD");
var gitRef = head;
Expand Down

0 comments on commit b19b0c8

Please sign in to comment.