From 36776fe7e1a971791478297a35e3bf0dab41327a Mon Sep 17 00:00:00 2001 From: Jan Henk Hazelaar Date: Thu, 25 Jan 2024 22:00:04 +0100 Subject: [PATCH 1/3] Add push option to git push process --- config/git.php | 12 ++++++++++++ src/Console/Processes/Git.php | 7 ++++++- tests/Git/GitTest.php | 19 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/config/git.php b/config/git.php index 3a9aaad118..fcf409ecdc 100644 --- a/config/git.php +++ b/config/git.php @@ -150,6 +150,18 @@ 'push' => env('STATAMIC_GIT_PUSH', false), + /* + |-------------------------------------------------------------------------- + | Push options + |-------------------------------------------------------------------------- + | + | Determine the git push options to be added when pushing to + | repository. This is an empty array by default. + | + */ + + 'push_options' => [], + /* |-------------------------------------------------------------------------- | Ignored Events diff --git a/src/Console/Processes/Git.php b/src/Console/Processes/Git.php index 5ba0f23014..e4db802d78 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..7098ea74f0 100644 --- a/tests/Git/GitTest.php +++ b/tests/Git/GitTest.php @@ -346,6 +346,25 @@ 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'); From 519edbc78b7ea37ffddbba2f804bf478940e2d92 Mon Sep 17 00:00:00 2001 From: Jan Henk Hazelaar Date: Thu, 25 Jan 2024 22:10:08 +0100 Subject: [PATCH 2/3] Pint --- src/Console/Processes/Git.php | 4 ++-- tests/Git/GitTest.php | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Console/Processes/Git.php b/src/Console/Processes/Git.php index e4db802d78..29c45fa00b 100644 --- a/src/Console/Processes/Git.php +++ b/src/Console/Processes/Git.php @@ -47,8 +47,8 @@ public function status($subPaths = null) public function push() { $pushOptions = collect(config('statamic.git.push_options')) - ->map(fn($item, $key) => is_int($key) ? $item : implode("=", [$key, $item])) - ->map(fn($item) => implode(" ", ["-o", $item])) + ->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 7098ea74f0..a1c3f9f83f 100644 --- a/tests/Git/GitTest.php +++ b/tests/Git/GitTest.php @@ -356,7 +356,7 @@ public function it_can_push_with_push_options() Config::set('statamic.git.push_options', [ 'merge_request.create', - 'merge_request.target' => 'develop' + 'merge_request.target' => 'develop', ]); $this->files->put(base_path('content/collections/pages.yaml'), 'title: Pages Title Changed'); @@ -364,7 +364,6 @@ public function it_can_push_with_push_options() Git::commit(); } - private function showLastCommit($path) { return Process::create($path)->run('git show'); From b5667e56bd9921d9d48f02906095c1b40af379e3 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Fri, 26 Jan 2024 16:32:29 -0500 Subject: [PATCH 3/3] Just put under current 'push' comment block. --- config/git.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/config/git.php b/config/git.php index fcf409ecdc..0ea3c20f0a 100644 --- a/config/git.php +++ b/config/git.php @@ -150,16 +150,6 @@ 'push' => env('STATAMIC_GIT_PUSH', false), - /* - |-------------------------------------------------------------------------- - | Push options - |-------------------------------------------------------------------------- - | - | Determine the git push options to be added when pushing to - | repository. This is an empty array by default. - | - */ - 'push_options' => [], /*