diff --git a/README.md b/README.md index 3f71379..1268ac6 100644 --- a/README.md +++ b/README.md @@ -144,13 +144,22 @@ There are also several debug options which can be adjusted using the following p */ 'debug_output' => false, ``` +### Laravel Sail support + +If you are using Laravel Sail and maybe not lokal PHP is installed, you can adjust the following parameters in the git-hooks.php config file: + +```php + 'use_sail' => env('GITHOOKS_USE_SAIL', false), +``` +This will force the local git hooks to use the `sail` command to execute the hooks. + ### Docker support By default commands are executed locally, however this behavior can be adjusted for each hook using the parameters `run_in_docker` and `docker_container`: ```php - 'run_in_docker' => env('LARAVEL_PINT_RUN_IN_DOCKER', true), - 'docker_container' => env('LARAVEL_PINT_DOCKER_CONTAINER', 'app'), + 'run_in_docker' => env('LARAVEL_PINT_RUN_IN_DOCKER', true), + 'docker_container' => env('LARAVEL_PINT_DOCKER_CONTAINER', 'app'), ``` ### Creating Custom Git Hooks diff --git a/config/git-hooks.php b/config/git-hooks.php index 9ca1b30..ecb3952 100644 --- a/config/git-hooks.php +++ b/config/git-hooks.php @@ -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' => env('GITHOOKS_USE_SAIL', false), + /* |-------------------------------------------------------------------------- | Validate paths @@ -278,17 +292,6 @@ */ 'analyzer_chunk_size' => env('GITHOOKS_ANALYZER_CHUNK_SIZE', 100), - /* - |-------------------------------------------------------------------------- - | Output errors - |-------------------------------------------------------------------------- - | - | This configuration option allows you output any errors encountered - | during execution directly for easy debug. - | - */ - 'output_errors' => env('GITHOOKS_OUTPUT_ERRORS', false), - /* |-------------------------------------------------------------------------- | Automatically fix errors @@ -323,6 +326,17 @@ */ 'stop_at_first_analyzer_failure' => env('GITHOOKS_STOP_AT_FIRST_ANALYZER_FAILURE', true), + /* + |-------------------------------------------------------------------------- + | Output errors + |-------------------------------------------------------------------------- + | + | This configuration option allows you output any errors encountered + | during execution directly for easy debug. + | + */ + 'output_errors' => env('GITHOOKS_OUTPUT_ERRORS', false), + /* |-------------------------------------------------------------------------- | Debug commands diff --git a/src/Console/Commands/stubs/hook b/src/Console/Commands/stubs/hook index df94d95..2cfa70e 100644 --- a/src/Console/Commands/stubs/hook +++ b/src/Console/Commands/stubs/hook @@ -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 diff --git a/src/GitHooks.php b/src/GitHooks.php index 077bc22..938a92e 100644 --- a/src/GitHooks.php +++ b/src/GitHooks.php @@ -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); }