public StdOutputLineWalker(Process p, string?stdinText, int[]?expectedResults) { if (p is null) { throw new ArgumentNullException(nameof(p)); } _rcv = new ErrorReceiver(p); _p = p; _stdinText = stdinText; _expectedResults = expectedResults; _reader = p.StandardOutput; }
protected internal async ValueTask <Bucket> RunGitCommandBucketAsync(string command, IEnumerable <string>?args, string?stdinText = null, int[]?expectedResults = null) { ProcessStartInfo startInfo = new ProcessStartInfo(GitConfiguration.GitProgramPath) { UseShellExecute = false, CreateNoWindow = true, WorkingDirectory = this.FullPath, RedirectStandardInput = true, RedirectStandardError = true, RedirectStandardOutput = true, }; IEnumerable <string> allArgs = new string[] { command }.Concat(args ?? Array.Empty <string>()); #if NETFRAMEWORK startInfo.Arguments = string.Join(" ", allArgs.Select(x => EscapeGitCommandlineArgument(x))); FixConsoleUTF8BOMEncoding(); #else foreach (var v in allArgs) { startInfo.ArgumentList.Add(v); } #endif using var p = Process.Start(startInfo); if (p == null) { throw new GitExecCommandException($"Unable to start 'git {command}' operation"); } var rcv = new ErrorReceiver(p); if (!string.IsNullOrEmpty(stdinText)) { await p.StandardInput.WriteAsync(stdinText).ConfigureAwait(false); } p.StandardInput.Close(); return(p.StandardOutput.BaseStream.AsBucket().AtEof(async() => { await Task.WhenAll(p.WaitForExitAsync(), rcv.DoneTask).ConfigureAwait(false); if (expectedResults != null ? !(expectedResults.Length == 0 || expectedResults.Contains(p.ExitCode)) : p.ExitCode != 0) { throw new GitExecCommandException($"Unexpected error {p.ExitCode} from 'git {command}' operation in '{FullPath}'"); } })); }