diff --git a/library/Icinga/Application/Version.php b/library/Icinga/Application/Version.php index ee4dc6505..0565c3bf5 100644 --- a/library/Icinga/Application/Version.php +++ b/library/Icinga/Application/Version.php @@ -25,24 +25,46 @@ class Version } } - $gitDir = Icinga::app()->getBaseDir('.git'); - $gitHead = @file_get_contents($gitDir . DIRECTORY_SEPARATOR . 'HEAD'); - if (false !== $gitHead) { - $matches = array(); - if (@preg_match('/(?[0-9a-f]+)$/ms', $gitCommitID, $matches)) { - return array_merge($version, $matches); - } - } + $gitCommitId = static::getGitHead(Icinga::app()->getBaseDir()); + if ($gitCommitId !== false) { + $version['gitCommitID'] = $gitCommitId; } return $version; } + + /** + * Get the hexadecimal ID of the HEAD commit of the Git repository in $repoDir + * + * @param string $repoDir + * @param bool $bare Whether the repository has been created with + * $ git init|clone --bare + * + * @return string|bool false if not available + */ + public static function getGitHead($repoDir, $bare = false) + { + if (! $bare) { + $repoDir .= DIRECTORY_SEPARATOR . '.git'; + } + + $gitHead = @ file_get_contents($repoDir . DIRECTORY_SEPARATOR . 'HEAD'); + if ($gitHead !== false) { + $matches = array(); + if (preg_match('/(?