Skip to content

Commit af89131

Browse files
committed
Fix exception thrown for repos cloned without tags
Fixes #1150
1 parent e6a2ed5 commit af89131

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/NerdBank.GitVersioning/ManagedGit/GitRepository.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -666,16 +666,19 @@ void HandleCandidate(GitObjectId pointsAt, string tagName, bool isPeeled)
666666

667667
// Both tag files and packed-refs might either contain lightweight or annotated tags.
668668
// tag files
669-
var tagDir = Path.Combine(this.CommonDirectory, "refs", "tags");
670-
foreach (var tagFile in Directory.EnumerateFiles(tagDir, "*", SearchOption.AllDirectories))
669+
string tagDir = Path.Combine(this.CommonDirectory, "refs", "tags");
670+
if (Directory.Exists(tagDir))
671671
{
672-
var tagObjId = GitObjectId.ParseHex(File.ReadAllBytes(tagFile).AsSpan().Slice(0, 40));
672+
foreach (string tagFile in Directory.EnumerateFiles(tagDir, "*", SearchOption.AllDirectories))
673+
{
674+
var tagObjId = GitObjectId.ParseHex(File.ReadAllBytes(tagFile).AsSpan().Slice(0, 40));
673675

674-
// \ is not legal in git tag names
675-
var tagName = tagFile.Substring(tagDir.Length + 1).Replace('\\', '/');
676-
var canonical = $"refs/tags/{tagName}";
676+
// \ is not legal in git tag names
677+
var tagName = tagFile.Substring(tagDir.Length + 1).Replace('\\', '/');
678+
var canonical = $"refs/tags/{tagName}";
677679

678-
HandleCandidate(tagObjId, canonical, false);
680+
HandleCandidate(tagObjId, canonical, false);
681+
}
679682
}
680683

681684
// packed-refs file

0 commit comments

Comments
 (0)