claude-code / mods /diff /tests /fixtures /scripted /scripted-git-of.ts
SaylorTwift's picture
SaylorTwift HF Staff
Add files using upload-large-folder tool
7f0ec95 verified
Raw
History Blame Contribute Delete
852 Bytes
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 }
}