From d589bc5f25bcc191ebe47f01ecb1bb7a769533dc Mon Sep 17 00:00:00 2001 From: Alex Newman Date: Thu, 16 Apr 2026 17:21:49 -0700 Subject: [PATCH] fix(cwd-remap): address PR review feedback - Handle bare repo common-dir (strip trailing .git) instead of an identical-branch ternary - Surface unexpected git stderr while keeping "not a git repository" silent - Explicitly close the sqlite handle in both dry-run and apply paths so WAL checkpoints complete Co-Authored-By: Claude Opus 4.7 (1M context) --- scripts/cwd-remap.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/scripts/cwd-remap.ts b/scripts/cwd-remap.ts index 8eb12683..20a0e328 100644 --- a/scripts/cwd-remap.ts +++ b/scripts/cwd-remap.ts @@ -32,7 +32,13 @@ type Classification = function git(cwd: string, args: string[]): string | null { const r = spawnSync('git', ['-C', cwd, ...args], { encoding: 'utf8' }); - if (r.status !== 0) return null; + if (r.status !== 0) { + const stderr = (r.stderr ?? '').trim(); + if (stderr && !/not a git repository/i.test(stderr)) { + console.error(`git ${args.join(' ')} failed in ${cwd}: ${stderr}`); + } + return null; + } return r.stdout.trim(); } @@ -54,8 +60,11 @@ function classify(cwd: string): Classification { return { kind: 'main', project: leaf }; } - // worktree: common-dir = /.git (or .git for bare) - const parentRepoDir = commonDir.endsWith('/.git') ? dirname(commonDir) : dirname(commonDir); + // worktree: common-dir = /.git (normal) or .git (bare). + // Normal: dirname strips the trailing /.git. Bare: strip the .git suffix. + const parentRepoDir = commonDir.endsWith('/.git') + ? dirname(commonDir) + : commonDir.replace(/\.git$/, ''); const parent = basename(parentRepoDir); return { kind: 'worktree', project: `${parent}/${leaf}`, parent }; } @@ -149,6 +158,7 @@ function main() { if (!APPLY) { console.log('\nDry-run only. Re-run with --apply to perform UPDATEs.'); + db.close(); return; } @@ -169,6 +179,7 @@ function main() { tx(); console.log(`\nApplied. sessions=${sessionN} observations=${obsN} session_summaries=${sumN}`); + db.close(); } main();