Index: git_deploy.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/git_deploy/git_deploy.module,v
retrieving revision 1.2.2.11
diff -u -p -r1.2.2.11 git_deploy.module
--- git_deploy.module	1 Feb 2011 05:49:59 -0000	1.2.2.11
+++ git_deploy.module	1 Feb 2011 06:55:21 -0000
@@ -83,10 +83,20 @@ function git_deploy_system_info_alter(&$
 function git_deploy_get_project_timestamp($git_dir) {
   $repo = new Git($git_dir);
   $git_object = $repo->getObject($repo->revParse());
-
   return $git_object->committer->time;
 }
 
+function git_find_tag_for_commit($git_dir) {
+  $repo = new Git($git_dir);
+  $head = $repo->revParse();
+  foreach ($repo->refcache->refs as $name) {
+    $ref = $repo->getObject($name);
+    if ($ref->getType() == Git::OBJ_TAG && $ref->object == $head) {
+      return $ref->tag;
+    }
+  }
+}
+
 /**
  * Private helper to alter the version of a module based on what we can figure
  * out about the Git tag.
@@ -103,37 +113,40 @@ function _git_deploy_version_alter(&$ver
   $repo = new Git($git_dir);
   $githash = $repo->revParse();
   $git_refs = $repo->getrefs();
+  $git_tag = git_find_tag_for_commit($git_dir);
 
-  $head_contents = file_get_contents($git_dir . DIRECTORY_SEPARATOR . 'HEAD');
+  if (!$git_tag) {
+    $head_contents = file_get_contents($git_dir . DIRECTORY_SEPARATOR . 'HEAD');
 
-  if (strpos($head_contents, ':') == 3) {
-      foreach ($git_refs as $branch => $ref) {
-      if ($githash === $ref) {
-        $branch_name = explode('/', $branch);
-        if ($branch_name[2] === "origin") {
-          $git_tag = $branch_name[3];
-          break;
-        }
-        elseif ($branch_name[1] === "heads") {
-          $git_tag = $branch_name[2];
-          break;
-        }
-        else {
-          break;
+    if (strpos($head_contents, ':') == 3) {
+        foreach ($git_refs as $branch => $ref) {
+        if ($githash === $ref) {
+          $branch_name = explode('/', $branch);
+          if ($branch_name[2] === "origin") {
+            $git_tag = $branch_name[3];
+            break;
+          }
+          elseif ($branch_name[1] === "heads") {
+            $git_tag = $branch_name[2];
+            break;
+          }
+          else {
+            break;
+          }
         }
       }
     }
-  }
-  else {
-    foreach ($git_refs as $tag => $ref) {
-      if ($githash === $ref) {
-        $tag_name = explode('/', $tag);
-        if ($tag_name[0] === "HEAD") {
-          continue;
-        }
-        else {
-          if ($tag_name[1] == "tags") {
-            $git_tag = $tag_name[2];
+    else {
+      foreach ($git_refs as $tag => $ref) {
+        if ($githash === $ref) {
+          $tag_name = explode('/', $tag);
+          if ($tag_name[0] === "HEAD") {
+            continue;
+          }
+          else {
+            if ($tag_name[1] == "tags") {
+              $git_tag = $tag_name[2];
+            }
           }
         }
       }
