]> BookStack Code Mirror - system-cli/commitdiff
Added check and warning for updating non-git-managed instances
authorDan Brown <redacted>
Sat, 6 May 2023 10:31:20 +0000 (11:31 +0100)
committerDan Brown <redacted>
Sat, 6 May 2023 10:31:20 +0000 (11:31 +0100)
Closes #5
Added test to cover.

src/Commands/UpdateCommand.php
tests/Commands/UpdateCommandTest.php

index 5475aaa9f0cc747199359023aeafb3c5ee75d024..02cf3c6ccb9452416d3d0632e7881e7f39f314f8 100644 (file)
@@ -5,6 +5,7 @@ namespace Cli\Commands;
 use Cli\Services\AppLocator;
 use Cli\Services\ArtisanRunner;
 use Cli\Services\ComposerLocator;
+use Cli\Services\Paths;
 use Cli\Services\ProgramRunner;
 use Cli\Services\RequirementsValidator;
 use Symfony\Component\Console\Command\Command;
@@ -30,6 +31,9 @@ class UpdateCommand extends Command
         $output->writeln("<info>Checking system requirements...</info>");
         RequirementsValidator::validate();
 
+        $output->writeln("<info>Checking local Git repository is active...</info>");
+        $this->ensureGitRepoExists($appDir);
+
         $output->writeln("<info>Checking composer exists...</info>");
         $composerLocator = new ComposerLocator($appDir);
         $composer = $composerLocator->getProgram();
@@ -91,4 +95,16 @@ class UpdateCommand extends Command
             throw new CommandError("Failed composer install with errors:\n" . $errors);
         }
     }
+
+    protected function ensureGitRepoExists(string $appDir): void
+    {
+        $expectedPath = Paths::join($appDir, '.git');
+        if (!is_dir($expectedPath)) {
+            $message = "Could not find a local git repository, it does not look like this instance is managed via common means.\n";
+            $message .= "If you are running BookStack via a docker container, you should update following the advised process for the docker container image in use.\n";
+            $message .= "This typically involves pulling and using an updated docker container image.";
+
+            throw new CommandError($message);
+        }
+    }
 }
index f60398c39c5687770e8f8ba4da95bb3b84c102a3..d0d0f2e4d6bf71ad1f55c613248e387024d08120 100644 (file)
@@ -43,6 +43,20 @@ class UpdateCommandTest extends TestCase
         $result->assertStderrContains('Could not find a valid BookStack installation');
     }
 
+    public function test_command_rejects_on_no_git_repo_found()
+    {
+        exec('cp -r /var/www/bookstack /var/www/bookstack-update-git');
+        exec('rm -rf /var/www/bookstack-update-git/.git');
+        chdir('/var/www/bookstack-update-git');
+
+        $result = $this->runCommand('update');
+        $result->assertErrorExit();
+        $result->assertStderrContains("Could not find a local git repository");
+        $result->assertStderrContains("If you are running BookStack via a docker container");
+
+        exec('rm -rf /var/www/bookstack-update-git');
+    }
+
     public function test_command_can_be_provided_app_directory_option()
     {
         chdir('/home');