Skip to content

Handle Relative Git Worktree Paths in Worktree Detection#321368

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-relative-worktree-detection
Draft

Handle Relative Git Worktree Paths in Worktree Detection#321368
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-relative-worktree-detection

Conversation

Copilot AI commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Worktree auto-detection handled absolute gitdir entries but failed when .git/worktrees/*/gitdir contained relative paths (e.g. from git worktree add --relative-paths). This change normalizes both formats so relative-path worktrees are discovered consistently.

  • Path normalization in git worktree parsing

    • Added parseGitWorktreePath(gitdirPath, gitdirContent) in extensions/git/src/git.ts.
    • Resolves relative gitdir entries against the gitdir file directory.
    • Normalizes separators and strips trailing .git (and nested suffix) for stable worktree root paths.
  • Detection flow update

    • Replaced inline string replacement logic in getWorktreesFS() with the new parser.
    • Removes implicit assumption that gitdir content is always absolute and POSIX-shaped.
  • Focused regression coverage

    • Added unit tests in extensions/git/src/test/git.test.ts for:
      • relative gitdir paths
      • absolute gitdir paths
const worktreeGitPath = path.isAbsolute(gitdirContent)
	? gitdirContent
	: path.resolve(path.dirname(gitdirPath), gitdirContent);

return worktreeGitPath.replace(/[\\/]\.git(?:[\\/].*)?$/, '');

Copilot AI requested review from Copilot and removed request for Copilot June 15, 2026 07:52
Co-authored-by: lszomoru <3372902+lszomoru@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 15, 2026 08:00
Copilot AI changed the title [WIP] Fix detection of relative worktrees in VS Code Handle Relative Git Worktree Paths in Worktree Detection Jun 15, 2026
Copilot AI requested a review from lszomoru June 15, 2026 08:01

@Otto-Deviant1904 Otto-Deviant1904 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

3 participants