Git Branch (Git 현재 저장소 확인)
Unity 에서 현재 사용하는 정보를 알고 싶어서 테스트 코드를 만들어봤다.
원리는 간단하게 Unity 에서 Git Process를 통해서 Git 명령어를 전송 이후에 해당 결과를 노출하는 형태이다.
반응형
<Git 명령어>
명령어 | 설명 |
rev-parse --short HEAD | 현재 커밋에서 짧은 SHA-1 해시 키를 표시 |
log -n 1 | 현재 저장소의 가장 최근 커밋의 세부 정보 1개만 표시 |
branch --show-current | 현재 branch 이름 표시 (Git 2.22이상) |
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Diagnostics;
using System;
public class GitInformation : MonoBehaviour
{
[MenuItem("Infomation/Show - Git Infomation")]
public static void ShowGitBracnName()
{
string header = GetGitProcess("rev-parse --short HEAD");
string log = GetGitProcess("log -n 1");
string branchName = GetGitProcess("branch --show-current");
if (EditorUtility.DisplayDialog($"Git - Short Head : [{header}]", $" Git Current Revision : {log}", $" Branch :{branchName} "))
{
Debug.Log($"[Git] Git Information head: {header} / branch : {branchName} / log : {log}");
}
}
/// <summary>
/// Git Process
/// </summary>
/// <param name="_gitCommand"></param>
/// <returns></returns>
public static string GetGitProcess(string _gitCommand)
{
try
{
Process process = new Process();
ProcessStartInfo procStartInfo = new ProcessStartInfo();
procStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
procStartInfo.UseShellExecute = false;
procStartInfo.RedirectStandardOutput = true;
procStartInfo.WorkingDirectory = Path.GetFullPath(Application.dataPath + "/..");
procStartInfo.CreateNoWindow = true;
procStartInfo.FileName = "git.exe";
procStartInfo.Arguments = _gitCommand;
Process p = Process.Start(procStartInfo);
StreamReader sreader = p.StandardOutput;
string output = sreader.ReadToEnd();
p.WaitForExit();
return output;
}
catch (Exception ex)
{
return string.Empty;
}
}
}
.Net Prcosse 클래스 : [링크]
★☆☆☆☆
반응형
댓글