fix(core): update stale project worktree when directory is moved - #39056
fix(core): update stale project worktree when directory is moved#39056cyrasafia wants to merge 2 commits into
Conversation
fromDirectory now checks whether the stored worktree path still exists on disk before reusing it. When the path is gone (project moved or renamed) the freshly resolved path takes over, while preserving the existing value for linked-worktree accumulation.
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found several related PRs that address similar concerns about handling moved/relocated projects: Potentially Related PRs:
The PR mentions it supersedes #38682 (which was auto-closed). The key difference here is that PR #39056 focuses on updating the stale |
|
Closing in favor of #38584, which was submitted earlier and covers a strict superset of this change. Both PRs fix the same root cause (the stored
#39056 only updates the Thanks for the contribution! |
Issue for this PR
Closes #35240
Related #30697 #30005 #30015 #23248
Type of change
What does this PR do?
When a project directory is moved or renamed on disk,
Project.fromDirectorykept the staleworktreepath in theprojecttable forever. The root cause is that the upsert infromDirectoryunconditionally reusedexisting.worktreefor non-global projects:This meant reopening the project from its new location never updated the stored path, causing the desktop app and TUI to display and navigate to the old (now-dead) path.
Fix: Before reusing the stored
worktree, check whether it still exists on disk viafs.existsSafe. If the path is gone (project was moved/renamed), use the freshly resolved path instead. If the path still exists, the existing value is preserved — this is important for the linked-worktree accumulation behavior verified by the "should accumulate multiple worktrees in sandboxes" test, where opening a second worktree must NOT overwrite the primaryworktree.How did you verify your code works?
mv, reopens from the new path, and assertsworktreeis updated while the project ID stays the same.bun typecheckandbun test test/project/project.test.ts test/project/project-directory.test.ts test/project/migrate-global.test.ts— all 49 tests pass.Screenshots / recordings
N/A — server-side data layer change.
Checklist