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> /// <param name="RequestUser"></param> /// <returns></returns> public bool RunPublishBat(PdProject project, string RequestUser) { if (project == null) { return(false); } string batPath = project.SourcePath + project.ProjectFile; if (File.Exists(batPath)) { FileInfo fileInfo = new FileInfo(batPath); if (!fileInfo.Exists) { return(false); } string enlistmentRoot = project.SourcePath; string workingDirectory = fileInfo.Directory.ToString(); string repoUrl = project.VersionUrl; string gitBinPath = project.MSBuildPath; GitBaseConfig config = new GitAuthConfig(enlistmentRoot, workingDirectory, repoUrl, gitBinPath); GitProcess process = config.CreateGitProcess(); int exitCode = -1; List <string> commandList = new List <string>(); commandList.Add(fileInfo.Name); List <string> reulit = this.Shell("cmd.exe", "/k ", 5 * 60 * 1000, fileInfo.Directory.ToString(), out exitCode, commandList.ToArray()); LoginResultType resultType = exitCode == 0 && reulit.Contains(" 0 个错误") ? LoginResultType.SUCCESS_PUBLISHCMD : LoginResultType.FAILED; string message = JsonConvert.SerializeObject(project); string HandleUser = ServerConstData.ServerName; int HandleResult = (int)resultType; string HandleMessage = resultType == LoginResultType.SUCCESS_PUBLISHCMD ? resultType.GetEnumDescription() : String.Join(";", reulit); DataHandleManager.Instance().UcLoginLogHandle. InsertCommonLog(RequestUser, message, LogTypeEumns.PublishCmd, HandleUser, HandleResult, HandleMessage); if (exitCode == 0 && reulit.Contains(" 0 个错误")) { return(true); } } else { DataHandleManager.Instance().UcLoginLogHandle. InsertPublishDeployGitLog(RequestUser, "batPath:" + batPath, ServerConstData.ServerName, 400, "文件不存在;"); } return(false); }
/// <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); }