Skip to content

Instantly share code, notes, and snippets.

@KimDaesap
Created December 12, 2017 03:16
Show Gist options
  • Save KimDaesap/9cb5693caaf878c018bd85baf9b80914 to your computer and use it in GitHub Desktop.
Save KimDaesap/9cb5693caaf878c018bd85baf9b80914 to your computer and use it in GitHub Desktop.
public static int GetRevision()
{
var p = new Process { StartInfo = new ProcessStartInfo
{
FileName = "git",
Arguments = "rev-list HEAD --count",
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
StandardOutputEncoding = Encoding.Default,
StandardErrorEncoding = Encoding.Default,
UseShellExecute = false
} };
var revision = 0;
try
{
p.Start();
var output = p.StandardOutput.ReadToEnd();
var error = p.StandardError.ReadToEnd();
p.WaitForExit();
if (!string.IsNullOrEmpty(output) && string.IsNullOrEmpty(error))
{
var separator = new[] { "\r", "\n" };
var lines = output.Split(separator, StringSplitOptions.RemoveEmptyEntries);
revision = (from r in lines select int.Parse(r)).First();
}
else
{
throw new Exception(error);
}
}
catch (Exception e)
{
EditorUtility.DisplayDialog("Error", string.Format("Revision 정보를 확인할 수 없습니다.\n\n{0}", e), "확인");
}
return revision;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment