public static async Task <GitBashResult> RunAsync(string args, string workingDirectory) { GitBashResult ret = null; await Task.Run(new Action(() => { ret = Run(args, workingDirectory); })); return(ret); }
public static GitBashResult Run(string args, string workingDirectory, bool ignoreWorkingDirectory = false) { Debug.WriteLine(string.Format("{2}>{0} {1}", gitExePath, args, workingDirectory)); if (string.IsNullOrWhiteSpace(gitExePath) || !File.Exists(gitExePath)) { throw new GitException("Git Executable not found"); } if (!Directory.Exists(workingDirectory) && !ignoreWorkingDirectory) { return(new GitBashResult { HasError = true, Error = workingDirectory + " is not a valid folder to run git command " + args }); } GitBashResult result = new GitBashResult(); var pinfo = new ProcessStartInfo(gitExePath) { Arguments = args, CreateNoWindow = true, RedirectStandardError = true, RedirectStandardOutput = true, UseShellExecute = false, WorkingDirectory = workingDirectory, }; if (UseUTF8FileNames) { pinfo.StandardOutputEncoding = Encoding.UTF8; pinfo.StandardErrorEncoding = Encoding.UTF8; } using (var process = Process.Start(pinfo)) { string output = null; Thread thread = new Thread(_ => output = ReadStream(process.StandardOutput)); thread.Start(); var error = ReadStream(process.StandardError); thread.Join(); process.WaitForExit(); result.HasError = process.ExitCode != 0; result.Output = output; result.Error = error; return(result); } }
public static GitBashResult Run(string args, string workingDirectory) { Debug.WriteLine(string.Format("{2}>{0} {1}", "git", args, Thread.CurrentThread.ManagedThreadId)); if (string.IsNullOrWhiteSpace(gitExePath) || !File.Exists(gitExePath)) throw new GitException("Git Executable not found"); if (!Directory.Exists(workingDirectory)) { return new GitBashResult { HasError = true, Error = workingDirectory + " is not a valid folder to run git command " + args }; } GitBashResult result = new GitBashResult(); var pinfo = new ProcessStartInfo(gitExePath) { Arguments = args, CreateNoWindow = true, RedirectStandardError = true, RedirectStandardOutput = true, UseShellExecute = false, WorkingDirectory = workingDirectory, }; if (UseUTF8FileNames) { pinfo.StandardOutputEncoding = Encoding.UTF8; pinfo.StandardErrorEncoding = Encoding.UTF8; } using (var process = Process.Start(pinfo)) { var output = ""; Thread thread = new Thread(_ => output = process.StandardOutput.ReadToEnd()); thread.Start(); var error = process.StandardError.ReadToEnd(); thread.Join(); process.WaitForExit(); result.HasError = process.ExitCode != 0; result.Output = output; result.Error = error; return result; } }
public static GitBashResult Run(string args, string workingDirectory) { if (string.IsNullOrWhiteSpace(gitExePath) || !File.Exists(gitExePath)) { throw new Exception("Git Executable not found"); } GitBashResult result = new GitBashResult(); //Debug.WriteLine(string.Format("{2}>{0} {1}", gitExePath, args, workingDirectory)); var pinfo = new ProcessStartInfo(gitExePath) { Arguments = args, CreateNoWindow = true, RedirectStandardError = true, RedirectStandardOutput = true, UseShellExecute = false, WorkingDirectory = workingDirectory, }; if (UseUTF8FileNames) { pinfo.StandardOutputEncoding = Encoding.UTF8; pinfo.StandardErrorEncoding = Encoding.UTF8; } using (var process = Process.Start(pinfo)) { string output = process.StandardOutput.ReadToEnd(); string error = process.StandardError.ReadToEnd(); process.WaitForExit(); //Debug.WriteLine(output); result.HasError = process.ExitCode != 0; result.Output = output; result.Error = error; return(result); } }
public static GitBashResult Run(string args, string workingDirectory) { if (string.IsNullOrWhiteSpace(gitExePath) || !File.Exists(gitExePath)) throw new Exception("Git Executable not found"); GitBashResult result = new GitBashResult(); //Debug.WriteLine(string.Format("{2}>{0} {1}", gitExePath, args, workingDirectory)); var pinfo = new ProcessStartInfo(gitExePath) { Arguments = args, CreateNoWindow = true, RedirectStandardError = true, RedirectStandardOutput = true, UseShellExecute = false, WorkingDirectory = workingDirectory, }; if (UseUTF8FileNames) { pinfo.StandardOutputEncoding = Encoding.UTF8; pinfo.StandardErrorEncoding = Encoding.UTF8; } using (var process = Process.Start(pinfo)) { string output = process.StandardOutput.ReadToEnd(); string error = process.StandardError.ReadToEnd(); process.WaitForExit(); //Debug.WriteLine(output); result.HasError = process.ExitCode != 0; result.Output = output; result.Error = error; return result; } }
//internal GitUI.UI.GitConsole console = null; private GitBashResult GitRun(string cmd) { if (!GitBash.Exists) throw new GitException("git.exe is not found."); if (this.Tracker == null) throw new GitException("Git repository is not found."); var ret = new GitBashResult { HasError = true }; try { ret = GitBash.Run(cmd, this.Tracker.WorkingDirectory); HistoryViewCommands.ShowMessage.Execute(new { GitBashResult = ret }, null); } catch (Exception ex) { ret.Error = ex.Message; HistoryViewCommands.ShowMessage.Execute(new { GitBashResult = ret }, null); } return ret; }