(
args: string[],
cwd: string,
timeout?: number
)
| 46 | } |
| 47 | |
| 48 | async function runGitCommand( |
| 49 | args: string[], |
| 50 | cwd: string, |
| 51 | timeout?: number |
| 52 | ): Promise<GitCommandResponse> { |
| 53 | try { |
| 54 | const options: ExecFileOptions = { |
| 55 | cwd, |
| 56 | timeout: timeout ?? 10_000 |
| 57 | } |
| 58 | const { stdout, stderr } = await execFileAsync('git', args, options) |
| 59 | return { |
| 60 | success: true, |
| 61 | stdout: stdout ? stdout.toString() : '', |
| 62 | stderr: stderr ? stderr.toString() : '', |
| 63 | exitCode: 0 |
| 64 | } |
| 65 | } catch (error) { |
| 66 | const execError = error as NodeJS.ErrnoException & { |
| 67 | stdout?: string |
| 68 | stderr?: string |
| 69 | code?: number | string |
| 70 | killed?: boolean |
| 71 | } |
| 72 | |
| 73 | if (execError.code === 'ETIMEDOUT' || execError.killed) { |
| 74 | return rpcError('Command timed out', { |
| 75 | stdout: execError.stdout ? execError.stdout.toString() : '', |
| 76 | stderr: execError.stderr ? execError.stderr.toString() : '', |
| 77 | exitCode: typeof execError.code === 'number' ? execError.code : -1 |
| 78 | }) |
| 79 | } |
| 80 | |
| 81 | return rpcError(execError.message || 'Command failed', { |
| 82 | stdout: execError.stdout ? execError.stdout.toString() : '', |
| 83 | stderr: execError.stderr ? execError.stderr.toString() : execError.message || 'Command failed', |
| 84 | exitCode: typeof execError.code === 'number' ? execError.code : 1 |
| 85 | }) |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | export function registerGitHandlers(rpcHandlerManager: RpcHandlerManager, workingDirectory: string): void { |
| 90 | rpcHandlerManager.registerHandler<GitStatusRequest, GitCommandResponse>(RPC_METHODS.GitStatus, async (data) => { |
no test coverage detected