fix(vscode): select Git roots with platform-aware paths - #543
Conversation
|
🔍 OpenCodeReview found 1 issue(s) in this PR.
|
| const exact = roots.find((r) => r === workspacePath); | ||
| if (exact) return exact; | ||
| const candidates = roots.map((root) => { | ||
| const pathApi = /^[a-z]:[\\/]/i.test(root) || root.includes('\\') ? path.win32 : path.posix; |
There was a problem hiding this comment.
The path API detection heuristic only examines root but not workspacePath. If root and workspacePath use different path conventions (e.g., root uses forward slashes from Git output while workspacePath uses OS-native backslashes on Windows), the selected pathApi may compute relative() incorrectly.
Consider also checking workspacePath in the heuristic, or simply using the platform-native path module directly since VSCode extensions run on the host OS and both paths should follow the same OS convention:
const pathApi = process.platform === 'win32' ? path.win32 : path.posix;Or even simpler, just use path.relative() / path.isAbsolute() without selecting a sub-module, since Node's path module already auto-detects the platform.
There was a problem hiding this comment.
Good catch. Updated the heuristic to inspect both root and workspacePath, and added a regression test covering a forward-slash UNC root with a native Windows workspace path. The targeted suite now passes 30/30.
Description
The VS Code extension selects the repository associated with the first workspace folder.
pickRepoRootpreviously compared paths using raw string equality and a/-only prefix check.On Windows, VS Code repository paths normally use
\. When a repository subdirectory is opened as the workspace, the ancestor check therefore fails and the extension falls back to the first repository returned by the Git extension, which may be an unrelated or nested repository.This change uses Node's platform-aware POSIX/Windows path utilities to:
The change is limited to repository selection and its focused regression tests.
Type of Change
How Has This Been Tested?
corepack yarn test --runInBand src/extension/services/__tests__/gitMap.test.ts- 30 tests passedcorepack yarn lintcorepack yarn compileChecklist