0

I am running git commands using Process from cmd.exe, everything works fine, now I am trying to rebase a branch and want to know if rebase got successful then want to run the git push command as next step.

Is there any way to know if git rebase got successful without conflict from the response message of Process?

Because when it got successful it gives this response Successfully rebased and updated refs/heads/qa.

I checked this question Is there some kind of 'git rebase --dry-run', which would notify me of conflicts in advance?

The answer says if it is a non-zero response that means it is not successful but rebase does not give response in that 0/1 format, it returns text.

My code is this

ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c git rebase master");
procStartInfo.FileName = "cmd.exe";
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;

Process proc = new Process();
proc.StartInfo = procStartInfo;
proc.Start();

proc.WaitForExit();

// What should I check here to make sure rebase happened without conflicts
var response = await proc.StandardOutput.ReadToEndAsync();
1
  • A command's numeric return value is separate from its output, so I think this question boils down to "how do I get a process's return value in C#".
    – IMSoP
    Commented Aug 30, 2020 at 8:46

1 Answer 1

0

I think you need to check Process.ExitCode property. In most case if there some error, code will be non-zero. I think git isn't a exception.

Not the answer you're looking for? Browse other questions tagged or ask your own question.