private async Task <ProcessResults> ExecuteCommandLineAsync(GitArgumentsBuilder args, string workingDirectory, bool throwOnFailure = true) { var startInfo = new RemoteProcessStartInfo { FileName = this.gitExePath, Arguments = args.ToString(), WorkingDirectory = workingDirectory ?? await this.fileOps.GetBaseWorkingDirectoryAsync() }; if (this.repository.HasLocalRepository) { this.log.LogDebug("Ensuring local repository path exists..."); await this.fileOps.CreateDirectoryAsync(startInfo.WorkingDirectory).ConfigureAwait(false); } this.log.LogDebug("Working directory: " + startInfo.WorkingDirectory); this.log.LogDebug("Executing: " + startInfo.FileName + " " + args.ToSensitiveString()); using (var process = this.processExecuter.CreateProcess(startInfo)) { var outputLines = new List <string>(); var errorLines = new List <string>(); process.OutputDataReceived += (s, e) => { if (e?.Data != null) { outputLines.Add(e.Data); } }; process.ErrorDataReceived += (s, e) => { if (e?.Data != null) { errorLines.Add(e.Data); } }; process.Start(); await process.WaitAsync(this.cancellationToken).ConfigureAwait(false); if (throwOnFailure && process.ExitCode != 0) { throw new ExecutionFailureException($"git returned error code {process.ExitCode}\n{string.Join("\n", errorLines)}"); } return(new ProcessResults(process.ExitCode ?? -1, outputLines, errorLines)); } }
private async Task <ProcessResults> ExecuteCommandLineAsync(GitArgumentsBuilder args, string workingDirectory) { var startInfo = new RemoteProcessStartInfo { FileName = this.gitExePath, Arguments = args.ToString(), WorkingDirectory = workingDirectory }; this.log.LogDebug("Ensuring local repository path exists..."); await this.fileOps.CreateDirectoryAsync(this.repository.LocalRepositoryPath).ConfigureAwait(false); this.log.LogDebug("Working directory: " + startInfo.WorkingDirectory); this.log.LogDebug("Executing: " + startInfo.FileName + " " + args.ToSensitiveString()); using (var process = this.processExecuter.CreateProcess(startInfo)) { var outputLines = new List <string>(); var errorLines = new List <string>(); process.OutputDataReceived += (s, e) => { if (e?.Data != null) { outputLines.Add(e.Data); } }; process.ErrorDataReceived += (s, e) => { if (e?.Data != null) { errorLines.Add(e.Data); } }; process.Start(); await process.WaitAsync(this.cancellationToken).ConfigureAwait(false); return(new ProcessResults(process.ExitCode ?? -1, outputLines, errorLines)); } }