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 / is-unborn-head.ts
24 lines · 625 BRaw
1import Argv from '../argv'
2import type Types from '../types'
3
4/**
5 * Whether HEAD is unborn (a repository before its first commit): only a
6 * `rev-parse --verify HEAD` that ran and exited exactly 1 says so.
7 *
8 * A fatal repository error (128) or a killed probe proves nothing, as for
9 * the built-in panel's no-commits probe.
10 *
11 * @param run runs git
12 * @returns whether the probe exited 1
13 */
14export async function isUnbornHead(run: Types.GitRun): Promise<boolean> {
15 const { exitCode } = await run([
16 Argv.NO_OPTIONAL_LOCKS,
17 'rev-parse',
18 '--verify',
19 '--quiet',
20 'HEAD',
21 ])
22
23 return exitCode === 1
24}