CLI + version 1.2.4

This commit is contained in:
Roman 2021-04-07 13:09:50 +02:00
parent ae99ef8a09
commit e91edfeb1e
2 changed files with 34 additions and 10 deletions

42
cli.php

@ -160,6 +160,24 @@ function handleDatabase(array $argv) {
} }
} }
function findPullBranch(array $output): ?string {
foreach ($output as $line) {
$parts = preg_split('/\s+/', $line);
if (count($parts) >= 3 && $parts[2] === '(fetch)') {
$remoteName = $parts[0];
$url = $parts[1];
if (endsWith($url, "@github.com:rhergenreder/web-base.git") ||
endsWith($url, "@romanh.de:Projekte/web-base.git") ||
$url === 'https://github.com/rhergenreder/web-base.git' ||
$url === 'https://git.romanh.de/Projekte/web-base.git') {
return "$remoteName/master";
}
}
}
return null;
}
function onMaintenance(array $argv) { function onMaintenance(array $argv) {
$action = $argv[2] ?? "status"; $action = $argv[2] ?? "status";
$maintenanceFile = "MAINTENANCE"; $maintenanceFile = "MAINTENANCE";
@ -180,9 +198,21 @@ function onMaintenance(array $argv) {
_exit("Maintenance disabled"); _exit("Maintenance disabled");
} else if ($action === "update") { } else if ($action === "update") {
// TODO: find that dynamically printLine("$ git remote -v");
$pullBranch = "root/master"; exec("git remote -v", $gitRemote, $ret);
$pushBranch = "origin/master"; if ($ret !== 0) {
die();
}
$pullBranch = findPullBranch($gitRemote);
if ($pullBranch === null) {
$pullBranch = 'origin/master';
printLine("Unable to find remote update branch. Make sure, you are still in a git repository, and one of the remote branches " .
"have the original fetch url");
printLine("Trying to continue with '$pullBranch'");
} else {
printLine("Using remote update branch: $pullBranch");
}
printLine("$ git fetch " . str_replace("/", " ", $pullBranch)); printLine("$ git fetch " . str_replace("/", " ", $pullBranch));
exec("git fetch " . str_replace("/", " ", $pullBranch), $gitFetch, $ret); exec("git fetch " . str_replace("/", " ", $pullBranch), $gitFetch, $ret);
@ -205,12 +235,6 @@ function onMaintenance(array $argv) {
_exit("You have uncommitted changes. Please commit them before updating."); _exit("You have uncommitted changes. Please commit them before updating.");
} }
printLine("$ git rev-list HEAD...$pushBranch --ignore-submodules --count");
exec("git rev-list HEAD...$pushBranch --ignore-submodules --count", $gitRevList, $ret);
if ($ret !== 0) {
_exit("HEAD is behind your local branch. Please push your commits before updating.");
}
// enable maintenance mode if it wasn't turned on before // enable maintenance mode if it wasn't turned on before
if (!$isMaintenanceEnabled) { if (!$isMaintenanceEnabled) {
printLine("Turning on maintenance mode"); printLine("Turning on maintenance mode");

@ -1,6 +1,6 @@
<?php <?php
define("WEBBASE_VERSION", "1.2.3"); define("WEBBASE_VERSION", "1.2.4");
spl_autoload_extensions(".php"); spl_autoload_extensions(".php");
spl_autoload_register(function($class) { spl_autoload_register(function($class) {