Skip to content

Commit 987499b

Browse files
authored
Merge pull request #13 from algorhythm/master
Add Laravel Sail support
2 parents 9517dd2 + d52e5e9 commit 987499b

File tree

4 files changed

+53
-16
lines changed

4 files changed

+53
-16
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,22 @@ There are also several debug options which can be adjusted using the following p
144144
*/
145145
'debug_output' => false,
146146
```
147+
### Laravel Sail support
148+
149+
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:
150+
151+
```php
152+
'use_sail' => env('GITHOOKS_USE_SAIL', false),
153+
```
154+
This will force the local git hooks to use the `sail` command to execute the hooks.
155+
147156
### Docker support
148157

149158
By default commands are executed locally, however this behavior can be adjusted for each hook using the parameters `run_in_docker` and `docker_container`:
150159

151160
```php
152-
'run_in_docker' => env('LARAVEL_PINT_RUN_IN_DOCKER', true),
153-
'docker_container' => env('LARAVEL_PINT_DOCKER_CONTAINER', 'app'),
161+
'run_in_docker' => env('LARAVEL_PINT_RUN_IN_DOCKER', true),
162+
'docker_container' => env('LARAVEL_PINT_DOCKER_CONTAINER', 'app'),
154163
```
155164

156165
### Creating Custom Git Hooks

config/git-hooks.php

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,20 @@
254254
*/
255255
'artisan_path' => base_path('artisan'),
256256

257+
/*
258+
|--------------------------------------------------------------------------
259+
| Laravel Sail
260+
|--------------------------------------------------------------------------
261+
|
262+
| If you are using Laravel Sail you may not have local PHP or Composer.
263+
|
264+
| This configuration option allows you to use local Git but still run Artisan commands with `sail` in front of them.
265+
|
266+
| The `artisan_path` configuration is ignored.
267+
|
268+
*/
269+
'use_sail' => env('GITHOOKS_USE_SAIL', false),
270+
257271
/*
258272
|--------------------------------------------------------------------------
259273
| Validate paths
@@ -278,17 +292,6 @@
278292
*/
279293
'analyzer_chunk_size' => env('GITHOOKS_ANALYZER_CHUNK_SIZE', 100),
280294

281-
/*
282-
|--------------------------------------------------------------------------
283-
| Output errors
284-
|--------------------------------------------------------------------------
285-
|
286-
| This configuration option allows you output any errors encountered
287-
| during execution directly for easy debug.
288-
|
289-
*/
290-
'output_errors' => env('GITHOOKS_OUTPUT_ERRORS', false),
291-
292295
/*
293296
|--------------------------------------------------------------------------
294297
| Automatically fix errors
@@ -323,6 +326,17 @@
323326
*/
324327
'stop_at_first_analyzer_failure' => env('GITHOOKS_STOP_AT_FIRST_ANALYZER_FAILURE', true),
325328

329+
/*
330+
|--------------------------------------------------------------------------
331+
| Output errors
332+
|--------------------------------------------------------------------------
333+
|
334+
| This configuration option allows you output any errors encountered
335+
| during execution directly for easy debug.
336+
|
337+
*/
338+
'output_errors' => env('GITHOOKS_OUTPUT_ERRORS', false),
339+
326340
/*
327341
|--------------------------------------------------------------------------
328342
| Debug commands

src/Console/Commands/stubs/hook

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ if sh -c ": >/dev/tty" >/dev/null 2>/dev/null; then
44
exec < /dev/tty
55
fi
66

7-
php {artisanPath} {command} $@ >&2
7+
{php|sail} {artisanPath} {command} $@ >&2

src/GitHooks.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,25 @@ public function install(string $hookName): void
5858

5959
$hookPath = $this->getGitHooksDir().'/'.$hookName;
6060
$hookScript = str_replace(
61-
['{command}', '{artisanPath}'],
62-
[$command, config('git-hooks.artisan_path')],
61+
'{command}',
62+
$command,
6363
(string) $this->getHookStub()
6464
);
6565

66+
if (config('git-hooks.use_sail')) {
67+
$hookScript = str_replace(
68+
['{php|sail}', '{artisanPath}'],
69+
['vendor/bin/sail', 'artisan'],
70+
$hookScript
71+
);
72+
} else {
73+
$hookScript = str_replace(
74+
['{php|sail}', '{artisanPath}'],
75+
['php', config('git-hooks.artisan_path')],
76+
$hookScript
77+
);
78+
}
79+
6680
file_put_contents($hookPath, $hookScript);
6781
chmod($hookPath, 0777);
6882
}

0 commit comments

Comments
 (0)