Skip to content

Commit

Permalink
Merge pull request #13 from algorhythm/master
Browse files Browse the repository at this point in the history
Add Laravel Sail support
  • Loading branch information
indy2kro authored Oct 31, 2024
2 parents 9517dd2 + d52e5e9 commit 987499b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 16 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 25 additions & 11 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' => env('GITHOOKS_USE_SAIL', false),

/*
|--------------------------------------------------------------------------
| Validate paths
Expand All @@ -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
Expand Down Expand Up @@ -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
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 987499b

Please sign in to comment.