fix: resolve shared refs from commonPath in linked worktrees#304787
Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: resolve shared refs from commonPath in linked worktrees#304787yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Conversation
In linked worktrees, revParse() only reads ref files from the worktree-specific gitdir (dotGit.path), but shared refs like refs/heads/*, refs/remotes/*, and refs/tags/* live in the common gitdir (dotGit.commonPath). This causes branch detection and other ref-based operations to fail silently and fall back to spawning git rev-parse. When the initial read from the worktree gitdir fails with ENOENT and a commonPath is available, try reading the ref from the common gitdir before falling back to the git CLI. This matches git's own ref resolution order and is consistent with how commonPath is already used elsewhere in the file (getWorktreesFS, getRemotesFS). Fixes microsoft#297786
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.
What kind of change does this PR introduce?
Bug fix
What is the current behavior?
In linked worktrees,
revParse()only reads ref files from the worktree-specific gitdir (this.dotGit.path). However, shared refs likerefs/heads/*,refs/remotes/*, andrefs/tags/*are stored in the common gitdir (this.dotGit.commonPath), not in the per-worktree gitdir.This causes the fast-path file read to always fail with ENOENT for shared refs in linked worktrees, logging a warning and falling back to spawning
git rev-parsevia the CLI. While the fallback produces correct results, it is slower and generates unnecessary warning logs.Closes #297786
What is the new behavior?
When the initial file read from the worktree gitdir fails with ENOENT and
this.dotGit.commonPathis available,revParse()now tries reading the ref from the common gitdir before falling back to thegit rev-parseCLI.This matches git's own ref resolution order:
HEAD,MERGE_HEAD) from$GIT_DIRrefs/heads/*,refs/remotes/*) from$GIT_COMMON_DIRFor non-worktree repositories,
commonPathisundefined, so behavior is unchanged.Additional context
This is consistent with how
commonPathis already used elsewhere in the same file:getWorktreesFS()(line 3004):this.dotGit.commonPath ?? this.dotGit.pathgetRemotesFS()(line 3096):this.dotGit.commonPath ?? this.dotGit.path