/// <summary> /// Asynchronously run a git command, with streaming onOutput and onError events as they happen, /// and then running onComplete when the process completes /// </summary> /// <param name="command"></param> /// <param name="onComplete"></param> /// <param name="onError"></param> public static void RunCommandInternal(string command, Action <string> onOutput, Action <string> onError, Action onComplete) { //Start info ProcessStartInfo gitInfo = new ProcessStartInfo(); gitInfo.CreateNoWindow = true; gitInfo.RedirectStandardError = true; gitInfo.RedirectStandardOutput = true; gitInfo.FileName = GitGudSettings.GetString("git_path"); gitInfo.Arguments = command; gitInfo.WorkingDirectory = GitGudSettings.GetString("repo_path"); gitInfo.UseShellExecute = false; //Process Process gitProcess = new Process(); gitProcess.StartInfo = gitInfo; gitProcess.EnableRaisingEvents = true; //Hook events gitProcess.OutputDataReceived += (sender, args) => onOutput(args.Data); gitProcess.ErrorDataReceived += (sender, args) => onError(args.Data); //Run process bool started = gitProcess.Start(); if (!started) { onError("Process for command " + command + " failed"); GitEvents.TriggerOnGitCommandComplete(); return; } GitEvents.TriggerOnGitCommandStart(); gitProcess.BeginOutputReadLine(); gitProcess.BeginErrorReadLine(); gitProcess.WaitForExit(); gitProcess.Close(); GitEvents.TriggerOnGitCommandComplete(); onComplete(); }
//Converts a path relative to the repo to an absolute path public static string RepoPathToAbsolutePath(string repoPath) { return(System.IO.Path.Combine(GitGudSettings.GetString("repo_path"), repoPath)); }