From 83f0f9fca42502662836618f2210fabed0cc0cdd Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 31 Jan 2025 18:17:00 +0100 Subject: [PATCH] fix(core): improve public repository URL parsing for branch and base directory --- app/Livewire/Project/New/PublicGitRepository.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/Livewire/Project/New/PublicGitRepository.php b/app/Livewire/Project/New/PublicGitRepository.php index 2f2331fc0..45b3b5726 100644 --- a/app/Livewire/Project/New/PublicGitRepository.php +++ b/app/Livewire/Project/New/PublicGitRepository.php @@ -188,11 +188,22 @@ class PublicGitRepository extends Component private function getGitSource() { + $this->git_branch = 'main'; + $this->base_directory = '/'; + $this->repository_url_parsed = Url::fromString($this->repository_url); $this->git_host = $this->repository_url_parsed->getHost(); $this->git_repository = $this->repository_url_parsed->getSegment(1).'/'.$this->repository_url_parsed->getSegment(2); + if ($this->repository_url_parsed->getSegment(3) === 'tree') { - $this->git_branch = str($this->repository_url_parsed->getPath())->after('tree/')->value(); + $path = str($this->repository_url_parsed->getPath())->trim('/'); + $this->git_branch = str($path)->after('tree/')->before('/')->value(); + $this->base_directory = str($path)->after($this->git_branch)->after('/')->value(); + if (filled($this->base_directory)) { + $this->base_directory = '/'.$this->base_directory; + } else { + $this->base_directory = '/'; + } } else { $this->git_branch = 'main'; }