mirror of
https://github.com/anthropics/claude-code.git
synced 2026-09-14 19:48:39 +08:00
18be13be81
Squash merge of 4 commits
33 lines
852 B
TypeScript
33 lines
852 B
TypeScript
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 }
|
|
}
|