- How do I add Git hooks to my Laravel project using Composer?
- Define hooks in your `composer.json` under the `extra.git-hooks` section, then run `composer install` or `composer update`. The plugin will automatically install and update the hooks in your `.git/hooks` directory. Example: Add a `pre-commit` hook by specifying the script path in the config.
- Does this package support Laravel’s dependency management?
- Yes, it integrates natively with Composer, so hooks are managed alongside other Laravel dependencies. This ensures hooks are installed consistently across all environments, including local dev, staging, and production, as long as Composer is used for dependency resolution.
- Can I use this for pre-commit PHPStan or PHPUnit tests in Laravel?
- Absolutely. You can configure the package to run PHPStan or PHPUnit as pre-commit hooks by defining the script paths in `composer.json`. The hooks execute before commits, blocking invalid code from being pushed. Example: `"pre-commit": ["vendor/bin/phpstan analyze", "vendor/bin/phpunit"]`.
- Will this work with Laravel Forge or Envoyer for deployment?
- Yes, since hooks are managed via Composer, they’ll be installed on any server where you run `composer install`. However, ensure your deployment scripts include Composer updates to avoid missing hooks. For Envoyer, add a `composer install` step in your deployment recipe.
- How do I migrate existing manual Git hooks to this package?
- Move your hook scripts (e.g., `pre-commit`, `pre-push`) into your project’s root or a designated `hooks/` directory, then reference them in `composer.json` under `extra.git-hooks`. Run `composer install` to replace manual hooks with the Composer-managed versions. Backup old hooks before migration.
- Does this package support Laravel 10+ and PHP 8.1+?
- Yes, the package is designed to work with modern Laravel versions (9.x and 10.x) and PHP 8.1+. It leverages Composer’s plugin system, which is fully compatible with these environments. Check the package’s Composer constraints for exact version requirements.
- Can I customize hook behavior (e.g., exit codes, logging) in Laravel?
- Yes, you can customize hook scripts directly in your project. The package only handles installation and updates; the scripts themselves can include Laravel-specific logic, like checking `.env` files or running Artisan commands. Example: Use `php artisan test` in a pre-push hook.
- What if a hook fails in production? Will it block deployments?
- Hooks run locally or on the server where Composer installs them. In production, failing hooks (e.g., pre-push) won’t block deployments unless explicitly configured to do so. For CI/CD pipelines, consider using the package’s hooks as guardrails in staging, not production.
- Are there alternatives to this package for Laravel Git hooks?
- Alternatives include `evilmartians/composer-hooks` or manual `.git/hooks` setup, but this package offers tighter Composer integration and Laravel-friendly features like Artisan command hooks. It’s ideal for teams wanting hooks managed alongside Laravel dependencies without extra tooling.
- How do I test Git hooks locally before committing to Laravel projects?
- Use `composer hooks:test` (if supported) or manually trigger hooks with `git commit --no-verify` to bypass them. For pre-push, simulate it with `GIT_PUSH=true git push --dry-run`. Ensure hooks are committed to your repo so all team members get the same behavior during testing.