I use the 'rev-list [remote_branch] --count' value as the internal build version number in mobile submissions, but would like to retrieve the commit hash id from the value for reference at a later date.
Below is the C# code I use to retrieve the rev-list count:
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using Debug = UnityEngine.Debug;
public static string GetCommitCountFromCorrespondingRemoteBranch()
{
string strCommitCount = "";
Process p = new Process();
// Set path to git exe.
p.StartInfo.FileName = GIT_EXEC_PATH;
// Set git command.
p.StartInfo.Arguments = "rev-list " + GetRemoteBranchName() + " --count";
// Set working directory.
p.StartInfo.WorkingDirectory = Application.dataPath + "/../";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
// Pass output to variable.
strCommitCount = p.StandardOutput.ReadToEnd();
p.WaitForExit();
if (string.IsNullOrEmpty(strCommitCount) == true)
{
Debug.LogError("UNABLE TO GET BRANCH COMMIT COUNT");
}
return strCommitCount;
}
Example Return Value: 4427