Repository navigation
Conversation
Recognize .git files as well as directories and safely stop walking at the filesystem root. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 2ffe5c7a-b92e-45d2-8906-1bfa3f2d99c8
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused diff correctly handles both worktree markers and filesystem-root termination, with no unresolved findings.
0 open findings
What changed in this PR
Fixes test repository-root detection for Git worktrees while preserving regular-checkout behavior and the ML_TEST_DATADIR override.
Changes:
- Recognizes both
.gitfiles and directories. - Safely handles reaching the filesystem root without finding a repository.
| File | Description |
|---|---|
| test/Microsoft.ML.TestFrameworkCommon/TestCommon.cs | Adds worktree detection and null-safe parent traversal. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7803 +/- ##
==========================================
+ Coverage 69.95% 70.00% +0.04%
==========================================
Files 1419 1419
Lines 272603 272763 +160
Branches 27562 27580 +18
==========================================
+ Hits 190698 190942 +244
+ Misses 73718 73647 -71
+ Partials 8187 8174 -13
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
svick
marked this pull request as ready for review
October 15, 2026 15:23
rosebyte
approved these changes
Oct 16, 2026
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.
Problem
When tests run from a Git worktree and ML_TEST_DATADIR is not set, GetRepoRoot() walks up from the test output directory looking for a .git directory. Git worktrees instead have a .git file, so the method skips the worktree root and continues walking. If no ancestor has a .git directory, it reaches the filesystem root, where Directory.GetParent(directory) returns null, and accessing .FullName throws a NullReferenceException.
For tests using BaseTestClass, this happens during its static initialization, before the test body runs. The exception is surfaced as a TypeInitializationException, causing those tests to fail during initialization rather than execute. If an ancestor happens to contain a .git directory, the method instead selects that unrelated repository root and uses the wrong test-data paths. Normal checkouts with a .git directory and runs using the ML_TEST_DATADIR override are unaffected.
Summary
Validation