Skip to content

git: fix REBASE_HEAD, MERGE_HEAD and CHERRY_PICK_HEAD paths for linked worktrees#309180

Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c:fix/git-worktree-operation-state-paths
Open

git: fix REBASE_HEAD, MERGE_HEAD and CHERRY_PICK_HEAD paths for linked worktrees#309180
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c:fix/git-worktree-operation-state-paths

Conversation

@yogeshwaran-c
Copy link
Copy Markdown
Contributor

In a linked git worktree (git worktree add), the worktree-specific gitdir files — REBASE_HEAD, MERGE_HEAD, CHERRY_PICK_HEAD, rebase-apply/, rebase-merge/ — live under dotGit.path (.git/worktrees/<name>/), not under the working-tree root's .git entry, which is a plain redirect file.

Three methods in extensions/git/src/repository.ts were building those paths with path.join(this.repository.root, '.git', ...):

Method File
getRebaseCommit() REBASE_HEAD, rebase-apply/, rebase-merge/
isMergeInProgress() MERGE_HEAD
isCherryPickInProgress() CHERRY_PICK_HEAD

Because repository.root/.git is a file (not a directory) in a linked worktree, all fs.exists() calls returned false and fs.readFile threw. As a result VS Code never detected an in-progress rebase, merge, or cherry-pick in a linked worktree: the Source Control view showed no rebase commit, no merge conflict indicators, and no cherry-pick state.

Fix: Use this.repository.dotGit.path in all three methods — the same gitdir pointer already used by getHEADFS(), revParse(), and the DotGitWatcher. For the main worktree, dotGit.path equals <root>/.git/, so behaviour is unchanged there.

Files changed

  • extensions/git/src/repository.ts — getRebaseCommit(), isMergeInProgress(), isCherryPickInProgress()

…d worktrees

In a linked git worktree (created with git worktree add), the
worktree-specific gitdir files (REBASE_HEAD, MERGE_HEAD,
CHERRY_PICK_HEAD, rebase-apply/, rebase-merge/) live under
dotGit.path (.git/worktrees/<name>/), not under the working-tree
root's .git entry, which is a plain file (a gitdir redirect).

The three methods that detect in-progress operations were building
paths with path.join(this.repository.root, '.git', ...):

  getRebaseCommit()     -- REBASE_HEAD, rebase-apply, rebase-merge
  isMergeInProgress()   -- MERGE_HEAD
  isCherryPickInProgress() -- CHERRY_PICK_HEAD

Because repository.root/.git is a file rather than a directory in
a linked worktree, all fs.exists() calls returned false and
fs.readFile failed, so VS Code never detected an in-progress
rebase, merge, or cherry-pick when operating inside a linked
worktree. The Source Control view consequently showed no rebase
commit, no merge indicators, and no cherry-pick state.

Fix all three methods to use this.repository.dotGit.path, which
already points to the worktree-specific gitdir for linked worktrees
and to the .git/ directory for the main worktree — matching the
pattern established by getHEADFS() and revParse().
@vs-code-engineering
Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@lszomoru

Matched files:

  • extensions/git/src/repository.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants