Skip to content

Commit

Permalink
Merge pull request #1 from algorhythm/feature/sail-support
Browse files Browse the repository at this point in the history
Füge Unterstützung für Laravel Sail hinzu
  • Loading branch information
algorhythm authored Sep 19, 2024
2 parents 54bf0c5 + 0568e8b commit 45b0831
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
14 changes: 14 additions & 0 deletions config/git-hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,20 @@
*/
'artisan_path' => base_path('artisan'),

/*
|--------------------------------------------------------------------------
| Laravel Sail
|--------------------------------------------------------------------------
|
| If you are using Laravel Sail you may not have local PHP or Composer.
|
| This configuration option allows you to use local Git but still run Artisan commands with `sail` in front of them.
|
| The `artisan_path` configuration is ignored.
|
*/
'use_sail' => false,

/*
|--------------------------------------------------------------------------
| Validate paths
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Commands/stubs/hook
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ if sh -c ": >/dev/tty" >/dev/null 2>/dev/null; then
exec < /dev/tty
fi

php {artisanPath} {command} $@ >&2
{php|sail} {artisanPath} {command} $@ >&2
18 changes: 16 additions & 2 deletions src/GitHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,25 @@ public function install(string $hookName): void

$hookPath = $this->getGitHooksDir().'/'.$hookName;
$hookScript = str_replace(
['{command}', '{artisanPath}'],
[$command, config('git-hooks.artisan_path')],
'{command}',
$command,
(string) $this->getHookStub()
);

if (config('git-hooks.use_sail')) {
$hookScript = str_replace(
['{php|sail}', '{artisanPath}'],
['vendor/bin/sail', 'artisan'],
$hookScript
);
} else {
$hookScript = str_replace(
['{php|sail}', '{artisanPath}'],
['php', config('git-hooks.artisan_path')],
$hookScript
);
}

file_put_contents($hookPath, $hookScript);
chmod($hookPath, 0777);
}
Expand Down

0 comments on commit 45b0831

Please sign in to comment.