-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Description
When a workspace is opened inside a linked git worktree (created with git worktree add), the Source Control panel spins indefinitely. The Git output log shows a repeated warning loop:
[Git][revParse] Unable to read file: ENOENT .git/worktrees/<name>/refs/remotes/origin/<branch>
All individual git CLI commands complete quickly (2–30ms), so the issue is purely in the extension's ref resolution logic.
Root Cause
In extensions/git/src/repository.ts, the revParse helper reads ref files directly from this.dotGit.path before falling back to git rev-parse:
async revParse(ref: string): Promise<string | undefined> {
try {
return (await fs.promises.readFile(path.join(this.dotGit.path, ref), 'utf8')).trim();
} catch (err) {
this.logger.warn(`[Git][revParse] Unable to read file: ${err.message}`);
}
// ... falls back to git rev-parse
}For a linked worktree, this.dotGit.path points to .git/worktrees/<name>/ — the worktree-specific gitdir. Remote refs (e.g. refs/remotes/origin/<branch>) live in the common gitdir (.git/), not in the worktree-specific one.
The dotGit object already has a commonPath field that holds the common gitdir path. It is used correctly elsewhere (e.g. in onDidChangeWorkspaceTrustedFolders), but not in revParse.
Fix
Use this.dotGit.commonPath with fallback to this.dotGit.path:
async revParse(ref: string): Promise<string | undefined> {
try {
const basePath = this.dotGit.commonPath ?? this.dotGit.path;
return (await fs.promises.readFile(path.join(basePath, ref), 'utf8')).trim();
} catch (err) {
this.logger.warn(`[Git][revParse] Unable to read file: ${err.message}`);
}
// ... falls back to git rev-parse
}Steps to Reproduce
- Create a linked worktree:
git worktree add ../my-feature feat/my-branch - Open the worktree folder in VS Code
- Observe Source Control panel loading indefinitely
- Open Output → Git and observe repeated ENOENT warnings for remote ref paths under
.git/worktrees/<name>/refs/remotes/...
Environment
- OS: Linux (WSL2)
- VS Code / VS Code Server version: 1.109.5
- VS Code Server commit:
072586267e68ece9a47aa43f8c108e0dcbf44622 - VS Code Server release date: 2026-02-19
- Reproduced with a standard
git worktree addlinked worktree