(cwd: string, limit: number)
| 37 | * Tab-separated to avoid quoting headaches inside commit subjects. |
| 38 | */ |
| 39 | export async function gitLog(cwd: string, limit: number): Promise<GitLogEntry[]> { |
| 40 | const n = Math.max(1, Math.min(limit, 500)); |
| 41 | const { stdout, exitCode, stderr } = await exec( |
| 42 | ['log', `--pretty=format:${LOG_FORMAT}`, `-n`, String(n)], |
| 43 | cwd, |
| 44 | gitOpts(), |
| 45 | ); |
| 46 | if (exitCode !== 0) { |
| 47 | throw new Error(`git log exited ${exitCode}: ${stderr.slice(0, 200)}`); |
| 48 | } |
| 49 | const lines = stdout.split('\n').filter((l) => l.length > 0); |
| 50 | return lines.map((line) => { |
| 51 | const parts = line.split('\t'); |
| 52 | return { |
| 53 | hash: parts[0] ?? '', |
| 54 | relTime: parts[1] ?? '', |
| 55 | authorTime: parts[2] ?? '', |
| 56 | subject: parts.slice(3).join('\t'), |
| 57 | }; |
| 58 | }); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Best-effort branch + working-tree status. `branch --show-current` returns |
no test coverage detected