Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/Actions/Site/UpdateBranch.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
class UpdateBranch
{
/**
* With modern deployment the site path is the live release, so the branch
* is switched in the source checkout and the next deployment clones it.
*
* @param array<string, mixed> $input
*
* @throws SSHError
Expand All @@ -21,8 +24,9 @@ public function update(Site $site, array $input): void
])->validate();

$site->branch = $input['branch'];
app(Git::class)->fetchOrigin($site);
app(Git::class)->checkout($site);
$path = $site->modernDeploymentEnabled() ? $site->basePath().'/source' : null;
app(Git::class)->fetchOrigin($site, $path);
app(Git::class)->checkout($site, $path);
$site->save();
}
}
8 changes: 4 additions & 4 deletions app/SSH/OS/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public function clone(Site $site, ?string $path = null): void
/**
* @throws SSHError
*/
public function checkout(Site $site): void
public function checkout(Site $site, ?string $path = null): void
{
$site->server->ssh($site->user)->exec(
view('ssh.git.checkout', [
'path' => escapeshellarg((string) $site->path),
'path' => escapeshellarg((string) ($path ?? $site->path)),
'branch' => escapeshellarg((string) $site->branch),
]),
'checkout-branch',
Expand All @@ -53,7 +53,7 @@ public function checkout(Site $site): void
/**
* @throws SSHError
*/
public function fetchOrigin(Site $site): void
public function fetchOrigin(Site $site, ?string $path = null): void
{
$ssh = $site->server->ssh($site->user);

Expand All @@ -63,7 +63,7 @@ public function fetchOrigin(Site $site): void

$ssh->exec(
view('ssh.git.fetch-origin', [
'path' => escapeshellarg((string) $site->path),
'path' => escapeshellarg((string) ($path ?? $site->path)),
]),
'fetch-origin',
$site->id
Expand Down
29 changes: 29 additions & 0 deletions tests/Feature/SitesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,35 @@
SSH::assertExecutedContains("git checkout -f 'master'");
});

test('change branch with modern deployment checks out the source, not the live release', function () {
SSH::fake();

$this->site->update([
'path' => '/home/vito/vito.test/current',
'type_data' => [
'modern_deployment' => true,
'modern_deployment_history' => 10,
'modern_deployment_shared_resources' => ['.env', 'storage'],
],
]);

$this->actingAs($this->user);

$this->patch(route('site-settings.update-branch', [
'server' => $this->server->id,
'site' => $this->site,
]), [
'branch' => 'develop',
])
->assertSessionDoesntHaveErrors();

expect($this->site->refresh()->branch)->toEqual('develop');

SSH::assertExecutedContains("cd '/home/vito/vito.test/source'");
SSH::assertExecutedContains("git checkout -f 'develop'");
SSH::assertNotExecutedContains("cd '/home/vito/vito.test/current'");
});

test('update web directory', function () {
SSH::fake();

Expand Down
Loading