Skip to content

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.

TypeScript
852 B
Raw Blame
import type { ProcessRunResult } from 'claude-code'

import type Git from '../../../hooks/git'
import type { ScriptedGit } from './scripted-git.js'
import { UNSCRIPTED } from './unscripted.js'

/**
 * A git answering from a script: the first entry whose pattern the joined
 * argv contains, UNSCRIPTED otherwise; every argv is kept in order.
 *
 * @param script pattern to result
 * @returns the runner and the argvs it saw
 */
export function scriptedGitOf(
  script: Readonly<Record<string, ProcessRunResult>>,
): ScriptedGit {
  const argvs: (readonly string[])[] = []

  const run: Git.GitRun = argv => {
    argvs.push(argv)

    const line = argv.join(' ')

    const scripted = Object.entries(script).find(([pattern]) =>
      line.includes(pattern),
    )

    return Promise.resolve(scripted?.[1] ?? UNSCRIPTED)
  }

  return { run, argvs }
}