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 / merge-base-candidates-of / merge-base-candidates-of.ts
38 lines · 1.1 KBRaw
1import Argv from '../../argv'
2import type Types from '../../types'
3import { isSha } from '../is-sha'
4import type { MergeBaseCandidates } from './merge-base-candidates'
5
6/**
7 * The merge-bases of HEAD with `origin/<default>` and with `<default>`, in
8 * that order, each present only when git printed an object name.
9 *
10 * Also whether any call ran and exited 1: no common ancestor, a stable
11 * state rather than a failure.
12 *
13 * @param run runs git
14 * @param defaultBranch the default branch's name
15 * @returns the candidate object names and the no-ancestor flag
16 */
17export async function mergeBaseCandidatesOf(
18 run: Types.GitRun,
19 defaultBranch: string,
20): Promise<MergeBaseCandidates> {
21 const results = [
22 await run([
23 Argv.NO_OPTIONAL_LOCKS,
24 'merge-base',
25 'HEAD',
26 `origin/${defaultBranch}`,
27 ]),
28 await run([Argv.NO_OPTIONAL_LOCKS, 'merge-base', 'HEAD', defaultBranch]),
29 ]
30
31 return {
32 candidates: results
33 .filter(result => result.exitCode === 0)
34 .map(result => result.stdout.trim())
35 .filter(isSha),
36 hasNoCommonAncestor: results.some(result => result.exitCode === 1),
37 }
38}