Skip to content

Commit 82b7899

Browse files
committed
Be able to handle detached HEAD for GitConfiguration
1 parent 6c5137a commit 82b7899

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Elastic.Markdown/IO/GitConfiguration.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,17 @@ public static GitConfiguration Create(IFileSystem fileSystem)
2929
if (!gitConfig.Exists)
3030
throw new Exception($"{Paths.Root.FullName} is not a git repository.");
3131

32-
var head = Read(".git/HEAD").Replace("ref: ", string.Empty);
33-
var gitRef = Read(".git/" + head);
32+
var head = Read(".git/HEAD");
33+
var gitRef = head;
3434
var branch = head.Replace("refs/heads/", string.Empty);
35+
//not detached HEAD
36+
if (head.StartsWith("ref:"))
37+
{
38+
head = head.Replace("ref: ", string.Empty);
39+
gitRef = Read(".git/" + head);
40+
}
41+
else
42+
branch = "detached/head";
3543

3644
var ini = new FileIniDataParser();
3745
using var stream = gitConfig.OpenRead();

0 commit comments

Comments
 (0)