( args: string[], path: string, name: string, options?: IGitExecutionOptions )
| 223 | options?: IGitBufferExecutionOptions |
| 224 | ): Promise<IGitBufferResult> |
| 225 | export async function git( |
| 226 | args: string[], |
| 227 | path: string, |
| 228 | name: string, |
| 229 | options?: IGitExecutionOptions |
| 230 | ): Promise<IGitResult> { |
| 231 | const defaultOptions: IGitExecutionOptions = { |
| 232 | successExitCodes: new Set([0]), |
| 233 | expectedErrors: new Set(), |
| 234 | maxBuffer: options?.encoding === 'buffer' ? Infinity : kStringMaxLength, |
| 235 | } |
| 236 | |
| 237 | const opts = { ...defaultOptions, ...options } |
| 238 | |
| 239 | // The combined contents of stdout and stderr with some light processing |
| 240 | // applied to remove redundant lines caused by Git's use of `\r` to "erase" |
| 241 | // the current line while writing progress output. See createTerminalOutput. |
| 242 | // |
| 243 | // Note: The output is capped at a maximum of 256kb and the sole intent of |
| 244 | // this property is to provide "terminal-like" output to the user when a Git |
| 245 | // command fails. |
| 246 | const terminalChunks: string[] = [] |
| 247 | const terminalCapacity = 256 * 1024 |
| 248 | |
| 249 | // Keep at most 256kb of combined stderr and stdout output. This is used |
| 250 | // to provide more context in error messages. |
| 251 | opts.processCallback = process => { |
| 252 | options?.onTerminalOutputAvailable?.(function (cb) { |
| 253 | terminalChunks.forEach(chunk => cb(chunk)) |
| 254 | |
| 255 | process.stdout?.on('data', cb) |
| 256 | process.stderr?.on('data', cb) |
| 257 | |
| 258 | return { |
| 259 | unsubscribe: () => { |
| 260 | process.stdout?.off('data', cb) |
| 261 | process.stderr?.off('data', cb) |
| 262 | }, |
| 263 | } |
| 264 | }) |
| 265 | |
| 266 | const push = (chunk: Buffer | string) => { |
| 267 | pushTerminalChunk(terminalChunks, terminalCapacity, chunk) |
| 268 | } |
| 269 | |
| 270 | process.stdout?.on('data', push) |
| 271 | process.stderr?.on('data', push) |
| 272 | |
| 273 | options?.processCallback?.(process) |
| 274 | } |
| 275 | |
| 276 | return withHooksEnv( |
| 277 | hooksEnv => |
| 278 | withTrampolineEnv( |
| 279 | async env => { |
| 280 | const commandName = `${name}: git ${args.join(' ')}` |
| 281 | |
| 282 | const result = await GitPerf.measure(commandName, () => |
no test coverage detected