Skip to content

Commit

Permalink
[5.x] Provide git binary var to commands array in config (#10154)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseleite authored May 22, 2024
1 parent f9778b4 commit 4632d38
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
6 changes: 3 additions & 3 deletions config/git.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
|
*/

'binary' => $binary = env('STATAMIC_GIT_BINARY', 'git'),
'binary' => env('STATAMIC_GIT_BINARY', 'git'),

/*
|--------------------------------------------------------------------------
Expand All @@ -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 }}"',
],

/*
Expand Down
1 change: 1 addition & 0 deletions src/Git/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
2 changes: 1 addition & 1 deletion tests/Git/Concerns/PreparesTempRepos.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]" commit -m "Initial commit."');

Expand Down
27 changes: 27 additions & 0 deletions tests/Git/GitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 4632d38

Please sign in to comment.