git: route linked-worktree files to the correct window - #335634
Open
Mr Majumder (D-Majumder) wants to merge 2 commits into
Open
git: route linked-worktree files to the correct window#335634Mr Majumder (D-Majumder) wants to merge 2 commits into
Mr Majumder (D-Majumder) wants to merge 2 commits into
Conversation
…, microsoft#299540) findWindowOnFile matched windows by simple parent-folder containment of a file's path. Git linked worktrees store their private per-worktree files (COMMIT_EDITMSG, rebase-merge/git-rebase-todo, etc.) inside the *main* worktree's .git/worktrees/<name> directory rather than under the linked worktree's own folder, so such files always resolved to the main worktree's window instead of the correct linked-worktree window (e.g. when core.editor is "code --wait"). Add findWindowOnGitWorktreeFile, checked before the existing parent-folder matching: it recognizes .git/worktrees/<name> metadata paths and, by resolving each candidate window's own .git pointer file, matches against the full worktree directory path rather than just the trailing <name> segment, so two unrelated repositories that happen to share a worktree name cannot be confused with one another. Ordinary repositories (.git as a directory) and non-worktree files are unaffected and never trigger the new filesystem read. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TzTiUkg9L2rajTg9eb9zxY
Copilot started reviewing on behalf of
Mr Majumder (D-Majumder)
September 11, 2026 07:23
View session
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Linked worktrees opened within multi-root workspaces are ignored and can still route to the wrong window.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Routes Git linked-worktree metadata files to the window containing the corresponding worktree.
Changes:
- Resolves worktrees through their
.gitpointer files. - Adds regression coverage for routing and repository-name collisions.
File summaries
| File | Description |
|---|---|
windowsFinder.ts |
Adds linked-worktree-aware window selection. |
windowsFinder.test.ts |
Adds filesystem-backed routing tests. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+54
to
+55
| const openedFolder = isSingleFolderWorkspaceIdentifier(window.openedWorkspace) ? window.openedWorkspace.uri : undefined; | ||
| if (!openedFolder || openedFolder.scheme !== Schemas.file) { |
Author
|
@microsoft-github-policy-service agree |
findWindowOnGitWorktreeFile only checked single-folder windows when matching a linked worktree's .git pointer file, so a linked worktree opened as one folder of a multi-root workspace was skipped and could still route to the main worktree's window. Resolve IWorkspaceIdentifier folders through the existing localWorkspaceResolver, matching how the surrounding findWindowOnFile fallback logic already handles multi-root workspaces. Unresolved workspaces are skipped gracefully, as before. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TzTiUkg9L2rajTg9eb9zxY
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.
Fixes #290708
Related to #299540 (same underlying root cause, reported independently).
Bug
When multiple VS Code windows are open, one per Git worktree, operations that write into a linked worktree's private Git metadata — such as
git commitwithcore.editorset tocode --wait, or a rebase — can open the editor in the main worktree's window instead of the linked worktree's window.Root cause
findWindowOnFilenormally selects a window by checking whether the target file is a child of an open window's folder. Git linked worktrees store their private per-worktree files under the main worktree's.git/worktrees/<name>/directory, so those files appear to belong to the main worktree rather than the linked worktree.Fix
Recognize Git linked-worktree metadata paths before the existing parent-folder matching and resolve the linked worktree through its
.gitpointer file. The comparison uses the full resolved worktree metadata path so unrelated repositories with the same worktree name cannot be confused.Ordinary repositories, normal files, non-file URIs, and existing fallback behavior remain unchanged.
Tests
Added regression coverage for:
Validation
git diff --check— passedThe repository's actual
windowsFinder.test.tssuite was not run locally because this environment has Node v22.23.1, while VS Code requires Node v24.18.0. No compatible Node version manager or vendored Node binary was available, so no dependency installation was attempted. CI/maintainer validation is therefore requested for the full test suite.