{"version":3,"file":"product-git.d.ts","sourceRoot":"","sources":["../src/product-git.ts"],"names":[],"mappings":"AAsBA;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAc9G","sourcesContent":["import { execFileSync } from \"node:child_process\";\nimport { existsSync, writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\nconst PRODUCT_GITIGNORE = `node_modules/\ndist/\nSTOP\n`;\n\nfunction git(workdir: string, args: string[]): string {\n\treturn execFileSync(\"git\", [\"-C\", workdir, ...args], { encoding: \"utf8\" }).trim();\n}\n\nfunction ensureRepo(workdir: string): void {\n\tif (!existsSync(join(workdir, \".git\"))) {\n\t\tgit(workdir, [\"init\", \"--quiet\"]);\n\t\tgit(workdir, [\"config\", \"user.name\", \"pi-agora\"]);\n\t\tgit(workdir, [\"config\", \"user.email\", \"pi-agora@local\"]);\n\t\twriteFileSync(join(workdir, \".gitignore\"), PRODUCT_GITIGNORE);\n\t}\n}\n\n/**\n * Snapshot the product repository after an attempt. For product-at-root\n * projects this gives the product its own git history: one commit per\n * attempt, message recording the task, attempt number, and outcome.\n */\nexport function snapshotAttempt(workdir: string, task: string, attempt: number, passed: boolean): string | null {\n\ttry {\n\t\tensureRepo(workdir);\n\t\tgit(workdir, [\"add\", \"-A\"]);\n\t\tconst status = git(workdir, [\"status\", \"--porcelain\"]);\n\t\tif (status.length === 0) {\n\t\t\treturn null;\n\t\t}\n\t\tconst outcome = passed ? \"pass\" : \"fail\";\n\t\tgit(workdir, [\"commit\", \"--quiet\", \"-m\", `task ${task} attempt ${attempt}: ${outcome}`]);\n\t\treturn git(workdir, [\"rev-parse\", \"--short\", \"HEAD\"]);\n\t} catch {\n\t\treturn null;\n\t}\n}\n"]}