diff --git a/psalm-baseline.xml b/psalm-baseline.xml index abb9cea..b43db06 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -5,7 +5,7 @@ $configuration - + shell_exec($command) diff --git a/src/Classes/Controllers/IndexController.php b/src/Classes/Controllers/IndexController.php index 01fff0a..93b855f 100644 --- a/src/Classes/Controllers/IndexController.php +++ b/src/Classes/Controllers/IndexController.php @@ -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; @@ -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([ @@ -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; - } } diff --git a/src/Classes/Helpers/GitHelper.php b/src/Classes/Helpers/GitHelper.php new file mode 100644 index 0000000..d0c7699 --- /dev/null +++ b/src/Classes/Helpers/GitHelper.php @@ -0,0 +1,47 @@ + + * + * 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; + } +} diff --git a/src/Classes/ViewModels/ModuleViewModel.php b/src/Classes/ViewModels/ModuleViewModel.php index 90ea2f4..4ef2ffd 100644 --- a/src/Classes/ViewModels/ModuleViewModel.php +++ b/src/Classes/ViewModels/ModuleViewModel.php @@ -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; @@ -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(); diff --git a/src/Templates/ModuleInfo.tmpl.php b/src/Templates/ModuleInfo.tmpl.php index 1ea6039..a233eaf 100644 --- a/src/Templates/ModuleInfo.tmpl.php +++ b/src/Templates/ModuleInfo.tmpl.php @@ -115,7 +115,7 @@ Version - = $moduleView->getVersion(); ?> + = $moduleView->getVersionAndGitBranch(); ?> @@ -292,8 +292,9 @@ Alle Versionen getVersions() as $moduleVersion) {?> + - = $moduleVersion->getVersion(); ?> + = $moduleVersionView->getVersionAndGitBranch(); ?> isInstalled()) { ?> installiert
$configuration
shell_exec($command)