commit
eafb689136
|
@ -4,6 +4,7 @@
|
||||||
namespace Icinga\Controllers;
|
namespace Icinga\Controllers;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Icinga\Application\Version;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Icinga\Application\Config;
|
use Icinga\Application\Config;
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga;
|
||||||
|
@ -122,6 +123,7 @@ class ConfigController extends Controller
|
||||||
|
|
||||||
$this->view->module = $module;
|
$this->view->module = $module;
|
||||||
$this->view->tabs = $module->getConfigTabs()->activate('info');
|
$this->view->tabs = $module->getConfigTabs()->activate('info');
|
||||||
|
$this->view->moduleGitCommitId = Version::getGitHead($module->getBaseDir());
|
||||||
} else {
|
} else {
|
||||||
$this->view->module = false;
|
$this->view->module = false;
|
||||||
$this->view->tabs = null;
|
$this->view->tabs = null;
|
||||||
|
|
|
@ -37,7 +37,14 @@
|
||||||
</td>
|
</td>
|
||||||
<tr>
|
<tr>
|
||||||
<th><?= $this->escape($this->translate('Version')) ?></th>
|
<th><?= $this->escape($this->translate('Version')) ?></th>
|
||||||
<td><?= $this->escape($module->getVersion()) ?></td></tr>
|
<td><?= $this->escape($module->getVersion()) ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php if (isset($moduleGitCommitId) && $moduleGitCommitId !== false): ?>
|
||||||
|
<tr>
|
||||||
|
<th><?= $this->escape($this->translate('Git commit')) ?></th>
|
||||||
|
<td><?= $this->escape($moduleGitCommitId) ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endif ?>
|
||||||
<tr>
|
<tr>
|
||||||
<th><?= $this->escape($this->translate('Description')) ?></th>
|
<th><?= $this->escape($this->translate('Description')) ?></th>
|
||||||
<td><?= nl2br($this->escape($module->getDescription())) ?></td>
|
<td><?= nl2br($this->escape($module->getDescription())) ?></td>
|
||||||
|
|
|
@ -25,24 +25,38 @@ class Version
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$gitDir = Icinga::app()->getBaseDir('.git');
|
$gitCommitId = static::getGitHead(Icinga::app()->getBaseDir());
|
||||||
$gitHead = @file_get_contents($gitDir . DIRECTORY_SEPARATOR . 'HEAD');
|
if ($gitCommitId !== false) {
|
||||||
if (false !== $gitHead) {
|
$version['gitCommitID'] = $gitCommitId;
|
||||||
$matches = array();
|
|
||||||
if (@preg_match('/(?<!.)ref:\s+(.+?)$/ms', $gitHead, $matches)) {
|
|
||||||
$gitCommitID = @file_get_contents($gitDir . DIRECTORY_SEPARATOR . $matches[1]);
|
|
||||||
} else {
|
|
||||||
$gitCommitID = $gitHead;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (false !== $gitCommitID) {
|
|
||||||
$matches = array();
|
|
||||||
if (@preg_match('/(?<!.)(?P<gitCommitID>[0-9a-f]+)$/ms', $gitCommitID, $matches)) {
|
|
||||||
return array_merge($version, $matches);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $version;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue