vito/app/SSH/Git/Git.php
Dimitar Yanakiev e52903c649
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.
2025-02-28 19:38:38 +01:00

57 lines
1.3 KiB
PHP

<?php
namespace App\SSH\Git;
use App\Exceptions\SSHError;
use App\Models\Site;
class Git
{
/**
* @throws SSHError
*/
public function clone(Site $site): void
{
$site->server->ssh($site->user)->exec(
view('ssh.git.clone', [
'host' => str($site->getFullRepositoryUrl())->after('@')->before('-'),
'repo' => $site->getFullRepositoryUrl(),
'path' => $site->path,
'branch' => $site->branch,
'key' => $site->getSshKeyName(),
]),
'clone-repository',
$site->id
);
}
/**
* @throws SSHError
*/
public function checkout(Site $site): void
{
$site->server->ssh($site->user)->exec(
view('ssh.git.checkout', [
'path' => $site->path,
'branch' => $site->branch,
]),
'checkout-branch',
$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
);
}
}