* Determine the best ref to diff against for a PR-like diff. * Priority: * 1. CLAUDE_CODE_BASE_REF env var (set externally, e.g. by CCR managed containers) * 2. Merge base with the default branch (best guess) * 3. HEAD (fallback if merge-base fails)
(gitRoot: string)
| 488 | * 3. HEAD (fallback if merge-base fails) |
| 489 | */ |
| 490 | async function getDiffRef(gitRoot: string): Promise<string> { |
| 491 | const baseBranch = |
| 492 | process.env.CLAUDE_CODE_BASE_REF || (await getDefaultBranch()) |
| 493 | const { stdout, code } = await execFileNoThrowWithCwd( |
| 494 | gitExe(), |
| 495 | ['--no-optional-locks', 'merge-base', 'HEAD', baseBranch], |
| 496 | { cwd: gitRoot, timeout: SINGLE_FILE_DIFF_TIMEOUT_MS }, |
| 497 | ) |
| 498 | if (code === 0 && stdout.trim()) { |
| 499 | return stdout.trim() |
| 500 | } |
| 501 | return 'HEAD' |
| 502 | } |
| 503 | |
| 504 | async function generateSyntheticDiff( |
| 505 | gitPath: string, |
no test coverage detected