Skip to content

git: fix MERGE_MSG and SQUASH_MSG path for linked worktrees#309178

Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c:fix/git-worktree-merge-squash-msg
Open

git: fix MERGE_MSG and SQUASH_MSG path for linked worktrees#309178
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c:fix/git-worktree-merge-squash-msg

Conversation

@yogeshwaran-c
Copy link
Copy Markdown
Contributor

When working in a linked git worktree (created with git worktree add), VS Code fails to populate the commit message input box with the merge/squash message.

getMergeMessage() and getSquashMessage() in extensions/git/src/git.ts construct the path to MERGE_MSG / SQUASH_MSG using path.join(repositoryRoot, '.git', ...). In a linked worktree, the .git entry in the worktree root is a file (not a directory) that redirects to the worktree-specific gitdir. Reading a path through it fails with ENOTDIR, so both methods silently return undefined and the commit message box stays empty after a merge or squash in a linked worktree.

Fix: Use this.dotGit.path directly — the same gitdir pointer already used by getHEAD(), revParse(), and getHEADFS().

  • Regular repository: dotGit.path === repositoryRoot/.git — behaviour unchanged.
  • Linked worktree: dotGit.path === .git/worktrees/<name>/ — correct location where git places MERGE_MSG and SQUASH_MSG for that worktree.

Files changed

  • extensions/git/src/git.ts — getSquashMessage() and getMergeMessage()

In linked worktrees, the worktree-specific gitdir (dotGit.path) contains
the MERGE_MSG and SQUASH_MSG files, not the common gitdir. Previously,
getMergeMessage() and getSquashMessage() constructed paths using
`path.join(repositoryRoot, '.git', ...)`, which points to a file (the
.git file redirector) rather than a directory in linked worktrees,
causing fs.readFile to fail and the commit message input box to remain
empty during a merge or squash in a worktree.

Fix both methods to use dotGit.path directly, which is already set to
the worktree-specific gitdir for linked worktrees and the main .git
directory for normal repositories.
@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/git.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