From 0568e8b19f1363050ed7c3da7964e72a25748f6e Mon Sep 17 00:00:00 2001 From: Martin Seysen Date: Thu, 19 Sep 2024 11:13:14 +0200 Subject: [PATCH 1/3] =?UTF-8?q?F=C3=BCge=20Unterst=C3=BCtzung=20f=C3=BCr?= =?UTF-8?q?=20Laravel=20Sail=20hinzu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/git-hooks.php | 14 ++++++++++++++ src/Console/Commands/stubs/hook | 2 +- src/GitHooks.php | 18 ++++++++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/config/git-hooks.php b/config/git-hooks.php index 9ca1b30..21134e9 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' => false, + /* |-------------------------------------------------------------------------- | Validate paths 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); } From 0a5a79baa3eef45cc86d0faa23bc7b431b034219 Mon Sep 17 00:00:00 2001 From: Martin Seysen Date: Thu, 19 Sep 2024 16:52:37 +0200 Subject: [PATCH 2/3] Extend README.md with a "Laravel Sail" section --- README.md | 9 +++++++++ config/git-hooks.php | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3f71379..af99356 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,15 @@ 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`: diff --git a/config/git-hooks.php b/config/git-hooks.php index 21134e9..4f5a695 100644 --- a/config/git-hooks.php +++ b/config/git-hooks.php @@ -266,7 +266,7 @@ | The `artisan_path` configuration is ignored. | */ - 'use_sail' => false, + 'use_sail' => env('GITHOOKS_USE_SAIL', false), /* |-------------------------------------------------------------------------- From d52e5e99025430ea46f743d4c656964279ed240b Mon Sep 17 00:00:00 2001 From: Martin Seysen Date: Thu, 19 Sep 2024 16:54:47 +0200 Subject: [PATCH 3/3] Optimize README.md Optimize config order --- README.md | 6 +++--- config/git-hooks.php | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index af99356..1268ac6 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,7 @@ There are also several debug options which can be adjusted using the following p 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), + 'use_sail' => env('GITHOOKS_USE_SAIL', false), ``` This will force the local git hooks to use the `sail` command to execute the hooks. @@ -158,8 +158,8 @@ This will force the local git hooks to use the `sail` command to execute the hoo 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 4f5a695..ecb3952 100644 --- a/config/git-hooks.php +++ b/config/git-hooks.php @@ -292,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 @@ -337,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