Notice: Undefined offset: 2 in environment_indicator_environment_indicator_matched_indicator_alter() (line 513 of environment_indicator/environment_indicator.module).

function environment_indicator_environment_indicator_matched_indicator_alter(&$environment_info) {
  // Show the git branch, if it exists.
  if (variable_get('environment_indicator_git_support', TRUE) && command_exists('git') && $git_path = exec('git rev-parse --show-toplevel')) {
    // The first line of the .git/HEAD file contains a reference to the branch
    // in a string like: ref: refs/heads/[branch]
    $git_head_file = file($git_path . '/.git/HEAD', FILE_USE_INCLUDE_PATH);
    list(, , $branch_name) = explode('/', reset($git_head_file));
    if (!empty($branch_name)) {
      $environment_info['git_branch'] = $branch_name;
    }
  }
  // Acquia cloud environments don't have a .git directory to check. Instead, we
  // need to maintain the release string ourselves using the post deploy hooks.
  if (!empty($_ENV['AH_SITE_ENVIRONMENT']) && variable_get('environment_indicator_git_support', TRUE)) {
    // Display the contents of the variable if it is not empty. If it is empty
    // then a warning should be set in the status report about the hook being
    // missing for the environment.
    $release = variable_get('environment_indicator_remote_release.' . $_ENV['AH_SITE_ENVIRONMENT'], NULL);
    if (!empty($git_branch)) {
      $environment_info['git_branch'] = $release;
    }
  }
}

This is caused when you perform a Git checkout of a tag instead of a branch, and the .git/HEAD file (and the $git_head_file variable) contains just the commit hash of that tag, failing the expectation that explode() will return three valid parts. Might it be better to run git describe --all rather than read the .git/HEAD file directly?

Also there is a bug in the Acquia environment section in the second half. if (!empty($git_branch) should be if (!empty($release)) because that $git_branch variable is not defined.

CommentFileSizeAuthor
#1 git-php-notices-2287977-1.patch2.86 KBe0ipso
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

e0ipso’s picture

Thanks for contributing and describing the error so thoroughly.

  • Commit bcf11f6 on 7.x-2.x by e0ipso:
    Issue #2287977 by e0ipso: Use git describe --all to find tag name.
    
helmo’s picture

Status: Active » Fixed

Assuming fixed as this has long been committed and included in a stable release.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.