From 4632d388d6e360cfd72dd2eb4f642bbc66bae8f3 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Wed, 22 May 2024 10:57:29 -0400 Subject: [PATCH] [5.x] Provide git binary var to commands array in config (#10154) --- config/git.php | 6 +++--- src/Git/Git.php | 1 + tests/Git/Concerns/PreparesTempRepos.php | 2 +- tests/Git/GitTest.php | 27 ++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/config/git.php b/config/git.php index 4d0a78a4e5..80d2a3b6de 100644 --- a/config/git.php +++ b/config/git.php @@ -116,7 +116,7 @@ | */ - 'binary' => $binary = env('STATAMIC_GIT_BINARY', 'git'), + 'binary' => env('STATAMIC_GIT_BINARY', 'git'), /* |-------------------------------------------------------------------------- @@ -132,8 +132,8 @@ */ 'commands' => [ - $binary.' add {{ paths }}', - $binary.' -c "user.name={{ name }}" -c "user.email={{ email }}" commit -m "{{ message }}"', + '{{ git }} add {{ paths }}', + '{{ git }} -c "user.name={{ name }}" -c "user.email={{ email }}" commit -m "{{ message }}"', ], /* diff --git a/src/Git/Git.php b/src/Git/Git.php index 10215cfeaa..a328a7dffc 100644 --- a/src/Git/Git.php +++ b/src/Git/Git.php @@ -254,6 +254,7 @@ protected function getParsedCommands($paths, $message) protected function getCommandContext($paths, $message) { return [ + 'git' => config('statamic.git.binary'), 'paths' => collect($paths)->implode(' '), 'message' => $this->shellEscape($message), 'name' => $this->shellEscape($this->gitUserName()), diff --git a/tests/Git/Concerns/PreparesTempRepos.php b/tests/Git/Concerns/PreparesTempRepos.php index cd035a408a..bc46a15dec 100644 --- a/tests/Git/Concerns/PreparesTempRepos.php +++ b/tests/Git/Concerns/PreparesTempRepos.php @@ -38,7 +38,7 @@ protected function createTempRepo($path) $process = Process::create($path); - $process->run('git init'); + $process->run('git init -b master'); $process->run('git add --all'); $process->run('git -c "user.name=Tests" -c "user.email=tests@example.com" commit -m "Initial commit."'); diff --git a/tests/Git/GitTest.php b/tests/Git/GitTest.php index 59eeaabaeb..28eec0d611 100644 --- a/tests/Git/GitTest.php +++ b/tests/Git/GitTest.php @@ -298,6 +298,33 @@ public function it_can_run_custom_commands() Spock committed. Spock committed. +EOT; + + $this->assertEquals($expectedLog, $this->files->get($logFile)); + } + + /** @test */ + public function it_can_run_custom_commands_with_custom_git_binary() + { + $this->markTestSkippedInWindows(); + + $this->files->put($logFile = $this->basePath('temp/log.txt'), ''); + + Config::set('statamic.git.binary', 'the custom git binary'); + + Config::set('statamic.git.commands', [ + 'echo "{{ name }} committed using {{ git }}." >> '.$logFile, + ]); + + Git::partialMock() + ->shouldReceive('groupTrackedContentPathsByRepo') + ->andReturn(collect([base_path('content') => collect(['foo'])])); + + Git::commit(); + + $expectedLog = <<<'EOT' +Spock committed using the custom git binary. + EOT; $this->assertEquals($expectedLog, $this->files->get($logFile));