Skip to content

Commit 6a845c0

Browse files
fix(server): only replace a plain folder with registered paths that are still linked worktrees
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 401d6da commit 6a845c0

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

‎apps/server/src/storageCleanup.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,7 @@ describe("orphan worktree reports", () => {
12381238
yield* fixture.command(fixture.repo, ["worktree", "add", "-b", "locked", worktree]);
12391239
yield* fixture.command(fixture.repo, ["worktree", "lock", worktree]);
12401240
yield* fixture.fs.rename(worktree, `${replay}/moved`);
1241+
yield* fixture.fs.makeDirectory(worktree);
12411242
yield* fixture.fs.utimes(replay, 1, 1);
12421243
expect((yield* fixture.service.runNow).entries.map((entry) => entry.path)).toEqual([
12431244
replay,

‎apps/server/src/storageCleanup.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,16 @@ const make = Effect.gen(function* () {
460460
registered ??= (yield* Effect.forEach(new Set(projectRoots), (root) =>
461461
git.listWorktreePaths(root).pipe(Effect.orElseSucceed((): string[] => [])),
462462
)).flat();
463-
// Locked registrations outlive their directory, so only replace the folder with real ones.
463+
// Locked registrations outlive their directory, whose path may since hold something else.
464464
return yield* Effect.filter(
465465
registered.filter(
466466
(worktree) => inside(folder, worktree) && !inProject(worktree, managedRoot),
467467
),
468-
(worktree) => fs.exists(worktree).pipe(Effect.orElseSucceed(() => false)),
468+
(worktree) =>
469+
Effect.gen(function* () {
470+
if (pathKey(yield* fs.realPath(worktree)) !== pathKey(worktree)) return false;
471+
return (yield* fs.stat(path.join(worktree, ".git"))).type === "File";
472+
}).pipe(Effect.orElseSucceed(() => false)),
469473
);
470474
});
471475
for (const root of roots) {

0 commit comments

Comments
 (0)