Skip to content

Commit 45b0831

Browse files
authored
Merge pull request #1 from algorhythm/feature/sail-support
Füge Unterstützung für Laravel Sail hinzu
2 parents 54bf0c5 + 0568e8b commit 45b0831

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

config/git-hooks.php

Lines changed: 14 additions & 0 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' => false,
270+
257271
/*
258272
|--------------------------------------------------------------------------
259273
| Validate paths

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)