diff --git a/app/Livewire/Project/New/GithubPrivateRepository.php b/app/Livewire/Project/New/GithubPrivateRepository.php index 5dd508c29..40d2674e2 100644 --- a/app/Livewire/Project/New/GithubPrivateRepository.php +++ b/app/Livewire/Project/New/GithubPrivateRepository.php @@ -128,6 +128,7 @@ public function loadBranches() $this->loadBranchByPage(); } } + $this->branches = sortBranchesByPriority($this->branches); $this->selected_branch_name = data_get($this->branches, '0.name', 'main'); } diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 3d9e9e729..670716164 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -301,6 +301,24 @@ function generate_application_name(string $git_repository, string $git_branch, ? return Str::kebab("$git_repository:$git_branch-$cuid"); } +/** + * Sort branches by priority: main first, master second, then alphabetically. + * + * @param Collection $branches Collection of branch objects with 'name' key + */ +function sortBranchesByPriority(Collection $branches): Collection +{ + return $branches->sortBy(function ($branch) { + $name = data_get($branch, 'name'); + + return match ($name) { + 'main' => '0_main', + 'master' => '1_master', + default => '2_'.$name, + }; + })->values(); +} + function base_ip(): string { if (isDev()) {