summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.BuildTasks
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2010-01-17 21:44:30 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2010-01-17 21:44:30 -0800
commita16b9b9222da75b43a44cfde9de912bba4c09670 (patch)
tree5429e7a464fa77bf61ce111efe686183745e3537 /src/DotNetOpenAuth.BuildTasks
parent9a77154c54439bacd06938e2c0624c69d4e48c69 (diff)
parentcdb850c6cf90381e6db75365272b7d65ef5fe359 (diff)
downloadDotNetOpenAuth-a16b9b9222da75b43a44cfde9de912bba4c09670.zip
DotNetOpenAuth-a16b9b9222da75b43a44cfde9de912bba4c09670.tar.gz
DotNetOpenAuth-a16b9b9222da75b43a44cfde9de912bba4c09670.tar.bz2
Merge branch 'master' into master-Dev10
Conflicts: build.proj lib/DotNetOpenAuth.BuildTasks.dll lib/DotNetOpenAuth.BuildTasks.pdb src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs src/DotNetOpenAuth.Test/Messaging/MultiPartPostPartTests.cs src/DotNetOpenAuth.sln src/DotNetOpenAuth.vsmdi src/DotNetOpenAuth/OAuth/OAuthStrings.Designer.cs
Diffstat (limited to 'src/DotNetOpenAuth.BuildTasks')
-rw-r--r--src/DotNetOpenAuth.BuildTasks/DotNetOpenAuth.BuildTasks.csproj4
-rw-r--r--src/DotNetOpenAuth.BuildTasks/GetBuildVersion.cs50
2 files changed, 47 insertions, 7 deletions
diff --git a/src/DotNetOpenAuth.BuildTasks/DotNetOpenAuth.BuildTasks.csproj b/src/DotNetOpenAuth.BuildTasks/DotNetOpenAuth.BuildTasks.csproj
index daf6327..3f76f78 100644
--- a/src/DotNetOpenAuth.BuildTasks/DotNetOpenAuth.BuildTasks.csproj
+++ b/src/DotNetOpenAuth.BuildTasks/DotNetOpenAuth.BuildTasks.csproj
@@ -80,7 +80,9 @@
<Reference Include="Microsoft.Build.Utilities.v3.5">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
- <Reference Include="Microsoft.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=736440c9b414ea16, processorArchitecture=MSIL" />
+ <Reference Include="Microsoft.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=736440c9b414ea16, processorArchitecture=MSIL">
+ <Private>False</Private>
+ </Reference>
<Reference Include="Microsoft.Web.Administration, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(SystemRoot)\System32\inetsrv\Microsoft.Web.Administration.dll</HintPath>
diff --git a/src/DotNetOpenAuth.BuildTasks/GetBuildVersion.cs b/src/DotNetOpenAuth.BuildTasks/GetBuildVersion.cs
index 48b5d5c..23db9a6 100644
--- a/src/DotNetOpenAuth.BuildTasks/GetBuildVersion.cs
+++ b/src/DotNetOpenAuth.BuildTasks/GetBuildVersion.cs
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel;
+using System.Diagnostics;
+using System.IO;
using System.Linq;
using System.Text;
-using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;
-using System.IO;
+using Microsoft.Build.Utilities;
namespace DotNetOpenAuth.BuildTasks {
public class GetBuildVersion : Task {
@@ -52,18 +54,54 @@ namespace DotNetOpenAuth.BuildTasks {
return string.Empty;
}
- string headContent = string.Empty;
+ string commitId = string.Empty;
+
+ // First try asking Git for the HEAD commit id
+ try {
+ string cmdPath = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.System), "cmd.exe");
+ ProcessStartInfo psi = new ProcessStartInfo(cmdPath, "/c git rev-parse HEAD");
+ psi.WindowStyle = ProcessWindowStyle.Hidden;
+ psi.RedirectStandardOutput = true;
+ psi.UseShellExecute = false;
+ Process git = Process.Start(psi);
+ commitId = git.StandardOutput.ReadLine();
+ git.WaitForExit();
+ if (git.ExitCode != 0) {
+ commitId = string.Empty;
+ }
+ if (commitId != null) {
+ commitId = commitId.Trim();
+ if (commitId.Length == 40) {
+ return commitId;
+ }
+ }
+ } catch (InvalidOperationException) {
+ } catch (Win32Exception) {
+ }
+
+ // Failing being able to use the git command to figure out the HEAD commit ID, try the filesystem directly.
try {
- headContent = File.ReadAllText(Path.Combine(this.GitRepoRoot, @".git/HEAD")).Trim();
+ string headContent = File.ReadAllText(Path.Combine(this.GitRepoRoot, @".git/HEAD")).Trim();
if (headContent.StartsWith("ref:", StringComparison.Ordinal)) {
string refName = headContent.Substring(5).Trim();
- headContent = File.ReadAllText(Path.Combine(this.GitRepoRoot, @".git/" + refName)).Trim();
+ string refPath = Path.Combine(this.GitRepoRoot, ".git/" + refName);
+ if (File.Exists(refPath)) {
+ commitId = File.ReadAllText(refPath).Trim();
+ } else {
+ string packedRefPath = Path.Combine(this.GitRepoRoot, ".git/packed-refs");
+ string matchingLine = File.ReadAllLines(packedRefPath).FirstOrDefault(line => line.EndsWith(refName));
+ if (matchingLine != null) {
+ commitId = matchingLine.Substring(0, matchingLine.IndexOf(' '));
+ }
+ }
+ } else {
+ commitId = headContent;
}
} catch (FileNotFoundException) {
} catch (DirectoryNotFoundException) {
}
- return headContent.Trim();
+ return commitId.Trim();
}
private Version ReadVersionFromFile() {