예제 #1
0
        public static GitCloneResult Clone(string uri, string dest, string branch = null, int timeLimit = 1000 * 60 * 20)
        {
            if (!System.IO.Directory.Exists(dest))
                System.IO.Directory.CreateDirectory(dest);
            Process p = new Process();

            var argument = $"clone {uri}";
            if (!string.IsNullOrEmpty(branch))
                argument = $"clone {uri} -b {branch}";

            p.StartInfo = new ProcessStartInfo
            {
                RedirectStandardError = true,
                RedirectStandardOutput = true,
                UseShellExecute = false,
                CreateNoWindow = true,
                FileName = "git",
                Arguments = argument,
                WorkingDirectory = dest
            };
            p.Start();
            if (!p.WaitForExit(timeLimit))
                p.Kill();
            var ret = new GitCloneResult
            {
                IsSucceeded = true,
                Output = p.StandardOutput.ReadToEnd(),
                Error = p.StandardError.ReadToEnd()
            };
            if (p.ExitCode != 0)
                ret.IsSucceeded = false;
            return ret;
        }
예제 #2
0
        public static GitCloneResult Clone(string uri, string dest, string branch = null, int timeLimit = 1000 * 60 * 20)
        {
            if (!System.IO.Directory.Exists(dest))
            {
                System.IO.Directory.CreateDirectory(dest);
            }
            Process p = new Process();

            var argument = $"clone {uri}";

            if (!string.IsNullOrEmpty(branch))
            {
                argument = $"clone {uri} -b {branch}";
            }

            p.StartInfo = new ProcessStartInfo
            {
                RedirectStandardError  = true,
                RedirectStandardOutput = true,
                UseShellExecute        = false,
                CreateNoWindow         = true,
                FileName         = "git",
                Arguments        = argument,
                WorkingDirectory = dest
            };
            p.Start();
            if (!p.WaitForExit(timeLimit))
            {
                p.Kill();
            }
            var ret = new GitCloneResult
            {
                IsSucceeded = true,
                Output      = p.StandardOutput.ReadToEnd(),
                Error       = p.StandardError.ReadToEnd()
            };

            if (p.ExitCode != 0)
            {
                ret.IsSucceeded = false;
            }
            return(ret);
        }