fix(core): update stale project worktree when directory is moved - #38682
fix(core): update stale project worktree when directory is moved#38682cyrasafia 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 issues with moved/stale project paths: Potentially Related PRs:
These PRs are working on overlapping concerns around project relocation and stale paths. PR #38584 appears to be the most directly related, as it specifically focuses on recovering projects moved to new paths. You may want to check if there's any overlap in approach or if these should be coordinated. |
|
Closing in favor of #39056 (same change, head branch renamed to |
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