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
4 changes: 2 additions & 2 deletions docs/4.x/prologue/contribution-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ Please do not refactor any existing code without discussing it with the maintain

## Which Branch?

All bug fixes should be sent to the latest version that supports bug fixes (currently `3.x`).
All bug fixes should be sent to the latest version that supports bug fixes (currently `4.x`).

Minor features that are fully backward compatible with the current release may be sent to the latest stable branch (
currently `3.x`).
currently `4.x`).

Major new features or features with breaking changes should always be sent to the `main` branch, which contains the
upcoming major release.
Expand Down
29 changes: 29 additions & 0 deletions tests/Feature/SitesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,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