internal static async Task<string> GetBlobHashAsync(string gitExe, FileName fileName) { if (!File.Exists(fileName)) return null; ProcessRunner runner = new ProcessRunner(); runner.WorkingDirectory = fileName.GetParentDirectory(); runner.RedirectStandardOutput = true; runner.Start(gitExe, "ls-tree", "HEAD", fileName.GetFileName()); using (var reader = runner.OpenStandardOutputReader()) { string firstLine = await reader.ReadLineAsync().ConfigureAwait(false); if (firstLine != null) { string[] parts = firstLine.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length >= 3) { if (parts[2].Length == 40) return parts[2]; } } } return null; }
static void GitGetFiles(string wcRoot, GitStatusSet statusSet) { string git = Git.FindGit(); if (git == null) return; using (ProcessRunner runner = new ProcessRunner()) { runner.WorkingDirectory = DirectoryName.Create(wcRoot); runner.RedirectStandardOutput = true; runner.RedirectStandardError = true; runner.Start(git, "ls-files"); // 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) { statusSet.AddEntry(line, GitStatus.OK); } } } errorTask.Wait(); } }
async Task<int> RunNAnt() { string[] arguments = GetArguments(); runner = new ProcessRunner(); runner.WorkingDirectory = workingDirectory; runner.RedirectStandardOutputAndErrorToSingleStream = true; runner.Start(nantFileName, arguments); AbstractRunNAntCommand.Category.AppendLine(runner.CommandLine); var writer = new NAntMessageViewCategoryTextWriter(AbstractRunNAntCommand.Category); using (TextReader reader = runner.OpenStandardOutputReader()) { await reader.CopyToAsync(writer); } OnNAntStarted(); await runner.WaitForExitAsync(); AbstractRunNAntCommand.Category.AppendLine(StringParser.Parse("${res:XML.MainMenu.ToolMenu.ExternalTools.ExitedWithCode} " + runner.ExitCode)); OnNAntExited(writer.Output, String.Empty, runner.ExitCode); return runner.ExitCode; }
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(); }