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())) ?> diff --git a/library/Icinga/Application/Version.php b/library/Icinga/Application/Version.php index ee4dc6505..264fe5065 100644 --- a/library/Icinga/Application/Version.php +++ b/library/Icinga/Application/Version.php @@ -25,24 +25,38 @@ 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 current commit of the Git repository in the given path + * + * @param string $repo Path to the Git repository + * @param bool $bare Whether the Git repository is bare + * + * @return string|bool False if not available + */ + public static function getGitHead($repo, $bare = false) + { + if (! $bare) { + $repo .= '/.git'; + } + + $head = @file_get_contents($repo . '/HEAD'); + + if ($head !== false) { + if (preg_match('/^ref: (.+)/', $head, $matches)) { + return @file_get_contents($repo . '/' . $matches[1]); + } + + return $head; + } + + return false; + } }