diff --git a/config/git.php b/config/git.php index f6a3e6427d..2fcbcdcb5a 100644 --- a/config/git.php +++ b/config/git.php @@ -151,6 +151,8 @@ 'push' => env('STATAMIC_GIT_PUSH', false), + 'push_options' => [], + /* |-------------------------------------------------------------------------- | Ignored Events diff --git a/src/Console/Processes/Git.php b/src/Console/Processes/Git.php index f758a25eb1..be4f9a60b7 100644 --- a/src/Console/Processes/Git.php +++ b/src/Console/Processes/Git.php @@ -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); } /** diff --git a/tests/Git/GitTest.php b/tests/Git/GitTest.php index 59eeaabaeb..a1c3f9f83f 100644 --- a/tests/Git/GitTest.php +++ b/tests/Git/GitTest.php @@ -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');