git: fix MERGE_MSG and SQUASH_MSG path for linked worktrees#309178
Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Open
git: fix MERGE_MSG and SQUASH_MSG path for linked worktrees#309178yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Conversation
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.
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @lszomoruMatched files:
|
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.
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()andgetSquashMessage()inextensions/git/src/git.tsconstruct the path toMERGE_MSG/SQUASH_MSGusingpath.join(repositoryRoot, '.git', ...). In a linked worktree, the.gitentry in the worktree root is a file (not a directory) that redirects to the worktree-specific gitdir. Reading a path through it fails withENOTDIR, so both methods silently returnundefinedand the commit message box stays empty after a merge or squash in a linked worktree.Fix: Use
this.dotGit.pathdirectly — the same gitdir pointer already used bygetHEAD(),revParse(), andgetHEADFS().dotGit.path === repositoryRoot/.git— behaviour unchanged.dotGit.path === .git/worktrees/<name>/— correct location where git placesMERGE_MSGandSQUASH_MSGfor that worktree.Files changed
extensions/git/src/git.ts—getSquashMessage()andgetMergeMessage()