From b240e0e6bb74205a2ba0b4379c6981c3588f5c81 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 1 Sep 2016 10:14:14 +0200 Subject: [PATCH 1/3] Implement Version::getGitHead() refs #11664 --- library/Icinga/Application/Version.php | 54 ++++++++++++++++++-------- 1 file changed, 38 insertions(+), 16 deletions(-) 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('/(? Date: Thu, 1 Sep 2016 10:26:55 +0200 Subject: [PATCH 2/3] config/module: show Git HEAD commit's ID if available refs #11664 --- application/controllers/ConfigController.php | 2 ++ application/views/scripts/config/module.phtml | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index c1d75b711..c65298377 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -4,6 +4,7 @@ namespace Icinga\Controllers; use Exception; +use Icinga\Application\Version; use InvalidArgumentException; use Icinga\Application\Config; use Icinga\Application\Icinga; @@ -122,6 +123,7 @@ class ConfigController extends Controller $this->view->module = $module; $this->view->tabs = $module->getConfigTabs()->activate('info'); + $this->view->moduleGitCommitId = Version::getGitHead($module->getBaseDir()); } else { $this->view->module = false; $this->view->tabs = null; diff --git a/application/views/scripts/config/module.phtml b/application/views/scripts/config/module.phtml index 798b179ad..a201a0aab 100644 --- a/application/views/scripts/config/module.phtml +++ b/application/views/scripts/config/module.phtml @@ -37,7 +37,14 @@ escape($this->translate('Version')) ?> - escape($module->getVersion()) ?> + escape($module->getVersion()) ?> + + + + escape($this->translate('Git commit')) ?> + escape($moduleGitCommitId) ?> + + escape($this->translate('Description')) ?> escape($module->getDescription())) ?> From 576640e661f205f673662af68b24033df8a91e78 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 9 Sep 2016 14:19:32 +0200 Subject: [PATCH 3/3] Simplify Version::getGitHead() refs #11664 --- library/Icinga/Application/Version.php | 32 ++++++++++---------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/library/Icinga/Application/Version.php b/library/Icinga/Application/Version.php index 0565c3bf5..264fe5065 100644 --- a/library/Icinga/Application/Version.php +++ b/library/Icinga/Application/Version.php @@ -34,35 +34,27 @@ class Version } /** - * Get the hexadecimal ID of the HEAD commit of the Git repository in $repoDir + * Get the current commit of the Git repository in the given path * - * @param string $repoDir - * @param bool $bare Whether the repository has been created with - * $ git init|clone --bare + * @param string $repo Path to the Git repository + * @param bool $bare Whether the Git repository is bare * - * @return string|bool false if not available + * @return string|bool False if not available */ - public static function getGitHead($repoDir, $bare = false) + public static function getGitHead($repo, $bare = false) { if (! $bare) { - $repoDir .= DIRECTORY_SEPARATOR . '.git'; + $repo .= '/.git'; } - $gitHead = @ file_get_contents($repoDir . DIRECTORY_SEPARATOR . 'HEAD'); - if ($gitHead !== false) { - $matches = array(); - if (preg_match('/(?