diff --git a/packages/coding-agent/src/core/package-manager.ts b/packages/coding-agent/src/core/package-manager.ts index d666c1d4..b1523882 100644 --- a/packages/coding-agent/src/core/package-manager.ts +++ b/packages/coding-agent/src/core/package-manager.ts @@ -259,7 +259,6 @@ export class DefaultPackageManager implements PackageManager { this.cwd = options.cwd; this.agentDir = options.agentDir; this.settingsManager = options.settingsManager; - this.ensureGitIgnoreDirs(); } setProgressCallback(callback: ProgressCallback | undefined): void { @@ -623,6 +622,10 @@ export class DefaultPackageManager implements PackageManager { if (existsSync(targetDir)) { return; } + const gitRoot = this.getGitInstallRoot(scope); + if (gitRoot) { + this.ensureGitIgnore(gitRoot); + } mkdirSync(dirname(targetDir), { recursive: true }); const cloneUrl = source.repo.startsWith("http") ? source.repo : `https://${source.repo}`; await this.runCommand("git", ["clone", cloneUrl, targetDir]); @@ -666,13 +669,6 @@ export class DefaultPackageManager implements PackageManager { } } - private ensureGitIgnoreDirs(): void { - this.ensureGitIgnore(join(this.agentDir, "git")); - this.ensureGitIgnore(join(this.agentDir, "npm")); - this.ensureGitIgnore(join(this.cwd, CONFIG_DIR_NAME, "git")); - this.ensureGitIgnore(join(this.cwd, CONFIG_DIR_NAME, "npm")); - } - private ensureGitIgnore(dir: string): void { if (!existsSync(dir)) { mkdirSync(dir, { recursive: true }); @@ -722,6 +718,16 @@ export class DefaultPackageManager implements PackageManager { return join(this.agentDir, "git", source.host, source.path); } + private getGitInstallRoot(scope: SourceScope): string | undefined { + if (scope === "temporary") { + return undefined; + } + if (scope === "project") { + return join(this.cwd, CONFIG_DIR_NAME, "git"); + } + return join(this.agentDir, "git"); + } + private getTemporaryDir(prefix: string, suffix?: string): string { const hash = createHash("sha256") .update(`${prefix}-${suffix ?? ""}`)