| 98 | * For tools that want a clean exception flow rather than checking exitCode. |
| 99 | */ |
| 100 | export async function gitOrThrow(args: string[], opts: GitOptions): Promise<string> { |
| 101 | const r = await git(args, opts); |
| 102 | if (r.exitCode !== 0) { |
| 103 | const msg = (r.stderr || r.stdout || `git ${args.join(' ')} exited ${r.exitCode}`).trim(); |
| 104 | throw new Error(msg); |
| 105 | } |
| 106 | return r.stdout; |
| 107 | } |
| 108 | |
| 109 | /** Quick check: is this directory inside a git repo? */ |
| 110 | export async function isGitRepo(cwd: string, signal?: AbortSignal): Promise<boolean> { |