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.
Comment | File | Size | Author |
---|---|---|---|
#1 | git-php-notices-2287977-1.patch | 2.86 KB | e0ipso |
Comments
Comment #1
e0ipsoThanks for contributing and describing the error so thoroughly.
Comment #3
helmo CreditAttribution: helmo at Initfour websolutions commentedAssuming fixed as this has long been committed and included in a stable release.