static void GitGetFiles(string wcRoot, GitStatusSet statusSet) { string git = Git.FindGit(); if (git == null) { return; } ProcessRunner runner = new ProcessRunner(); runner.WorkingDirectory = wcRoot; runner.LogStandardOutputAndError = false; runner.OutputLineReceived += delegate(object sender, LineReceivedEventArgs e) { if (!string.IsNullOrEmpty(e.Line)) { statusSet.AddEntry(e.Line, GitStatus.OK); } }; string command = "ls-files"; bool hasErrors = false; runner.ErrorLineReceived += delegate(object sender, LineReceivedEventArgs e) { if (!hasErrors) { hasErrors = true; GitMessageView.AppendLine(runner.WorkingDirectory + "> git " + command); } GitMessageView.AppendLine(e.Line); }; runner.Start(git, command); runner.WaitForExit(); }
public static void RunGit(string workingDir, string arguments, Action <int> finished) { GitMessageView.AppendLine(workingDir + "> git " + arguments); string git = FindGit(); if (git == null) { GitMessageView.AppendLine("Could not find git.exe"); return; } ProcessRunner runner = new ProcessRunner(); runner.WorkingDirectory = workingDir; runner.LogStandardOutputAndError = false; runner.OutputLineReceived += (sender, e) => GitMessageView.AppendLine(e.Line); runner.ErrorLineReceived += (sender, e) => GitMessageView.AppendLine(e.Line); runner.ProcessExited += delegate { GitMessageView.AppendLine("Done. (exit code " + runner.ExitCode + ")"); if (finished != null) { finished(runner.ExitCode); } }; runner.Start(git, arguments); }
static async Task DisplayErrorStreamAsync(ProcessRunner runner, MessageViewCategory category) { using (var reader = runner.OpenStandardErrorReader()) { bool hasErrors = false; string line; while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null) { if (!hasErrors) { hasErrors = true; GitMessageView.AppendLine(runner.WorkingDirectory + "> " + runner.CommandLine); } GitMessageView.AppendLine(line); } } }
static void GitGetStatus(string wcRoot, GitStatusSet statusSet) { string git = Git.FindGit(); if (git == null) { return; } string command = "status --porcelain --untracked-files=no"; bool hasErrors = false; ProcessRunner runner = new ProcessRunner(); runner.WorkingDirectory = wcRoot; runner.LogStandardOutputAndError = false; runner.OutputLineReceived += delegate(object sender, LineReceivedEventArgs e) { if (!string.IsNullOrEmpty(e.Line)) { Match m = statusParseRegex.Match(e.Line); if (m.Success) { statusSet.AddEntry(m.Groups[2].Value, StatusFromText(m.Groups[1].Value)); } else { if (!hasErrors) { // in front of first output line, print the command line we invoked hasErrors = true; GitMessageView.AppendLine(runner.WorkingDirectory + "> git " + command); } GitMessageView.AppendLine("unknown output: " + e.Line); } } }; runner.ErrorLineReceived += delegate(object sender, LineReceivedEventArgs e) { if (!hasErrors) { hasErrors = true; GitMessageView.AppendLine(runner.WorkingDirectory + "> git " + command); } GitMessageView.AppendLine(e.Line); }; runner.Start(git, command); runner.WaitForExit(); }
static void GitGetStatus(string wcRoot, GitStatusSet statusSet) { string git = Git.FindGit(); if (git == null) { return; } ProcessRunner runner = new ProcessRunner(); runner.WorkingDirectory = DirectoryName.Create(wcRoot); runner.RedirectStandardOutput = true; runner.RedirectStandardError = true; runner.Start(git, "status", "--porcelain", "--untracked-files=no"); // process stderr in background var errorTask = DisplayErrorStreamAsync(runner, GitMessageView.Category); // process stderr on current thread: using (var reader = runner.OpenStandardOutputReader()) { string line; while ((line = reader.ReadLine()) != null) { if (line.Length > 0) { Match m = statusParseRegex.Match(line); if (m.Success) { statusSet.AddEntry(m.Groups[2].Value, StatusFromText(m.Groups[1].Value)); } else { GitMessageView.AppendLine("unknown git status output: " + line); } } } } errorTask.Wait(); }