From e52903c64989fac622ee8c5ac064a046dbbc6483 Mon Sep 17 00:00:00 2001 From: Dimitar Yanakiev Date: Fri, 28 Feb 2025 20:38:38 +0200 Subject: [PATCH] fix: ensure newly created branches are available for switching (#511) Fixed an issue where the "Change Branch" button didn't work when switching to a newly created remote branch after initially cloning the repository. Added `git fetch origin` to update branch references before switching. --- app/Actions/Site/UpdateBranch.php | 1 + app/SSH/Git/Git.php | 14 ++++++++++++++ resources/views/ssh/git/fetch-origin.blade.php | 7 +++++++ 3 files changed, 22 insertions(+) create mode 100644 resources/views/ssh/git/fetch-origin.blade.php diff --git a/app/Actions/Site/UpdateBranch.php b/app/Actions/Site/UpdateBranch.php index 94af0bf..0e2c5dd 100755 --- a/app/Actions/Site/UpdateBranch.php +++ b/app/Actions/Site/UpdateBranch.php @@ -16,6 +16,7 @@ class UpdateBranch public function update(Site $site, array $input): void { $site->branch = $input['branch']; + app(Git::class)->fetchOrigin($site); app(Git::class)->checkout($site); $site->save(); } diff --git a/app/SSH/Git/Git.php b/app/SSH/Git/Git.php index 21ea0b1..57d4313 100644 --- a/app/SSH/Git/Git.php +++ b/app/SSH/Git/Git.php @@ -39,4 +39,18 @@ public function checkout(Site $site): void $site->id ); } + + /** + * @throws SSHError + */ + public function fetchOrigin(Site $site): void + { + $site->server->ssh($site->user)->exec( + view('ssh.git.fetch-origin', [ + 'path' => $site->path, + ]), + 'fetch-origin', + $site->id + ); + } } diff --git a/resources/views/ssh/git/fetch-origin.blade.php b/resources/views/ssh/git/fetch-origin.blade.php new file mode 100644 index 0000000..4b55c64 --- /dev/null +++ b/resources/views/ssh/git/fetch-origin.blade.php @@ -0,0 +1,7 @@ +if ! cd {{ $path }}; then + echo 'VITO_SSH_ERROR' && exit 1 +fi + +if ! git fetch origin; then + echo 'VITO_SSH_ERROR' && exit 1 +fi