public string StageFiles(IList<GitItemStatus> files, out bool wereErrors)
{
var output = "";
string error = "";
wereErrors = false;
var startInfo = CreateGitStartInfo("update-index --add --stdin");
var processReader = new Lazy<SynchronizedProcessReader>(() => new SynchronizedProcessReader(Process.Start(startInfo)));
foreach (var file in files.Where(file => !file.IsDeleted))
{
UpdateIndex(processReader, file.Name);
}
if (processReader.IsValueCreated)
{
processReader.Value.Process.StandardInput.Close();
processReader.Value.WaitForExit();
wereErrors = processReader.Value.Process.ExitCode != 0;
output = processReader.Value.OutputString(SystemEncoding);
error = processReader.Value.ErrorString(SystemEncoding);
}
startInfo.Arguments = "update-index --remove --stdin";
processReader = new Lazy<SynchronizedProcessReader>(() => new SynchronizedProcessReader(Process.Start(startInfo)));
foreach (var file in files.Where(file => file.IsDeleted))
{
UpdateIndex(processReader, file.Name);
}
if (processReader.IsValueCreated)
{
processReader.Value.Process.StandardInput.Close();
processReader.Value.WaitForExit();
output = output.Combine(Environment.NewLine, processReader.Value.OutputString(SystemEncoding));
error = error.Combine(Environment.NewLine, processReader.Value.ErrorString(SystemEncoding));
wereErrors = wereErrors || processReader.Value.Process.ExitCode != 0;
}
return output.Combine(Environment.NewLine, error);
}