From abcdc5adb1c890765ba0559a403c0cb8261c16be Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 5 Jun 2015 12:38:55 +0200 Subject: [PATCH] Fetch Git commit ID from .git/HEAD if available refs #9247 --- library/Icinga/Application/Version.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/library/Icinga/Application/Version.php b/library/Icinga/Application/Version.php index c06eca2c2..70ad6cd63 100644 --- a/library/Icinga/Application/Version.php +++ b/library/Icinga/Application/Version.php @@ -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('/(?.+?)$/ms', $gitHead, $matches) || false !== ( + $gitHead = @file_get_contents($gitDir . DIRECTORY_SEPARATOR . $matches['gitCommitID']) + )) && 1 === @preg_match('/(?[0-9a-f]+)$/ms', $gitHead, $matches)) { + return $matches; + } + } + if (false === ($appVersion = @file_get_contents( Icinga::app()->getApplicationDir() . DIRECTORY_SEPARATOR . 'VERSION' ))) {