fix(project): use git common dir for project ID cache to prevent worktree session loss#15900
fix(project): use git common dir for project ID cache to prevent worktree session loss#15900michaeldwan wants to merge 1 commit intoanomalyco:devfrom
Conversation
…tree session loss Worktrees resolve .git to a per-worktree file, so caching the project ID there fails silently. Each restart recomputes the ID via rev-list --all, which is unstable for repos with orphan branches (gh-pages, stash roots). This causes sessions to become invisible after restarting opencode in a worktree. - Resolve --show-toplevel and --git-common-dir before reading the cache - Store and read the project ID cache from the shared .git directory - Switch rev-list from --all to HEAD to exclude orphan branches - Set local git config in test fixture for reproducible test runs
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
The following comment was made by an LLM, it may be inaccurate: I found a potentially related PR: #14287 - fix(project): repair split project IDs across worktrees This PR appears to address a similar issue with project IDs being split/different across worktrees. It may be addressing the same root cause (git worktree |
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
What does this PR do?
Fixes a bug where sessions become invisible after restarting opencode in a git worktree. The project ID cache was stored in the per-worktree
.gitpath, which is a file (not a directory) in worktrees — so reads and writes silently failed. Each restart recomputed the ID viarev-list --all, which is unstable for repos with orphan branches (gh-pages, stash roots, subtree merges), producing a different project ID and orphaning all previous sessions.Changes:
--show-topleveland--git-common-dirbefore reading the cache, so the cache is read/written in the shared.gitdirectoryrev-listfrom--alltoHEADto exclude orphan branches from the root commit setType of change
Issue for this PR
Fixes #12726
Fixes #12103
Fixes #13782
Fixes #5638
How did you verify your code works?
tsgo --noEmitpasses (0 errors)bun test test/project/project.test.ts— 18 pass, 0 fail.gitdirChecklist