Skip to content

fix: resolve symlinks in git-common-dir for worktree support#52

Merged
tickernelz merged 1 commit intotickernelz:mainfrom
newbeelee048:fix/git-worktree-symlink
Mar 4, 2026
Merged

fix: resolve symlinks in git-common-dir for worktree support#52
tickernelz merged 1 commit intotickernelz:mainfrom
newbeelee048:fix/git-worktree-symlink

Conversation

@newbeelee048
Copy link

Problem

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:

  • Main repo: returns .git → resolved to /tmp/worktree-test/main/.git
  • Feature worktree: returns /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 realpathSync to resolve symlinks in the getGitCommonDir function, ensuring consistent paths regardless of whether git returns a relative or absolute path, or whether the path contains symlinks.

Testing

# Before fix
Main repo tag:      opencode_project_34e2192f1926e08d
Feature worktree:   opencode_project_834e8685c25e514b
# Different tags → memories not shared ❌

# After fix
Main repo tag:      opencode_project_834e8685c25e514b
Feature worktree:   opencode_project_834e8685c25e514b
# Same tags → memories shared ✅

Changes

  • Added realpathSync and existsSync imports from node:fs
  • Modified getGitCommonDir to resolve symlinks before returning the path

Fixes #51

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
@tickernelz tickernelz merged commit ec96265 into tickernelz:main Mar 4, 2026
1 check passed
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.

Feature: Support git worktree memory sharing via git_repo_url

3 participants