private void GitForm_Load(object sender, EventArgs e) { string enlistmentRoot = @"E:\JProject\GitRepository\Work"; string workingDirectory = @"E:\JProject\GitRepository\Work\developmentdocs"; string repoUrl = "https://gitee.com/SkeCloud/SkeFramework.git"; string gitBinPath = @"D:\Program Files\Git\cmd\git.exe"; GitBaseConfig authConfig = new GitAuthConfig(enlistmentRoot, workingDirectory, repoUrl, gitBinPath); IGitCommandService command = new GitCommandService(authConfig); //Result result = gitProcess.InvokeGitOutsideEnlistment("version"); string version = command.GitVersion(); //string error = ""; string originUrl = "http://192.168.104.43/netProject/developmentdocs.git"; //string username = "******"; //string password = "******"; //ICredentialService credentialStore = new CredentialService(authConfig); //credentialStore.TryStoreCredential(repoUrl, username, password, out error); //username = ""; //password = ""; //credentialStore.TryGetCredential(repoUrl, out username, out password, out error); CloneService cloneService = new CloneService(authConfig); Result result = cloneService.GitClone(originUrl, "master"); result = cloneService.GitPull(); }
/// <summary> /// 拉去项目代码 /// </summary> /// <param name="project"></param> /// <returns></returns> public bool GitProjectSourceCode(PdProject project, string RequestUser) { string enlistmentRoot = project.SourcePath; string workingDirectory = project.SourcePath; string repoUrl = project.VersionUrl; string gitBinPath = project.GitBinPath; GitBaseConfig config = new GitAuthConfig(enlistmentRoot, workingDirectory, repoUrl, gitBinPath); CloneService cloneService = new CloneService(config); ConfigResult configResult = cloneService.GetFromLocalConfig(GitConstant.GitCommandConfig.RemoteOriginUrl); string value = ""; string error = ""; Result result; if (configResult.TryParseAsString(out value, out error)) { ConfigResult configResult1 = cloneService.GetFromLocalConfig($"branch.{project.GitBranch}.remote"); if (configResult1.TryParseAsString(out value, out error) && !String.IsNullOrEmpty(value)) { result = cloneService.GitPull(); } else { result = cloneService.ForceCheckout(project.GitBranch); } } else { result = cloneService.GitClone(project.VersionUrl, project.GitBranch); } string message = JsonConvert.SerializeObject(project); string HandleUser = ServerConstData.ServerName; LoginResultType resultType = result.ExitCode == 0 ? LoginResultType.SUCCESS_PUBLISHGIT : LoginResultType.FAILED; int HandleResult = (int)resultType; DataHandleManager.Instance().UcLoginLogHandle. InsertPublishDeployGitLog(RequestUser, message, HandleUser, HandleResult, result.Output); return(result.ExitCodeIsSuccess); }