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 / scripted / scripted-git-of.ts
32 lines · 852 BRaw
1import type { ProcessRunResult } from 'claude-code'
2
3import type Git from '../../../hooks/git'
4import type { ScriptedGit } from './scripted-git.js'
5import { UNSCRIPTED } from './unscripted.js'
6
7/**
8 * A git answering from a script: the first entry whose pattern the joined
9 * argv contains, UNSCRIPTED otherwise; every argv is kept in order.
10 *
11 * @param script pattern to result
12 * @returns the runner and the argvs it saw
13 */
14export function scriptedGitOf(
15 script: Readonly<Record<string, ProcessRunResult>>,
16): ScriptedGit {
17 const argvs: (readonly string[])[] = []
18
19 const run: Git.GitRun = argv => {
20 argvs.push(argv)
21
22 const line = argv.join(' ')
23
24 const scripted = Object.entries(script).find(([pattern]) =>
25 line.includes(pattern),
26 )
27
28 return Promise.resolve(scripted?.[1] ?? UNSCRIPTED)
29 }
30
31 return { run, argvs }
32}