diff --git a/environment_indicator.module b/environment_indicator.module index 56e6aba..454986c 100644 --- a/environment_indicator.module +++ b/environment_indicator.module @@ -493,21 +493,18 @@ function _environment_indicator_has_old_vars() { * Implements hook_environment_indicator_matched_indicator_alter(). */ function environment_indicator_environment_indicator_matched_indicator_alter(&$environment_info) { - // Show the git branch. - if (variable_get('environment_indicator_git_support', TRUE) && command_exists('git')) { - // Git exists. - $git_path = exec('git rev-parse --show-toplevel'); - $stringfromfile = file($git_path . '/.git/HEAD', FILE_USE_INCLUDE_PATH); - $stringfromfile = $stringfromfile[0]; //get the string from the array - $explodedstring = explode("/", $stringfromfile); //seperate out by the "/" in the string - $branchname = $explodedstring[2]; //get the one that is always the branch name - if (!empty($branchname)) { - $environment_info['git_branch'] = $branchname; + // 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); + (NULL, NULL, $branch_name) = explode('/', array_shift($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 of - // that we need to maintain the release string ourselves using the post deploy - // hooks. + // 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