An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
fix: application rollback uses correct commit sha
Tjeerd Smid193540305394
diff --git a/app/Models/Application.php b/app/Models/Application.phpindex 28ef790786..e31cf74e46 100644--- a/app/Models/Application.php+++ b/app/Models/Application.php@@ -1085,19 +1085,21 @@ class Application extends BaseModelreturn application_configuration_dir()."/{$this->uuid}";}- public function setGitImportSettings(string $deployment_uuid, string $git_clone_command, bool $public = false)+ public function setGitImportSettings(string $deployment_uuid, string $git_clone_command, bool $public = false, ?string $commit = null){$baseDir = $this->generateBaseDir($deployment_uuid);$escapedBaseDir = escapeshellarg($baseDir);$isShallowCloneEnabled = $this->settings?->is_git_shallow_clone_enabled ?? false;- if ($this->git_commit_sha !== 'HEAD') {+ $commitToUse = $commit ?? $this->git_commit_sha;++ if ($commitToUse !== 'HEAD') {// If shallow clone is enabled and we need a specific commit,// we need to fetch that specific commit with depth=1if ($isShallowCloneEnabled) {- $git_clone_command = "{$git_clone_command} && cd {$escapedBaseDir} && GIT_SSH_COMMAND=\"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\" git fetch --depth=1 origin {$this->git_commit_sha} && git -c advice.detachedHead=false checkout {$this->git_commit_sha} >/dev/null 2>&1";+ $git_clone_command = "{$git_clone_command} && cd {$escapedBaseDir} && GIT_SSH_COMMAND=\"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\" git fetch --depth=1 origin {$commitToUse} && git -c advice.detachedHead=false checkout {$commitToUse} >/dev/null 2>&1";} else {- $git_clone_command = "{$git_clone_command} && cd {$escapedBaseDir} && GIT_SSH_COMMAND=\"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\" git -c advice.detachedHead=false checkout {$this->git_commit_sha} >/dev/null 2>&1";+ $git_clone_command = "{$git_clone_command} && cd {$escapedBaseDir} && GIT_SSH_COMMAND=\"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\" git -c advice.detachedHead=false checkout {$commitToUse} >/dev/null 2>&1";}}if ($this->settings->is_git_submodules_enabled) {@@ -1285,7 +1287,7 @@ class Application extends BaseModel$escapedRepoUrl = escapeshellarg("{$this->source->html_url}/{$customRepository}");$git_clone_command = "{$git_clone_command} {$escapedRepoUrl} {$escapedBaseDir}";if (! $only_checkout) {- $git_clone_command = $this->setGitImportSettings($deployment_uuid, $git_clone_command, public: true);+ $git_clone_command = $this->setGitImportSettings($deployment_uuid, $git_clone_command, public: true, commit: $commit);}if ($exec_in_docker) {$commands->push(executeInDocker($deployment_uuid, $git_clone_command));@@ -1306,7 +1308,7 @@ class Application extends BaseModel$fullRepoUrl = $repoUrl;}if (! $only_checkout) {- $git_clone_command = $this->setGitImportSettings($deployment_uuid, $git_clone_command, public: false);+ $git_clone_command = $this->setGitImportSettings($deployment_uuid, $git_clone_command, public: false, commit: $commit);}if ($exec_in_docker) {$commands->push(executeInDocker($deployment_uuid, $git_clone_command));@@ -1345,7 +1347,7 @@ class Application extends BaseModelif ($only_checkout) {$git_clone_command = $git_clone_command_base;} else {- $git_clone_command = $this->setGitImportSettings($deployment_uuid, $git_clone_command_base);+ $git_clone_command = $this->setGitImportSettings($deployment_uuid, $git_clone_command_base, commit: $commit);}if ($exec_in_docker) {$commands = collect([@@ -1403,7 +1405,7 @@ class Application extends BaseModel$fullRepoUrl = $customRepository;$escapedCustomRepository = escapeshellarg($customRepository);$git_clone_command = "{$git_clone_command} {$escapedCustomRepository} {$escapedBaseDir}";- $git_clone_command = $this->setGitImportSettings($deployment_uuid, $git_clone_command, public: true);+ $git_clone_command = $this->setGitImportSettings($deployment_uuid, $git_clone_command, public: true, commit: $commit);if ($pull_request_id !== 0) {if ($git_type === 'gitlab') {diff --git a/tests/Feature/ApplicationRollbackTest.php b/tests/Feature/ApplicationRollbackTest.phpnew file mode 100644index 0000000000..dfb8da0101--- /dev/null+++ b/tests/Feature/ApplicationRollbackTest.php@@ -0,0 +1,55 @@+<?php++use App\Models\Application;+use App\Models\ApplicationSetting;+use App\Models\Environment;+use App\Models\Project;+use App\Models\Server;+use App\Models\Team;+use Illuminate\Foundation\Testing\RefreshDatabase;++uses(RefreshDatabase::class);++describe('Application Rollback', function () {+ test('setGitImportSettings uses passed commit instead of application git_commit_sha', function () {+ $team = Team::factory()->create();+ $project = Project::create([+ 'team_id' => $team->id,+ 'name' => 'Test Project',+ 'uuid' => (string) str()->uuid(),+ ]);+ $environment = Environment::create([+ 'project_id' => $project->id,+ 'name' => 'rollback-test-env',+ 'uuid' => (string) str()->uuid(),+ ]);+ $server = Server::factory()->create(['team_id' => $team->id]);++ // Create application with git_commit_sha = 'HEAD' (default - use latest)+ $application = Application::factory()->create([+ 'environment_id' => $environment->id,+ 'destination_id' => $server->id,+ 'git_commit_sha' => 'HEAD',+ ]);++ // Create application settings+ ApplicationSetting::create([+ 'application_id' => $application->id,+ 'is_git_shallow_clone_enabled' => false,+ ]);++ // The rollback commit SHA we want to deploy+ $rollbackCommit = 'abc123def456';++ // This should use the passed commit, not the application's git_commit_sha+ $result = $application->setGitImportSettings(+ deployment_uuid: 'test-uuid',+ git_clone_command: 'git clone',+ public: true,+ commit: $rollbackCommit+ );++ // Assert: The command should checkout the ROLLBACK commit+ expect($result)->toContain($rollbackCommit);+ });+});