You are here

function _git_deploy_tag in Git Deploy 6

Same name and namespace in other branches
  1. 7 git_deploy.module \_git_deploy_tag()

Checks for most recent tag in local history.

Parameters

Git $git: A Git instance.

string[] $tags: Tag hashes keyed by reference, in descending order.

string[] $local: Local history starting with most recent common commit hash.

array $upstream: Things we need to know to determine status.

1 call to _git_deploy_tag()
_git_deploy_get_upstream in ./git_deploy.module
Gets upstream info.

File

./git_deploy.module, line 411
Adds project, version and date information to projects checked out with Git.

Code

function _git_deploy_tag(Git $git, array $tags, $local, array &$upstream) {
  $githash = array_shift($local);

  // Check for tags that do not exist on a remote branch.
  $ref = key(array_intersect($tags, $local));
  if (!empty($ref)) {
    $upstream['tag'] = str_replace('refs/tags/', '', $ref);
    $githash = $tags[$ref];
  }
  elseif (in_array($githash, $tags)) {
    $upstream['tag'] = str_replace('refs/tags/', '', array_search($githash, $tags));
  }
  else {

    // Check for annotated tag.
    foreach ($tags as $ref => $hash) {
      $tag = @$git
        ->getObject($hash);
      if ($tag
        ->getType() == Git::OBJ_TAG) {
        $hash = $tag->object;

        // Check for tags that do not exist on a remote branch.
        if (in_array($hash, $local)) {
          $upstream['tag'] = str_replace('refs/tags/', '', $ref);
          $githash = $hash;
          break;
        }
        elseif ($hash == $githash) {
          $upstream['tag'] = $tag->tag;
          break;
        }
      }
    }
  }
  return $githash;
}