82 lines
2.3 KiB
C#
82 lines
2.3 KiB
C#
using LibGit2Sharp;
|
|
using Server.System;
|
|
using System.Diagnostics;
|
|
|
|
namespace Server.Git
|
|
{
|
|
public abstract class AbstractGit
|
|
{
|
|
public bool isRestart;
|
|
/// <summary>
|
|
/// 가장먼저 시작해야 하는 스크립트
|
|
/// </summary>
|
|
public void Init()
|
|
{
|
|
restart:
|
|
isRestart = false;
|
|
Pull();
|
|
if (isRestart)
|
|
goto restart;
|
|
ChangeScript();
|
|
if (isRestart)
|
|
goto restart;
|
|
Push();
|
|
if (isRestart)
|
|
goto restart;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 엑셀 불러오기, 저장, 혹은 배포 까지 작업해야하는 함수
|
|
/// </summary>
|
|
public abstract void ChangeScript();
|
|
|
|
private void Pull()
|
|
{
|
|
string repositoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "excel");
|
|
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()
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|