Fix git extension not working when repo root is "/" (chroot)#317637
Open
vanklompf wants to merge 5 commits into
Open
Fix git extension not working when repo root is "/" (chroot)#317637vanklompf wants to merge 5 commits into
vanklompf wants to merge 5 commits into
Conversation
The normalizePath() function in the git extension's util.ts would strip the trailing "/" from the root path to get an empty string, which path.normalize() then converts to ".". This broke isDescendant() and pathEquals() for any repository with root path "/", which is common in chroot environments. The fix adds a length > 1 check before stripping trailing separators, preserving root paths like "/" on Linux/macOS (and "C:\" on Windows where normalize restores the separator anyway). Fixes microsoft#298003 Co-authored-by: Franek Korta <vanklompf@users.noreply.github.com>
Use dirname() to detect filesystem roots instead of a length > 1 check. This correctly preserves all root paths: "/" on POSIX, "C:\" and UNC roots on Windows, rather than relying on normalize() to restore them. Co-authored-by: Franek Korta <vanklompf@users.noreply.github.com>
Add win32-guarded tests for isDescendant, pathEquals, and relativePath covering C:\ drive roots, ensuring the dirname()-based root detection does not regress on Windows. Co-authored-by: Franek Korta <vanklompf@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes path normalization in the built-in Git extension so that repository roots that are filesystem roots (notably / in chroot environments) are preserved during normalization, restoring correct behavior for descendant checks, path equality, and relative path computation.
Changes:
- Update
normalizePath()to avoid stripping the trailing separator when the input is a filesystem root (detected viapath !== dirname(path)). - Add unit tests covering root-path behavior for
isDescendant,pathEquals, andrelativePathon both POSIX and Windows drive roots.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
extensions/git/src/util.ts |
Prevents root paths (e.g. /, C:\) from being normalized into incorrect non-root values by avoiding trailing-separator stripping for roots. |
extensions/git/src/test/git.test.ts |
Adds unit coverage for root-path scenarios to ensure correct behavior in chroot and drive-root cases. |
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @lszomoruMatched files:
|
Author
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 working in a chroot environment where the project/repository root is
/, the git extension fails silently — discard changes, diffs, and staging all break.Root cause: The
normalizePath()function inextensions/git/src/util.tsunconditionally strips trailing path separators. When the path is/(root), stripping the trailing/produces an empty string"", whichpath.normalize("")converts to".". This breaks bothisDescendant()andpathEquals():As a result, the git extension cannot match files to their repository when the repository root is
/.Fix
The fix now uses path !== dirname(path). This correctly detects all filesystem roots.
This is consistent with how the core VS Code
removeTrailingPathSeparator()insrc/vs/base/common/extpath.tsalready handles this case.Testing
isDescendant,pathEquals, andrelativePathcovering the root path/scenario.