diff --git a/app/Livewire/Project/New/PublicGitRepository.php b/app/Livewire/Project/New/PublicGitRepository.php
index 62ac7ec0d..dbfa15a55 100644
--- a/app/Livewire/Project/New/PublicGitRepository.php
+++ b/app/Livewire/Project/New/PublicGitRepository.php
@@ -208,13 +208,8 @@ private function getGitSource()
if ($this->repository_url_parsed->getSegment(3) === 'tree') {
$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 = '/';
- }
+ $this->git_branch = str($path)->after('tree/')->value();
+ $this->base_directory = '/';
} else {
$this->git_branch = 'main';
}
@@ -235,9 +230,32 @@ private function getBranch()
return;
}
if ($this->git_source->getMorphClass() === GithubApp::class) {
- ['rate_limit_remaining' => $this->rate_limit_remaining, 'rate_limit_reset' => $this->rate_limit_reset] = githubApi(source: $this->git_source, endpoint: "/repos/{$this->git_repository}/branches/{$this->git_branch}");
- $this->rate_limit_reset = Carbon::parse((int) $this->rate_limit_reset)->format('Y-M-d H:i:s');
- $this->branchFound = true;
+ $originalBranch = $this->git_branch;
+ $branchToTry = $originalBranch;
+
+ while (true) {
+ try {
+ $encodedBranch = urlencode($branchToTry);
+ ['rate_limit_remaining' => $this->rate_limit_remaining, 'rate_limit_reset' => $this->rate_limit_reset] = githubApi(source: $this->git_source, endpoint: "/repos/{$this->git_repository}/branches/{$encodedBranch}");
+ $this->rate_limit_reset = Carbon::parse((int) $this->rate_limit_reset)->format('Y-M-d H:i:s');
+ $this->git_branch = $branchToTry;
+
+ $remaining = str($originalBranch)->after($branchToTry)->trim('/')->value();
+ $this->base_directory = filled($remaining) ? '/'.$remaining : '/';
+
+ $this->branchFound = true;
+
+ return;
+ } catch (\Throwable $e) {
+ if (str_contains($branchToTry, '/')) {
+ $branchToTry = str($branchToTry)->beforeLast('/')->value();
+
+ continue;
+ }
+
+ throw $e;
+ }
+ }
}
}
diff --git a/resources/views/livewire/project/shared/environment-variable/all.blade.php b/resources/views/livewire/project/shared/environment-variable/all.blade.php
index 28c67c5b4..2ae3ad166 100644
--- a/resources/views/livewire/project/shared/environment-variable/all.blade.php
+++ b/resources/views/livewire/project/shared/environment-variable/all.blade.php
@@ -84,21 +84,21 @@
Inline comments with space before # (e.g., KEY=value #comment) are stripped.
-