Skip to content

Git: revParse reads ref files from worktree gitdir instead of common gitdir, causing ENOENT loop in linked worktrees #297786

@QuentinAd

Description

@QuentinAd

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

  1. Create a linked worktree: git worktree add ../my-feature feat/my-branch
  2. Open the worktree folder in VS Code
  3. Observe Source Control panel loading indefinitely
  4. 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 add linked worktree

Metadata

Metadata

Assignees

Labels

ai-triagedbugIssue identified by VS Code Team member as probable buggitGIT issuesscmGeneral SCM compound issues

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions