mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 06:04:51 +00:00
fix(coding-agent): prune empty git dirs on remove
This commit is contained in:
parent
9f3eef65f8
commit
ee7d03cf52
1 changed files with 23 additions and 0 deletions
|
|
@ -955,6 +955,29 @@ export class DefaultPackageManager implements PackageManager {
|
||||||
const targetDir = this.getGitInstallPath(source, scope);
|
const targetDir = this.getGitInstallPath(source, scope);
|
||||||
if (!existsSync(targetDir)) return;
|
if (!existsSync(targetDir)) return;
|
||||||
rmSync(targetDir, { recursive: true, force: true });
|
rmSync(targetDir, { recursive: true, force: true });
|
||||||
|
this.pruneEmptyGitParents(targetDir, this.getGitInstallRoot(scope));
|
||||||
|
}
|
||||||
|
|
||||||
|
private pruneEmptyGitParents(targetDir: string, installRoot: string | undefined): void {
|
||||||
|
if (!installRoot) return;
|
||||||
|
const resolvedRoot = resolve(installRoot);
|
||||||
|
let current = dirname(targetDir);
|
||||||
|
while (current.startsWith(resolvedRoot) && current !== resolvedRoot) {
|
||||||
|
if (!existsSync(current)) {
|
||||||
|
current = dirname(current);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const entries = readdirSync(current);
|
||||||
|
if (entries.length > 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
rmSync(current, { recursive: true, force: true });
|
||||||
|
} catch {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
current = dirname(current);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ensureNpmProject(installRoot: string): void {
|
private ensureNpmProject(installRoot: string): void {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue