spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / diff / hooks / git / probes / missing-base-of / missing-base-of.ts
39 lines · 1013 BRaw
1import Argv from '../../argv'
2import type Types from '../../types'
3
4/**
5 * The verdict for a merge-base that produced nothing: `none` when neither
6 * ref of the default branch exists, else `error`.
7 *
8 * Only a probe that ran and exited non-zero is an authoritative miss; one
9 * that answered 0 or never ran means the merge-base failure may pass.
10 *
11 * @param run runs git
12 * @param defaultBranch the default branch's name
13 * @returns `none` or `error`
14 */
15export async function missingBaseOf(
16 run: Types.GitRun,
17 defaultBranch: string,
18): Promise<Types.BranchBase> {
19 for (const ref of [
20 `refs/remotes/origin/${defaultBranch}`,
21 `refs/heads/${defaultBranch}`,
22 ]) {
23 const { exitCode } = await run([
24 Argv.NO_OPTIONAL_LOCKS,
25 'show-ref',
26 '--verify',
27 '--quiet',
28 ref,
29 ])
30
31 const isPresentOrUnknown = exitCode === 0 || exitCode === -1
32
33 if (isPresentOrUnknown) {
34 return { kind: 'error', reason: 'merge_base_failed' }
35 }
36 }
37
38 return { kind: 'none' }
39}