/** * @file Centralized git command runner. Every fleet script that spawns git * goes through here so the spawn source, output encoding, timeout defaults, * and index.lock handling are consistent. The git binary is resolved once via * getGitPath; a GitLockError is thrown when the shared index is locked by * another git process, so a caller can retry or switch to an isolated index * (withIsolatedIndex) rather than fail open. Non-zero exits are NOT thrown: * git uses non-zero for ordinary conditions a caller routes on (no matches, a * dirty tree), so the caller checks .status / .code the same as raw * spawnSync. The index.lock detection is the one deviation, because a lock * error is transient and recoverable, and a silent swallow (the cascade * reporting "clean" when it could not check) is the false-green the * code-first-then-ai rule exists to stop. */ import type { SpawnSyncReturns } from '../process/spawn/types.js'; export declare const GIT_DEFAULT_TIMEOUT_MS = 30000; /** * Error thrown when a git command fails because the shared index is locked by * another git process. A caller can catch GitLockError to retry or switch to * withIsolatedIndex. The cmd + args are carried so a retry loop can log the * exact command that contended. */ export declare class GitLockError extends Error { readonly cmd: string; readonly args: readonly string[]; constructor(cmd: string, args: readonly string[], message: string); } /** * Options shared by the sync and async git runners. Mirrors the subset of * spawn options the fleet git call sites use: cwd, env, timeout, and * stdioString. The sync runner adds input, a sync-only spawn option. Async * spawn has no stdin write in the same sense, so input stays off the shared * bag. */ export interface GitExecOptions { cwd?: string | undefined; env?: NodeJS.ProcessEnv | undefined; timeout?: number | undefined; stdioString?: boolean | undefined; } /** * Options for the sync git runner. Extends GitExecOptions with input, a * sync-only spawn option. */ export interface GitSyncOptions extends GitExecOptions { input?: string | NodeJS.ArrayBufferView | undefined; } /** * The result shape returned by gitSync: the lib spawnSync return with string or * Buffer stdio depending on the stdioString option. A caller narrows with * Buffer.isBuffer(result.stdout) when stdioString is false. */ export type GitSyncResult = SpawnSyncReturns; /** * The result shape returned by gitSpawn: the lib async spawn return with string * or Buffer stdio depending on the stdioString option. */ export interface GitSpawnResult { cmd: string; args: string[] | readonly string[]; code: number; signal: NodeJS.Signals | null; stdout: string | Buffer; stderr: string | Buffer; } /** * Check git stderr for an index.lock contention and throw GitLockError when * found. The cmd + args are carried so a retry loop can log the exact command * that contended. */ export declare function detectLockError(cmd: string, args: readonly string[], stderr: string | Buffer | undefined): void; /** * Run a git command asynchronously with consistent defaults. The git binary is * resolved via getGitPath; cwd defaults to the current working directory; * timeout defaults to GIT_DEFAULT_TIMEOUT_MS; stdioString defaults to true * (string output). A GitLockError is thrown when the shared index is locked. * Non-zero exits are resolved, not rejected: the caller checks .code. * * @example * const { code, stdout } = await gitSpawn(['rev-parse', 'HEAD']) */ export declare function gitSpawn(args: readonly string[], options?: GitExecOptions | undefined): Promise; /** * Run a git command synchronously with consistent defaults. The git binary is * resolved via getGitPath; cwd defaults to the current working directory; * timeout defaults to GIT_DEFAULT_TIMEOUT_MS; stdioString defaults to true * (string output). A GitLockError is thrown when the shared index is locked. * Non-zero exits are returned, not thrown: the caller checks .status. * * @example * const r = gitSync(['status', '--porcelain']) * if (r.status === 0) { ... r.stdout ... } */ export declare function gitSync(args: readonly string[], options?: GitSyncOptions | undefined): GitSyncResult; /** * Convert a stderr value (string or Buffer) to text for substring matching. * * A spawn-level launch failure (e.g. an ENOENT from a missing git binary) * carries no stderr at all — `undefined`, not an empty string or Buffer — so * this returns `''` for that case rather than throwing on a nullish * `.toString()` call. */ export declare function stderrText(stderr: string | Buffer | undefined): string;