Skip to content

Commit

Permalink
Merge pull request #1151 from dotnet/fix1150
Browse files Browse the repository at this point in the history
Fix exception thrown for repos cloned without tags
  • Loading branch information
AArnott authored Jan 10, 2025
2 parents e6a2ed5 + af89131 commit 54ecc60
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/NerdBank.GitVersioning/ManagedGit/GitRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 54ecc60

Please sign in to comment.