From 925f451c8e5ecc0016d4f6c28f8a1dc2e949e2dd Mon Sep 17 00:00:00 2001
From: Vincent Isambart <vincent.isambart@gmail.com>
Date: Thu, 11 Dec 2008 20:56:21 +0900
Subject: [PATCH] Properly read the git revision if the head is detached
---
Rakefile | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/Rakefile b/Rakefile
index e8a88ef..34cb2a1 100644
|
a
|
b
|
|
| 273 | 273 | current_revision = "svn revision #{md_revision[1]} from #{md_url[1]}" if md_revision and md_url |
| 274 | 274 | end |
| 275 | 275 | if not current_revision and File.exist?('.git/HEAD') |
| 276 | | md_ref = /^ref: (.+)$/.match(File.read('.git/HEAD')) |
| | 276 | commit_sha1 = nil |
| | 277 | head = File.read('.git/HEAD').strip |
| | 278 | md_ref = /^ref: (.+)$/.match(head) |
| 277 | 279 | if md_ref |
| | 280 | # if the HEAD file contains "ref: XXXX", it's the reference to a branch |
| | 281 | # so we read the file indicating the last commit of the branch |
| 278 | 282 | head_file = ".git/#{md_ref[1]}" |
| 279 | | current_revision = "git commit #{File.read(head_file).strip}" if File.exist?(head_file) |
| | 283 | commit_sha1 = File.read(head_file).strip if File.exist?(head_file) |
| | 284 | else |
| | 285 | # otherwise, it's a detached head so it should be the SHA1 of the last commit |
| | 286 | commit_sha1 = head |
| 280 | 287 | end |
| | 288 | current_revision = "git commit #{commit_sha1}" if commit_sha1 and not commit_sha1.empty? |
| 281 | 289 | end |
| 282 | 290 | current_revision = 'unknown revision' unless current_revision |
| 283 | 291 | |