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) <noreply@anthropic.com>
This commit is contained in:
+14
-3
@@ -32,7 +32,13 @@ type Classification =
|
|||||||
|
|
||||||
function git(cwd: string, args: string[]): string | null {
|
function git(cwd: string, args: string[]): string | null {
|
||||||
const r = spawnSync('git', ['-C', cwd, ...args], { encoding: 'utf8' });
|
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();
|
return r.stdout.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,8 +60,11 @@ function classify(cwd: string): Classification {
|
|||||||
return { kind: 'main', project: leaf };
|
return { kind: 'main', project: leaf };
|
||||||
}
|
}
|
||||||
|
|
||||||
// worktree: common-dir = <parent-repo>/.git (or <parent>.git for bare)
|
// worktree: common-dir = <parent-repo>/.git (normal) or <parent>.git (bare).
|
||||||
const parentRepoDir = commonDir.endsWith('/.git') ? dirname(commonDir) : dirname(commonDir);
|
// 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);
|
const parent = basename(parentRepoDir);
|
||||||
return { kind: 'worktree', project: `${parent}/${leaf}`, parent };
|
return { kind: 'worktree', project: `${parent}/${leaf}`, parent };
|
||||||
}
|
}
|
||||||
@@ -149,6 +158,7 @@ function main() {
|
|||||||
|
|
||||||
if (!APPLY) {
|
if (!APPLY) {
|
||||||
console.log('\nDry-run only. Re-run with --apply to perform UPDATEs.');
|
console.log('\nDry-run only. Re-run with --apply to perform UPDATEs.');
|
||||||
|
db.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,6 +179,7 @@ function main() {
|
|||||||
tx();
|
tx();
|
||||||
|
|
||||||
console.log(`\nApplied. sessions=${sessionN} observations=${obsN} session_summaries=${sumN}`);
|
console.log(`\nApplied. sessions=${sessionN} observations=${obsN} session_summaries=${sumN}`);
|
||||||
|
db.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
|||||||
Reference in New Issue
Block a user