fix: handle annotated tags in GetTags() to prevent NullReferenceException#7
Open
NormandErwan wants to merge 7 commits into
Open
fix: handle annotated tags in GetTags() to prevent NullReferenceException#7NormandErwan wants to merge 7 commits into
NormandErwan wants to merge 7 commits into
Conversation
GetTags() casts tag.Target directly to Commit. For annotated tags, tag.Target is a TagAnnotation, so the cast yields null and the null-forgiving ! operator causes a NullReferenceException at runtime. UnityCsReference uses annotated tags, making this crash systematic. https://claude.ai/code/session_01WNaTJnpDwNjqyfL1uhYqJ4
For annotated tags, tag.Target is a TagAnnotation (not a Commit), so casting it directly to Commit returned null and the null-forgiving ! caused a NullReferenceException. Extracted GetTaggedCommit() which traverses the annotation chain until it reaches the underlying Commit, handling both lightweight and annotated tags (including nested ones). Fixes the crash that prevented --repositoryTags auto-discovery from working with UnityCsReference, which exclusively uses annotated tags. https://claude.ai/code/session_01WNaTJnpDwNjqyfL1uhYqJ4
RepositoryExtensionsTests creates Repository instances directly, requiring LibGit2Sharp types and its native binaries to be explicitly present in the test output. Relying on the transitive reference through UnityXrefMaps.csproj is not sufficient for native library resolution. https://claude.ai/code/session_01WNaTJnpDwNjqyfL1uhYqJ4
Commands.Stage with the "*" glob pathspec may not reliably match untracked files in LibGit2Sharp; using the explicit filename avoids a potential empty index that would cause Commit() to throw. https://claude.ai/code/session_01WNaTJnpDwNjqyfL1uhYqJ4
Replace Commands.Stage with Index.Add/Write (lower-level, unambiguous) and use commit.Sha (string objectish) instead of passing the Commit object directly to Tags.Add, removing any overload resolution ambiguity. Also use var to avoid shadowing the Commit type with a same-named variable. https://claude.ai/code/session_01WNaTJnpDwNjqyfL1uhYqJ4
Adds three tests alongside the existing annotated-tag regression test: - GetTags_WithLightweightTag_ReturnsTagName: tag.Target is Commit directly, while-loop in GetTaggedCommit never iterates. - GetTags_WithNestedAnnotatedTag_ReturnsTagName: outer TagAnnotation → inner TagAnnotation → Commit, loop iterates twice (multi-level peeling). - GetTags_WithTagNotPointingToCommit_IsStillReturned: tag points to a blob, GetTaggedCommit returns null, tag is still present sorted last. https://claude.ai/code/session_01WNaTJnpDwNjqyfL1uhYqJ4
Three of the four tests shared the same 5-line commit-creation block (signature, write file, stage, write index, commit). Extracted into a private CreateCommit() helper returning the commit and signature tuple. https://claude.ai/code/session_01WNaTJnpDwNjqyfL1uhYqJ4
aef2ec5 to
84a565c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GetTags()crashed withNullReferenceExceptionwhen the repository contained annotated tags (created withgit tag -a). It casttag.Targetdirectly toCommitusing the null-forgiving operator!, but for annotated tagstag.Targetis aTagAnnotation, not aCommit, so the cast silently returnednulland the subsequent.Author.Whenaccess threw.UnityCsReferencerepository uses annotated tags exclusively, soGetLatestVersions()— and therefore the entire tool — always crashed at startup.GetTaggedCommit(Tag), which peels through theTagAnnotationchain with awhileloop until it reaches the underlyingCommit(or returnsnullfor non-commit targets, falling back toDateTimeOffset.MinValuefor sorting).Test plan
GetTags_WithAnnotatedTag_ReturnsTagName— regression test: annotated tag must appear in results without throwingGetTags_WithLightweightTag_ReturnsTagName— lightweight tag (tag.TargetisCommitdirectly,while-loop never iterates)GetTags_WithNestedAnnotatedTag_ReturnsTagName— outerTagAnnotation→ innerTagAnnotation→Commit(loop iterates twice, multi-level peeling)GetTags_WithTagNotPointingToCommit_IsStillReturned— tag pointing to a blob;GetTaggedCommitreturnsnull, tag still appears in output sorted lasthttps://claude.ai/code/session_01WNaTJnpDwNjqyfL1uhYqJ4