diff --git a/src/NerdBank.GitVersioning/ManagedGit/GitRepository.cs b/src/NerdBank.GitVersioning/ManagedGit/GitRepository.cs index 7d37f715..0cafcf1e 100644 --- a/src/NerdBank.GitVersioning/ManagedGit/GitRepository.cs +++ b/src/NerdBank.GitVersioning/ManagedGit/GitRepository.cs @@ -666,16 +666,19 @@ void HandleCandidate(GitObjectId pointsAt, string tagName, bool isPeeled) // Both tag files and packed-refs might either contain lightweight or annotated tags. // tag files - var tagDir = Path.Combine(this.CommonDirectory, "refs", "tags"); - foreach (var tagFile in Directory.EnumerateFiles(tagDir, "*", SearchOption.AllDirectories)) + string tagDir = Path.Combine(this.CommonDirectory, "refs", "tags"); + if (Directory.Exists(tagDir)) { - var tagObjId = GitObjectId.ParseHex(File.ReadAllBytes(tagFile).AsSpan().Slice(0, 40)); + foreach (string tagFile in Directory.EnumerateFiles(tagDir, "*", SearchOption.AllDirectories)) + { + var tagObjId = GitObjectId.ParseHex(File.ReadAllBytes(tagFile).AsSpan().Slice(0, 40)); - // \ is not legal in git tag names - var tagName = tagFile.Substring(tagDir.Length + 1).Replace('\\', '/'); - var canonical = $"refs/tags/{tagName}"; + // \ is not legal in git tag names + var tagName = tagFile.Substring(tagDir.Length + 1).Replace('\\', '/'); + var canonical = $"refs/tags/{tagName}"; - HandleCandidate(tagObjId, canonical, false); + HandleCandidate(tagObjId, canonical, false); + } } // packed-refs file