Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<code>$configuration</code>
</UndefinedVariable>
</file>
<file src="src/Classes/Controllers/IndexController.php">
<file src="src/Classes/Helpers/GitHelper.php">
<ForbiddenCode occurrences="1">
<code>shell_exec($command)</code>
</ForbiddenCode>
Expand Down
34 changes: 3 additions & 31 deletions src/Classes/Controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use RobinTheHood\ModifiedModuleLoaderClient\SendMail;
use RobinTheHood\ModifiedModuleLoaderClient\Config;
use RobinTheHood\ModifiedModuleLoaderClient\DependencyManager\DependencyManager;
use RobinTheHood\ModifiedModuleLoaderClient\Helpers\GitHelper;
use RobinTheHood\ModifiedModuleLoaderClient\MmlcVersionInfoLoader;
use RobinTheHood\ModifiedModuleLoaderClient\ModuleManager\ModuleManager;
use RobinTheHood\ModifiedModuleLoaderClient\ModuleManager\ModuleManagerResult;
Expand Down Expand Up @@ -162,7 +163,8 @@ public function invokeSelfUpdate()
return $accessRedirect;
}

$gitBranch = $this->getCurrentGitBranch(App::getRoot() . '/.git');
$gitHelper = new GitHelper();
$gitBranch = $gitHelper->getCurrentGitBranch(App::getRoot() . '/.git');

if ($gitBranch) {
Notification::pushFlashMessage([
Expand Down Expand Up @@ -740,34 +742,4 @@ private function addModuleNotFoundNotification($archiveName, $version = '')
'type' => 'error'
]);
}

private function getCurrentGitBranch(string $gitPath): ?string
{
if (!is_dir($gitPath)) {
return null;
}

$os = strtoupper(substr(PHP_OS, 0, 3));
$command = '';

switch ($os) {
case 'WIN':
$command = 'cd /d "' . $gitPath . '" & git symbolic-ref --short HEAD 2>NUL';
break;
case 'LIN':
case 'DAR':
$command = 'cd "' . $gitPath . '" && git symbolic-ref --short HEAD 2>/dev/null';
break;
default:
return 'unkown branch';
}

$output = trim('' . shell_exec($command));

if (empty($output)) {
return null;
}

return $output;
}
}
47 changes: 47 additions & 0 deletions src/Classes/Helpers/GitHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

/*
* This file is part of MMLC - ModifiedModuleLoaderClient.
*
* (c) Robin Wieschendorf <mail@robinwieschendorf.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace RobinTheHood\ModifiedModuleLoaderClient\Helpers;

class GitHelper
{
public function getCurrentGitBranch(string $gitPath): ?string
{
if (!is_dir($gitPath)) {
return null;
}

$os = strtoupper(substr(PHP_OS, 0, 3));
$command = '';

switch ($os) {
case 'WIN':
$command = 'cd /d "' . $gitPath . '" & git symbolic-ref --short HEAD 2>NUL';
break;
case 'LIN':
case 'DAR':
$command = 'cd "' . $gitPath . '" && git symbolic-ref --short HEAD 2>/dev/null';
break;
default:
return 'unkown branch';
}

$output = trim('' . shell_exec($command));

if (empty($output)) {
return null;
}

return $output;
}
}
22 changes: 22 additions & 0 deletions src/Classes/ViewModels/ModuleViewModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace RobinTheHood\ModifiedModuleLoaderClient\ViewModels;

use RobinTheHood\ModifiedModuleLoaderClient\App;
use RobinTheHood\ModifiedModuleLoaderClient\Helpers\GitHelper;
use RobinTheHood\ModifiedModuleLoaderClient\Module;
use RobinTheHood\ModifiedModuleLoaderClient\ModuleStatus;
use RobinTheHood\ModifiedModuleLoaderClient\Semver\ParseErrorException;
Expand Down Expand Up @@ -188,6 +189,27 @@ public function getVersion(): string
return $this->module->getVersion();
}

public function getVersionAndGitBranch(): string
{
$version = $this->getVersion();

if ($this->module->isRemote()) {
return $version;
}

$gitHelper = new GitHelper();
$gitBranch = $gitHelper->getCurrentGitBranch(
$this->module->getLocalRootPath() . $this->module->getModulePath() . '/.git'
);

if ($gitBranch) {
//return $version . ' 🔀 ' . $gitBranch;
return $version . ' git:(' . $gitBranch . ')';
} else {
return $version;
}
}

public function getDate(): string
{
return $this->module->getDate();
Expand Down
5 changes: 3 additions & 2 deletions src/Templates/ModuleInfo.tmpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
<tbody>
<tr>
<td>Version</td>
<td><?= $moduleView->getVersion(); ?></td>
<td><?= $moduleView->getVersionAndGitBranch(); ?></td>
</tr>

<tr>
Expand Down Expand Up @@ -292,8 +292,9 @@
<td>Alle Versionen</td>
<td>
<?php foreach ($module->getVersions() as $moduleVersion) {?>
<?php $moduleVersionView = new ModuleViewModel($moduleVersion) ?>
<a href="?action=moduleInfo&archiveName=<?= $moduleVersion->getArchiveName() ?>&version=<?= $moduleVersion->getVersion()?>">
<?= $moduleVersion->getVersion(); ?>
<?= $moduleVersionView->getVersionAndGitBranch(); ?>
</a>
<?php if ($moduleVersion->isInstalled()) { ?>
<span>installiert</span>
Expand Down