fix: resolve symlinks in git-common-dir for worktree support#52
Merged
tickernelz merged 1 commit intotickernelz:mainfrom Mar 4, 2026
Merged
Conversation
When using git worktree on macOS (where /tmp is a symlink to /private/tmp), the git-common-dir path returned by git differs between the main repo and worktrees, causing different project tags and preventing memory sharing. This fix uses realpathSync to resolve symlinks, ensuring consistent project identity across all worktrees of the same repository. Fixes tickernelz#51
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.
Problem
When using git worktree on macOS (where
/tmpis a symlink to/private/tmp), thegit-common-dirpath returned by git differs between the main repo and worktrees:.git→ resolved to/tmp/worktree-test/main/.git/private/tmp/worktree-test/main/.git(absolute path)This causes different project tags to be generated, preventing memory sharing between worktrees of the same repository.
Solution
Use
realpathSyncto resolve symlinks in thegetGitCommonDirfunction, ensuring consistent paths regardless of whether git returns a relative or absolute path, or whether the path contains symlinks.Testing
Changes
realpathSyncandexistsSyncimports fromnode:fsgetGitCommonDirto resolve symlinks before returning the pathFixes #51