static bool ExecuteGitCommand(string args, GitCommandCallback callback = null, bool waitForExit = true, string dir = ".")
        {
            var startInfo = new System.Diagnostics.ProcessStartInfo
            {
                Arguments              = args,
                CreateNoWindow         = true,
                FileName               = "git",
                RedirectStandardError  = true,
                RedirectStandardOutput = true,
                UseShellExecute        = false,
                WorkingDirectory       = dir,
            };

            var launchProcess = System.Diagnostics.Process.Start(startInfo);

            if (launchProcess == null || launchProcess.HasExited || launchProcess.Id == 0)
            {
                Debug.LogError("No 'git' executable was found. Please install Git on your system and restart Unity");
                if (callback != null)
                {
                    callback(false, "");
                }
            }
            else
            {
                //Add process callback.
                IsGitRunning      = true;
                s_sbError.Length  = 0;
                s_sbOutput.Length = 0;
                launchProcess.OutputDataReceived += (sender, e) => s_sbOutput.AppendLine(e.Data ?? "");
                launchProcess.ErrorDataReceived  += (sender, e) => s_sbError.AppendLine(e.Data ?? "");
                launchProcess.Exited             += (sender, e) =>
                {
                    IsGitRunning = false;
                    var success = 0 == launchProcess.ExitCode;
                    if (!success)
                    {
                        Debug.LogErrorFormat("Error: git {0}\n\n{1}", args, s_sbError);
                    }

                    if (callback != null)
                    {
                        callback(success, s_sbOutput.ToString());
                    }
                };

                launchProcess.BeginOutputReadLine();
                launchProcess.BeginErrorReadLine();
                launchProcess.EnableRaisingEvents = true;

                if (waitForExit)
                {
                    launchProcess.WaitForExit();
                }
            }

            return(launchProcess.HasExited
                ? launchProcess.ExitCode == 0
                : true);
        }
Beispiel #2
0
        public static WaitWhile ExecuteGitCommand(string args, GitCommandCallback callback, bool waitForExit = false)
        {
            var startInfo = new System.Diagnostics.ProcessStartInfo
            {
                Arguments              = args,
                CreateNoWindow         = true,
                FileName               = "git",
                RedirectStandardError  = true,
                RedirectStandardOutput = true,
                UseShellExecute        = false,
            };

            var launchProcess = System.Diagnostics.Process.Start(startInfo);

            if (launchProcess == null || launchProcess.HasExited || launchProcess.Id == 0)
            {
                Debug.LogError("No 'git' executable was found. Please install Git on your system and restart Unity");
                callback(false, string.Empty);
            }
            else
            {
                //Add process callback.
                IsGitRunning      = true;
                s_sbError.Length  = 0;
                s_sbOutput.Length = 0;
                launchProcess.OutputDataReceived += (sender, e) => s_sbOutput.AppendLine(e.Data ?? string.Empty);
                launchProcess.ErrorDataReceived  += (sender, e) => s_sbError.AppendLine(e.Data ?? string.Empty);
                launchProcess.Exited             += (sender, e) =>
                {
                    IsGitRunning = false;
                    bool success = 0 == launchProcess.ExitCode;
                    if (!success)
                    {
                        Debug.LogError($"Error: git {args}\n\n{s_sbError}");
                    }

                    callback(success, s_sbOutput.ToString());
                };

                launchProcess.BeginOutputReadLine();
                launchProcess.BeginErrorReadLine();
                launchProcess.EnableRaisingEvents = true;

                if (waitForExit)
                {
                    launchProcess.WaitForExit();
                }
            }

            return(new WaitWhile(() => IsGitRunning));
        }
Beispiel #3
0
        static void ExecuteGitCommand(string args, GitCommandCallback callback)
        {
            var startInfo = new System.Diagnostics.ProcessStartInfo
            {
                Arguments              = args,
                CreateNoWindow         = true,
                FileName               = "git",
                RedirectStandardError  = true,
                RedirectStandardOutput = true,
                UseShellExecute        = false
            };

            Debug.LogFormat("[GitUtils]: Start git command: args = {0}", args);
            var launchProcess = System.Diagnostics.Process.Start(startInfo);

            if (launchProcess == null || launchProcess.HasExited == true || launchProcess.Id == 0)
            {
                Debug.LogError("No 'git' executable was found. Please install Git on your system and restart Unity");
                callback(false, "");
            }
            else
            {
                //Add process callback.
                IsGitRunning      = true;
                s_sbError.Length  = 0;
                s_sbOutput.Length = 0;
                launchProcess.OutputDataReceived += (sender, e) => s_sbOutput.AppendLine(e.Data ?? "");
                launchProcess.ErrorDataReceived  += (sender, e) => s_sbError.AppendLine(e.Data ?? "");
                launchProcess.Exited             += (sender, e) =>
                {
                    IsGitRunning = false;
                    bool success = 0 == launchProcess.ExitCode;
                    if (!success)
                    {
                        Debug.LogErrorFormat("Error: git {0}\n\n{1}", args, s_sbError);
                    }
                    callback(success, s_sbOutput.ToString());
                };

                launchProcess.BeginOutputReadLine();
                launchProcess.BeginErrorReadLine();
                launchProcess.EnableRaisingEvents = true;
            }
        }