Skip to content

Fix git worktree support#72

Closed
jhoff wants to merge 1 commit intochdsbd:masterfrom
jhoff:fix/worktree-support
Closed

Fix git worktree support#72
jhoff wants to merge 1 commit intochdsbd:masterfrom
jhoff:fix/worktree-support

Conversation

@jhoff
Copy link

@jhoff jhoff commented Mar 10, 2026

Summary

  • Fix absolute gitdir path resolution: Worktrees use absolute paths in their .git file, but path.join(dir, absolutePath) concatenated them into an invalid path. Changed to path.resolve(dir, path) which correctly handles both relative (submodules) and absolute (worktrees) paths.
  • Resolve shared git directory for worktrees: Worktree git directories (.git/worktrees/<name>) don't contain shared resources like refs/heads/, packed-refs, or config. Added resolution of the commondir file that git places in worktree directories to find the shared .git directory, and use it for branch lookups, packed-refs, and remote config reads.

This fixes all commands (Blame on Main, Copy Main, Permalink, etc.) when used from a git worktree.

Test plan

  • Tested manually in a git worktree — "Blame on Main" and other commands now work
  • Tested from the main repo root to verify no regression
  • All existing tests pass
  • Added worktree test case for dir() resolution

Two issues prevented the extension from working in git worktrees:

1. `path.join(dir, absolutePath)` produced a mangled path when the
   worktree's .git file contained an absolute gitdir path. Changed to
   `path.resolve(dir, path)` which handles both relative (submodules)
   and absolute (worktrees) paths correctly.

2. Worktree git directories (.git/worktrees/<name>) don't contain
   shared resources like refs/heads/, packed-refs, or config. Added
   resolution of the `commondir` file to find the shared .git directory,
   and use it for branch lookups, packed-refs, and config reads.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chdsbd
Copy link
Owner

chdsbd commented Mar 15, 2026

I think the way this extension inspects .git/ files is a problem and it'd be better to call the git binary directly.

If I find the time to make that change, git work trees should work too

@chdsbd
Copy link
Owner

chdsbd commented Mar 17, 2026

This is fixed in the latest release 4.0.0 via #75

@chdsbd chdsbd closed this Mar 17, 2026
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