Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/opencode/src/project/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,14 @@ const layer = Layer.effect(

if (flags.experimentalIconDiscovery) yield* discover(existing).pipe(Effect.ignore, Effect.forkIn(scope))

// Update worktree to the freshly resolved path when the stored path no
// longer exists on disk (project was moved or renamed). Otherwise keep
// the existing value so linked-worktree accumulation is preserved.
const staleWorktree =
projectID !== ProjectV2.ID.global && !(yield* fs.existsSafe(existing.worktree))
const result: Info = {
...existing,
worktree: projectID === ProjectV2.ID.global ? worktree : existing.worktree,
worktree: projectID === ProjectV2.ID.global || staleWorktree ? worktree : existing.worktree,
vcs: data.vcs?.type ?? fakeVcs,
time: { ...existing.time, updated: Date.now() },
}
Expand Down
22 changes: 22 additions & 0 deletions packages/opencode/test/project/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,28 @@ describe("Project.fromDirectory with worktrees", () => {
expect(result.project.sandboxes).not.toContain(tmp)
}),
)

it.live("updates worktree when project directory is moved", () =>
Effect.gen(function* () {
const project = yield* Project.Service
const tmp = yield* tmpdirScoped({ git: true })

const original = yield* project.fromDirectory(tmp)
expect(original.project.worktree).toBe(tmp)

const moved = tmp + "-moved"
yield* Effect.addFinalizer(() =>
Effect.promise(() => $`rm -rf ${moved}`.quiet().nothrow()).pipe(Effect.ignore),
)
yield* Effect.promise(() => $`mv ${tmp} ${moved}`.quiet())

const result = yield* project.fromDirectory(moved)

expect(result.project.id).toBe(original.project.id)
expect(result.project.worktree).toBe(moved)
expect(result.project.sandboxes).not.toContain(tmp)
}),
)
})

describe("Project.discover", () => {
Expand Down
Loading