Fetch Git commit ID from .git/HEAD if available

refs #9247
This commit is contained in:
Alexander A. Klimov 2015-06-05 12:38:55 +02:00
parent b69311165c
commit abcdc5adb1
1 changed files with 11 additions and 0 deletions

View File

@ -15,6 +15,17 @@ class Version
*/
public static function get()
{
if (false !== ($gitHead = @file_get_contents((
$gitDir = Icinga::app()->getBaseDir('.git')
) . DIRECTORY_SEPARATOR . 'HEAD'))) {
$matches = array();
if ((1 !== @preg_match('/(?<!.)ref:\s+(?P<gitCommitID>.+?)$/ms', $gitHead, $matches) || false !== (
$gitHead = @file_get_contents($gitDir . DIRECTORY_SEPARATOR . $matches['gitCommitID'])
)) && 1 === @preg_match('/(?<!.)(?P<gitCommitID>[0-9a-f]+)$/ms', $gitHead, $matches)) {
return $matches;
}
}
if (false === ($appVersion = @file_get_contents(
Icinga::app()->getApplicationDir() . DIRECTORY_SEPARATOR . 'VERSION'
))) {