Build.UpdateVersion can track the git revision now, in addition to svn and bzr.

This commit is contained in:
Andy Korth 2012-12-20 13:35:58 -06:00
parent 339ffa61db
commit 0847b2ca5c
2 changed files with 196 additions and 168 deletions

View file

@ -88,9 +88,12 @@ namespace Build.UpdateVersion
double timespan = now.Subtract(new DateTime(2010, 1, 1)).TotalDays;
string build = ((int)timespan).ToString();
string revision = RetrieveSvnRevision() ?? RetrieveBzrRevision() ?? RetrieveSeconds(timespan);
string revision = RetrieveGitRevision() ?? RetrieveSvnRevision() ?? RetrieveBzrRevision() ?? RetrieveSeconds(timespan);
revision = revision.Trim();
Console.WriteLine("Build timestamp was: " + build);
Console.WriteLine("Revision detected was: " + revision);
File.WriteAllLines(file, new string[]
{
"// This file is auto-generated through Source/Build.Tasks/GenerateAssemblyInfo.cs.",
@ -117,6 +120,26 @@ namespace Build.UpdateVersion
return revision;
}
static string RetrieveGitRevision()
{
try
{
string output = RunProcess("git", "log -1", RootDirectory);
const string RevisionText = "commit ";
int index = output.IndexOf(RevisionText);
int endIndex = output.IndexOf("\n"); // since it's the first line...
if (index > -1)
return output.Substring(index + RevisionText.Length, endIndex - index - RevisionText.Length).Trim();
}
catch (Exception e)
{
Debug.Print("Failed to retrieve git revision. Error: {0}", e);
}
return null;
}
static string RetrieveSvnRevision()
{
try

View file

@ -42,6 +42,11 @@ namespace Examples
{
try
{
// This seems to be useful enough to leave in for a while.
TextWriterTraceListener console = new TextWriterTraceListener(System.Console.Out);
Trace.Listeners.Add (console);
Debug.Listeners.Add (console);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);