/** * Shared git command execution utilities. * * This module provides the canonical `execGitCommand` helper and common * git utilities used across services and routes. All consumers should * import from here rather than defining their own copy. */ /** * Execute git command with array arguments to prevent command injection. * Uses spawnProcess from @automaker/platform for secure, cross-platform execution. * * @param args - Array of git command arguments (e.g., ['worktree', 'add', path]) * @param cwd - Working directory to execute the command in * @param env - Optional additional environment variables to pass to the git process. * These are merged on top of the current process environment. Pass * `{ LC_ALL: 'C' }` to force git to emit English output regardless of the * system locale so that text-based output parsing remains reliable. * @param abortController - Optional AbortController to cancel the git process. * When the controller is aborted the underlying process is sent SIGTERM and * the returned promise rejects with an Error whose message is 'Process aborted'. * @returns Promise resolving to stdout output * @throws Error with stderr/stdout message if command fails. The thrown error * also has `stdout` and `stderr` string properties for structured access. * * @example * ```typescript * // Safe: no injection possible * await execGitCommand(['branch', '-D', branchName], projectPath); * * // Force English output for reliable text parsing: * await execGitCommand(['rebase', '--', 'main'], worktreePath, { LC_ALL: 'C' }); * * // With a process-level timeout: * const controller = new AbortController(); * const timerId = setTimeout(() => controller.abort(), 30_000); * try { * await execGitCommand(['fetch', '--all', '--quiet'], cwd, undefined, controller); * } finally { * clearTimeout(timerId); * } * * // Instead of unsafe: * // await execAsync(`git branch -D ${branchName}`, { cwd }); * ``` */ export declare function execGitCommand(args: string[], cwd: string, env?: Record, abortController?: AbortController): Promise; /** * Get the current branch name for the given worktree. * * This is the canonical implementation shared across services. Services * should import this rather than duplicating the logic locally. * * @param worktreePath - Path to the git worktree * @returns The current branch name (trimmed) */ export declare function getCurrentBranch(worktreePath: string): Promise; /** * Check whether an error message indicates a stale git index lock file. * * Git operations that write to the index (e.g. `git stash push`) will fail * with "could not write index" or "Unable to create ... .lock" when a * `.git/index.lock` file exists from a previously interrupted operation. * * @param errorMessage - The error string from a failed git command * @returns true if the error looks like a stale index lock issue */ export declare function isIndexLockError(errorMessage: string): boolean; /** * Attempt to remove a stale `.git/index.lock` file for the given worktree. * * Uses `git rev-parse --git-dir` to locate the correct `.git` directory, * which works for both regular repositories and linked worktrees. * * @param worktreePath - Path to the git worktree (or main repo) * @returns true if a lock file was found and removed, false otherwise */ export declare function removeStaleIndexLock(worktreePath: string): Promise; /** * Execute a git command with automatic retry when a stale index.lock is detected. * * If the command fails with an error indicating a locked index file, this * helper will attempt to remove the stale `.git/index.lock` and retry the * command exactly once. * * This is particularly useful for `git stash push` which writes to the * index and commonly fails when a previous git operation was interrupted. * * @param args - Array of git command arguments * @param cwd - Working directory to execute the command in * @param env - Optional additional environment variables * @returns Promise resolving to stdout output * @throws The original error if retry also fails, or a non-lock error */ export declare function execGitCommandWithLockRetry(args: string[], cwd: string, env?: Record): Promise; //# sourceMappingURL=git.d.ts.map