using LibGit2Sharp; using Server.System; using System.Diagnostics; namespace Server.Git { public abstract class AbstractGit { public bool isRestart; string repositoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "excel"); public string _repositoryPath { get { return repositoryPath; } } /// /// 가장먼저 시작해야 하는 스크립트 /// public void Init() { restart: isRestart = false; Pull(); if (isRestart) goto restart; ChangeScript(); if (isRestart) goto restart; Push(); if (isRestart) goto restart; } /// /// 엑셀 불러오기, 저장, 혹은 배포 까지 작업해야하는 함수 /// public abstract void ChangeScript(); private void Pull() { if (!Directory.Exists(repositoryPath)) { Directory.CreateDirectory(repositoryPath); RepositorySet($"clone {STATICS.remoteUrl} {repositoryPath}", null); //main브렌치로 세팅 RepositorySet("branch -m main", repositoryPath); RepositorySet("branch --set-upstream-to=origin/main main", repositoryPath); } // pull 명령어 실행 RepositorySet("pull", repositoryPath); } private static void RepositorySet(string command, string workingDirectory) { ProcessStartInfo psi = new ProcessStartInfo { FileName = "git", Arguments = command, WorkingDirectory = workingDirectory, RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, CreateNoWindow = true }; using (Process process = new Process { StartInfo = psi }) { process.Start(); process.WaitForExit(); // Git 명령 실행 결과 출력 Console.WriteLine(process.StandardOutput.ReadToEnd()); // 오류 메시지 출력 Console.WriteLine(process.StandardError.ReadToEnd()); } } private void Push() { } } }