Skip to content

Commit b19b0c8

Browse files
authored
Make .git folder optional so tool can be run on any folder (#144)
1 parent 20a4d81 commit b19b0c8

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/Elastic.Markdown/IO/GitConfiguration.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,21 @@ namespace Elastic.Markdown.IO;
1010

1111
public record GitConfiguration
1212
{
13-
[JsonPropertyName("branch")] public required string Branch { get; init; }
14-
[JsonPropertyName("remote")] public required string Remote { get; init; }
15-
[JsonPropertyName("ref")] public required string Ref { get; init; }
13+
private static GitConfiguration Unavailable { get; } = new()
14+
{
15+
Branch = "unavailable",
16+
Remote = "unavailable",
17+
Ref = "unavailable"
18+
};
19+
20+
[JsonPropertyName("branch")]
21+
public required string Branch { get; init; }
22+
23+
[JsonPropertyName("remote")]
24+
public required string Remote { get; init; }
25+
26+
[JsonPropertyName("ref")]
27+
public required string Ref { get; init; }
1628

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

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

3143
var head = Read(".git/HEAD");
3244
var gitRef = head;

0 commit comments

Comments
 (0)