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 / current-branch-of / current-branch-of.ts
21 lines · 492 BRaw
1import Argv from '../../argv'
2import type Types from '../../types'
3
4/**
5 * The checked-out branch's name, or `HEAD` when detached or unreadable.
6 *
7 * @param run runs git
8 * @returns the branch name
9 */
10export async function currentBranchOf(run: Types.GitRun): Promise<string> {
11 const { exitCode, stdout } = await run([
12 Argv.NO_OPTIONAL_LOCKS,
13 'rev-parse',
14 '--abbrev-ref',
15 'HEAD',
16 ])
17
18 const name = stdout.trim()
19
20 return exitCode === 0 && name !== '' ? name : 'HEAD'
21}