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 / tests / fixtures / git-in.ts
27 lines · 841 BRaw
1import type { ProcessRunResult } from 'claude-code'
2
3import { NOT_A_REPOSITORY } from './not-a-repository.js'
4import { REPOSITORY } from './repository.js'
5
6/**
7 * What git answers from a script of outputs by command-line key, REPOSITORY
8 * when none is given.
9 *
10 * An invocation the script does not know fails as git does outside a
11 * repository.
12 *
13 * @param argv the invocation, program first
14 * @param script git's output for each invocation whose line holds the key
15 * @returns git's exit code and output
16 */
17export function gitIn(
18 argv: readonly string[],
19 script: Readonly<Record<string, string>> = REPOSITORY,
20): ProcessRunResult {
21 const line = argv.join(' ')
22 const found = Object.entries(script).find(([key]) => line.includes(key))
23
24 return found
25 ? { exitCode: 0, stdout: found[1], stderr: '' }
26 : NOT_A_REPOSITORY
27}