import { spawn } from "node:child_process"; export interface GitSpawnResult { readonly code: number; readonly stdout: string; readonly stderr: string; } export const runGit = (args: readonly string[], cwd: string): Promise => { return new Promise((resolve, reject) => { const child = spawn("git", [...args], { cwd, env: process.env, }); const out: Buffer[] = []; const err: Buffer[] = []; child.stdout.on("data", (chunk: Buffer) => { out.push(chunk); }); child.stderr.on("data", (chunk: Buffer) => { err.push(chunk); }); child.on("error", (e) => { reject(e); }); child.on("close", (code) => { resolve({ code: code ?? 1, stdout: Buffer.concat(out).toString("utf8"), stderr: Buffer.concat(err).toString("utf8"), }); }); }); };