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(git): handle Git redirects and improve URL parsing for tangled.sh and other Git hosts
Andras Bacsaibf0040597194
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.phpindex eafd25e07c..8e5b32d1c0 100644--- a/app/Jobs/ApplicationDeploymentJob.php+++ b/app/Jobs/ApplicationDeploymentJob.php@@ -1892,9 +1892,27 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue);}if ($this->saved_outputs->get('git_commit_sha') && ! $this->rollback) {- $this->commit = $this->saved_outputs->get('git_commit_sha')->before("\t");- $this->application_deployment_queue->commit = $this->commit;- $this->application_deployment_queue->save();+ // Extract commit SHA from git ls-remote output, handling multi-line output (e.g., redirect warnings)+ // Expected format: "commit_sha\trefs/heads/branch" possibly preceded by warning lines+ // Note: Git warnings can be on the same line as the result (no newline)+ $lsRemoteOutput = $this->saved_outputs->get('git_commit_sha');++ // Find the part containing a tab (the actual ls-remote result)+ // Handle cases where warning is on the same line as the result+ if ($lsRemoteOutput->contains("\t")) {+ // Get everything from the last occurrence of a valid commit SHA pattern before the tab+ // A valid commit SHA is 40 hex characters+ $output = $lsRemoteOutput->value();++ // Extract the line with the tab (actual ls-remote result)+ preg_match('/([0-9a-f]{40})\s*\t/', $output, $matches);++ if (isset($matches[1])) {+ $this->commit = $matches[1];+ $this->application_deployment_queue->commit = $this->commit;+ $this->application_deployment_queue->save();+ }+ }}$this->set_coolify_variables();diff --git a/app/Models/Application.php b/app/Models/Application.phpindex 595ba1cde6..3e4b22db06 100644--- a/app/Models/Application.php+++ b/app/Models/Application.php@@ -1305,7 +1305,8 @@ class Application extends BaseModel}if ($this->deploymentType() === 'other') {$fullRepoUrl = $customRepository;- $git_clone_command = "{$git_clone_command} {$customRepository} {$baseDir}";+ $escapedCustomRepository = escapeshellarg($customRepository);+ $git_clone_command = "{$git_clone_command} {$escapedCustomRepository} {$escapedBaseDir}";$git_clone_command = $this->setGitImportSettings($deployment_uuid, $git_clone_command, public: true);if ($pull_request_id !== 0) {diff --git a/tests/Unit/GitLsRemoteParsingTest.php b/tests/Unit/GitLsRemoteParsingTest.phpnew file mode 100644index 0000000000..f4fd2e881b--- /dev/null+++ b/tests/Unit/GitLsRemoteParsingTest.php@@ -0,0 +1,49 @@+<?php++uses(\Tests\TestCase::class);++it('extracts commit SHA from git ls-remote output without warnings', function () {+ $output = "196d3df7665359a8c8fa3329a6bcde0267e550bf\trefs/heads/master";++ preg_match('/([0-9a-f]{40})\s*\t/', $output, $matches);+ $commit = $matches[1] ?? null;++ expect($commit)->toBe('196d3df7665359a8c8fa3329a6bcde0267e550bf');+});++it('extracts commit SHA from git ls-remote output with redirect warning on separate line', function () {+ $output = "warning: redirecting to https://tangled.org/@tangled.org/core/\n196d3df7665359a8c8fa3329a6bcde0267e550bf\trefs/heads/master";++ preg_match('/([0-9a-f]{40})\s*\t/', $output, $matches);+ $commit = $matches[1] ?? null;++ expect($commit)->toBe('196d3df7665359a8c8fa3329a6bcde0267e550bf');+});++it('extracts commit SHA from git ls-remote output with redirect warning on same line', function () {+ // This is the actual format from tangled.sh - warning and result on same line, no newline+ $output = "warning: redirecting to https://tangled.org/@tangled.org/core/196d3df7665359a8c8fa3329a6bcde0267e550bf\trefs/heads/master";++ preg_match('/([0-9a-f]{40})\s*\t/', $output, $matches);+ $commit = $matches[1] ?? null;++ expect($commit)->toBe('196d3df7665359a8c8fa3329a6bcde0267e550bf');+});++it('extracts commit SHA from git ls-remote output with multiple warning lines', function () {+ $output = "warning: redirecting to https://example.org/repo/\ninfo: some other message\n196d3df7665359a8c8fa3329a6bcde0267e550bf\trefs/heads/main";++ preg_match('/([0-9a-f]{40})\s*\t/', $output, $matches);+ $commit = $matches[1] ?? null;++ expect($commit)->toBe('196d3df7665359a8c8fa3329a6bcde0267e550bf');+});++it('handles git ls-remote output with extra whitespace', function () {+ $output = " 196d3df7665359a8c8fa3329a6bcde0267e550bf \trefs/heads/master";++ preg_match('/([0-9a-f]{40})\s*\t/', $output, $matches);+ $commit = $matches[1] ?? null;++ expect($commit)->toBe('196d3df7665359a8c8fa3329a6bcde0267e550bf');+});