I've done a git pull origin develop
with help of System.Diagnosticsc.Process
like this:
var gitProcess = new Process
{
StartInfo = new ProcessStartInfo
{
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
FileName = "git.exe",
Arguments = "pull origin develop",
WorkingDirectory = @"C:\Workspaces\MyRepo",
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
}
};
gitProcess.Start();
string outputString = null;
string errorString = null;
gitProcess.OutputDataReceived += (sender, args) => outputString = string.IsNullOrWhiteSpace(outputString) ? args.Data : $"{outputString}\r\n{args.Data}";
gitProcess.ErrorDataReceived += (sender, args) => errorString = string.IsNullOrWhiteSpace(errorString) ? args.Data : $"{errorString}\r\n{args.Data}";
gitProcess.BeginErrorReadLine();
gitProcess.BeginOutputReadLine();
gitProcess.WaitForExit();
The Result is:
gitProcess.ExitCode = 0
outputString = Already up to date.
errorString = From https://mycompany.visualstudio.com/MyProject/_git/MyRepo * branch develop -> FETCH_HEAD
Now every thing seems okay, but why did the the git.exe put the data into the errorString? It seems like normal information. This makes errorhandling hard. The ExitCode is fine it suggests success.
Any ideas why there is errordata, this happens for several other git - commands in a similar manner.
EXPECTED ANSWER
I don't want to hear about alternatives to do a git-pull in c# that's not my interest. I want to understand the behaviour of the git.exe respectivly the behaviour of System.Diagnostics.Process, basically I want to understand how and why that errordata is produced. Who is responsible for that? Is it the git.exe or the way how System.Diagnostics.Process is doing stuff.
Thank you.