Pros:
git-hooks/ or .git-hooks.sh), improving collaboration and reproducibility.core.hooksPath and falls back gracefully for older versions with symlinks/copies..git/hooks/ directory, enabling CI/CD-friendly workflows.Cons:
boot() or console commands)..git-hooks.sh), which may complicate Windows/Laravel Forge/Valet deployments.post-install-cmd/post-update-cmd.php artisan githook:pre-commit from .git-hooks.sh)..git/hooks/ is not writable (symlink fallback required).core.hooksPath is configured and volumes mount the correct directories..git-hooks.sh may break on Windows (Git Bash required) or CI environments without shell access.post-install-cmd) add ~1–2s to deployments if hooks are complex.composer.json setup and proper core.hooksPath permissions..git-hooks.sh)..git/hooks/ is unwritable?symlink: true in composer.json for older Git versions?git:pre-commit) for tighter coupling?app/Console/Kernel.php to run hooks on demand?php artisan hook:pre-commit).GitHookExecuted).laravel-githooks (more Laravel-native but less flexible)..git/hooks/ management (less collaborative)..git/hooks/) and document their purpose.sweetchuck/git-hooks to composer.json (dev dependency).core.hooksPath (e.g., ./git-hooks) and symlink: true.pre-commit) to version-controlled scripts.git-hooks/")..git/hooks/ scripts post-migration.file_put_contents for slow operations).GitHookFailed).| Component | Compatibility | Mitigation |
|---|---|---|
| Git <2.9 | Symlinks may fail; requires symlink: true. |
Enforce symlink: true in composer.json. |
| Windows | Bash scripts may fail in Git Bash or PowerShell. | Use cross-env or rewrite hooks in PowerShell. |
| Laravel Forge | .git/hooks/ may be unwritable. |
Configure core.hooksPath to a writable dir. |
| CI/CD | Hooks run in CI may slow pipelines. | Skip hooks in CI or use lightweight stubs. |
| Robo Dependency | Example assumes Robo; not Laravel-native. | Replace with Artisan commands (see below). |
.git/hooks/ scripts.git-hooks/pre-commit).composer require --dev sweetchuck/git-hooks.composer.json:
"extra": {
"sweetchuck/git-hooks": {
"core.hooksPath": "./git-hooks",
"symlink": true
}
}
pre-commit to git-hooks/pre-commit (or use .git-hooks.sh).GitHookServiceProvider to register commands/events.// app/Console/Commands/GitHookPreCommit.php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class GitHookPreCommit extends Command {
protected $signature = 'hook:pre-commit';
public function handle() {
// Laravel logic (e.g., run tests, lint code)
$this->info('Running pre-commit checks...');
}
}
.git-hooks.sh:
#!/usr/bin/env bash
: "${sghHookName:?'argument is required'}"
: "${sghHasInput:?'argument is required'}"
echo "BEGIN Git hook: ${sghHookName}"
php artisan hook:"${sghHookName}" "${@}"
exit $?
git commit).COMPOSER_SKIP_HOOKS=false (or similar)..git/hooks/ from version control..gitignore (if not already present).How can I help you explore Laravel packages today?