Skip to content

[5.x] Add push options to git push process #9401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 2 additions & 0 deletions config/git.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@

'push' => env('STATAMIC_GIT_PUSH', false),

'push_options' => [],

/*
|--------------------------------------------------------------------------
| Ignored Events
Expand Down
7 changes: 6 additions & 1 deletion src/Console/Processes/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ public function status($subPaths = null)
*/
public function push()
{
return $this->runGitCommand('push', '--porcelain');
$pushOptions = collect(config('statamic.git.push_options'))
->map(fn ($item, $key) => is_int($key) ? $item : implode('=', [$key, $item]))
->map(fn ($item) => implode(' ', ['-o', $item]))
->flatten();

return $this->runGitCommand('push', '--porcelain', $pushOptions);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/Git/GitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,24 @@ public function it_can_push_after_a_commit()
Git::commit();
}

/** @test */
public function it_can_push_with_push_options()
{
Git::shouldReceive('push')->once();
Git::makePartial();

Config::set('statamic.git.push', true);

Config::set('statamic.git.push_options', [
'merge_request.create',
'merge_request.target' => 'develop',
]);

$this->files->put(base_path('content/collections/pages.yaml'), 'title: Pages Title Changed');

Git::commit();
}

private function showLastCommit($path)
{
return Process::create($path)->run('git show');
Expand Down
Loading