diff --git a/src/services/git.ts b/src/services/git.ts index 79eb5fe..80af1ff 100644 --- a/src/services/git.ts +++ b/src/services/git.ts @@ -21,7 +21,8 @@ function withRepo(fn: (dir: string, env: NodeJS.ProcessEnv) => T): T { execSync(`git -C ${dir} config user.email "manager@lunarfront.tech"`, { env }); execSync(`git -C ${dir} config user.name "lunarfront-manager"`, { env }); const result = fn(dir, env); - execSync(`git -C ${dir} push origin main`, { env, stdio: "pipe" }); + const unpushed = execSync(`git -C ${dir} log origin/main..HEAD --oneline`, { env }).toString().trim(); + if (unpushed) execSync(`git -C ${dir} push origin main`, { env, stdio: "pipe" }); return result; } finally { rmSync(dir, { recursive: true, force: true }); @@ -40,7 +41,10 @@ export function addCustomerChart(slug: string, appVersion: string) { export function removeCustomerChart(slug: string) { withRepo((dir, env) => { - rmSync(join(dir, "customers", `${slug}.yaml`), { force: true }); + const filePath = join(dir, "customers", `${slug}.yaml`); + const tracked = execSync(`git -C ${dir} ls-files customers/${slug}.yaml`, { env }).toString().trim(); + if (!tracked) return; + rmSync(filePath, { force: true }); execSync(`git -C ${dir} add customers/${slug}.yaml`, { env }); execSync(`git -C ${dir} commit -m "chore: deprovision customer ${slug}"`, { env }); });