Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(task-copy): 不排除已失效(prunable)的 worktree 登记

Dashe3fb87bd9c5c
diff --git a/apps/desktop/src/main/task-migration/__tests__/workspace.git-integration.test.ts b/apps/desktop/src/main/task-migration/__tests__/workspace.git-integration.test.ts
index d27b5c6274..8ce6e7373b 100644
--- a/apps/desktop/src/main/task-migration/__tests__/workspace.git-integration.test.ts
+++ b/apps/desktop/src/main/task-migration/__tests__/workspace.git-integration.test.ts
@@ -173,6 +173,14 @@ describe('cross-machine project snapshots', () => {
// Only the registered worktree is skipped; user folders beside it and an unregistered
// folder in a managed container are still project content.
expect(await estimateWorkspace(source, () => {})).toEqual({ fileCount: 3, bytes: 6 });
+ // Deleted outside Git and its path reused for ordinary files: the stale (prunable)
+ // registration must not hide them.
+ const reused = path.join(source, '.cindy-worktrees', 'other-task');
+ await fs.rm(reused, { recursive: true });
+ await fs.mkdir(reused);
+ await fs.writeFile(path.join(reused, 'r'), 'four');
+ expect(await git(source, 'worktree', 'list', '--porcelain')).toContain('prunable');
+ expect(await estimateWorkspace(source, () => {})).toEqual({ fileCount: 4, bytes: 10 });
});
it('keeps same-named folders of a plain directory', async () => {
await fs.mkdir(path.join(source, '.cindy-worktrees'));
diff --git a/apps/desktop/src/main/task-migration/workspace.ts b/apps/desktop/src/main/task-migration/workspace.ts
index 93fc5f175d..ddbf4fe7c2 100644
--- a/apps/desktop/src/main/task-migration/workspace.ts
+++ b/apps/desktop/src/main/task-migration/workspace.ts
@@ -34,8 +34,12 @@ export async function managedWorktreeExclusions(root: string): Promise<string[]>
throw error;
}
const excluded: string[] = [];
- for (const line of listing.split('\n')) {
- if (!line.startsWith('worktree ')) continue;
+ // Porcelain records are separated by blank lines. A `prunable` record is stale: its path
+ // may since hold ordinary files, which must be copied rather than skipped.
+ for (const record of listing.split('\n\n')) {
+ const lines = record.split('\n');
+ const line = lines.find((entry) => entry.startsWith('worktree '));
+ if (!line || lines.some((entry) => entry.startsWith('prunable'))) continue;
// A registered worktree whose directory is gone has nothing to copy or skip.
const worktree = await fs.realpath(line.slice('worktree '.length)).catch(() => null);
const relative = worktree && path.relative(root, worktree);