Download the PHP package igorsgm/laravel-git-hooks without Composer
On this page you can find all versions of the php package igorsgm/laravel-git-hooks. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download igorsgm/laravel-git-hooks
More information about igorsgm/laravel-git-hooks
Files in igorsgm/laravel-git-hooks
Package laravel-git-hooks
Short Description 🪝• Efficiently manage Git hooks in Laravel projects. Enhance code quality, save time on reviews, and prevent bugs from entering your repository.
License MIT
Homepage https://github.com/igorsgm/laravel-git-hooks
Informations about the package laravel-git-hooks
🪝 Laravel Git Hooks
A powerful and easy-to-use package for managing Git hooks within your Laravel projects. Improve your code quality, reduce the time spent on code reviews, and catch potential bugs before they make it into your repository.
✨ Features
- Pre-configured Hooks: Laravel Git Hooks comes with pre-configured pre-commit hooks for popular tools, such as Laravel Pint, PHPCS, ESLint, Prettier, Larastan, Enlightn, Rector, PHP Insights, and Blade Formatter, making it easy to enforce coding standards and style guidelines right away.
- Manage Git Hooks: Easily manage your Git hooks in your Laravel projects with a streamlined and organized approach.
- Edit Commit Messages: Gain control over your commit messages by customizing them to meet your project requirements and maintain a clean Git history.
- Create Custom Hooks: Add and integrate custom hooks tailored to your specific project needs, ensuring better code quality and adherence to guidelines.
- Artisan Command for Hook Generation: The package includes a convenient Artisan command that allows you to effortlessly generate new hooks of various types, such as:
pre-commit,prepare-commit-msg,commit-msg,post-commit, andpre-push. - Code Quality: The package is thoroughly tested with >95% code coverage, ensuring its reliability and stability in a wide range of Laravel projects.
- Docker support: Each hook can be configured to either run locally or inside a Docker container, with full Laravel Sail integration.
- Auto-fix Capabilities: Automatically fix code issues without manual intervention, with configurable re-run after fixes.
1️⃣ Installation
Laravel Version Support: This package supports Laravel 11 and Laravel 12. Laravel 10 support has been deprecated.
-
You can install the package via composer:
-
Publish the config file and customize it as needed:
- Now, whenever you make a change to your
config/git-hooks.phpfile, register your Git hooks by running the Artisan command:
Once you've configured and registered the hooks, you're all set!
2️⃣ General Usage
Usage of the configured Pre-commit Hooks
To use the pre-configured pre-commit hooks provided by this package, simply edit the pre-commit section of the git-hooks.php config file. Here's an example of how to configure them:
🔧 Auto-fix Capabilities
By default, the pre-commit hooks will stop at the first failure and will not continue with the remaining tools. If the tool contains a fixer option, it will prompt in the CLI to run the fix command.
The package includes powerful auto-fix functionality that can automatically resolve code style and formatting issues:
- Interactive Fixing: By default, when an issue is detected, you'll be prompted to run the fix command
- Automatic Fixing: Enable
automatically_fix_errorsto fix issues without prompts - Smart Re-running: Enable
rerun_analyzer_after_autofixto automatically verify fixes succeeded
This behavior can be adjusted using the following parameters from the git-hooks.php config file:
3️⃣ Advanced Usage
🐳 Laravel Sail Support
If you are using Laravel Sail and local PHP is not installed, you can adjust the following parameters in the git-hooks.php config file.
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:
🔧🪲 Advanced Configuration Options & Debug Mode
The git-hooks.php config file offers several debug options that can be adjusted using the following parameters.
It also provides additional configuration options for fine-tuning hook behavior:
🛠️ Creating Custom Git Hooks
1) If you need to create a custom Git hook for your project, Laravel Git Hooks makes it easy with the git-hooks:make Artisan command. To create a new custom hook, simply run the following command:
This command will prompt you to choose the type of hook you want to create (e.g., `pre-commit`, `post-commit`, etc.) and to provide a name for the hook. Once you've provided the required information, the command will generate a new hook class in the `app/Console/GitHooks` directory.
2) To start using your custom hook, open the generated file and implement the handle() method with your desired logic.
3) Add your custom hook to the appropriate array in the git-hooks.php config file:
4) Finally, register your custom hook by running the Artisan command:
4️⃣ Handling Git Hooks
Pre-commit Hook
The pre-commit hook is run first, before you even type in a commit message. It's used to inspect the snapshot that's about to be committed, to see if you've forgotten something, to make sure tests run, or to examine whatever you need to inspect in the code. Exiting non-zero from this hook aborts the commit, although you can bypass it with git commit --no-verify. You can do things like check for code style (run lint or something equivalent), check for trailing whitespace (the default hook does exactly this), or check for appropriate documentation on new methods.
Prepare-commit-message Hook
The prepare-commit-msg hook is run before the commit message editor is fired up but after the default message is created. It lets you edit the default message before the commit author sees it. This hook takes a few parameters: the path to the file that holds the commit message so far, the type of commit, and the commit SHA-1 if this is an amended commit. This hook generally isn't useful for normal commits; rather, it's good for commits where the default message is auto-generated, such as templated commit messages, merge commits, squashed commits, and amended commits. You may use it in conjunction with a commit template to programmatically insert information.
Commit-msg Hook
The commit-msg hook takes one parameter, which is the path to a temporary file that contains the commit message written by the developer. If this script exits non-zero, Git aborts the commit process, so you can use it to validate the commit message format.
The class structure of the commit-msg hook is the same as the prepare-commit-msg hook, shown right above.
Post-commit Hook
After the entire commit process is completed, the post-commit hook runs. It doesn't take any parameters, but you can easily get the last commit by running git log -1 HEAD. Generally, this script is used for notification or something similar.
Pre-push Hook
The pre-push hook runs during git push, after the remote refs have been updated but before any objects have been transferred. It receives the name and location of the remote as parameters, and a list of to-be-updated refs through stdin. You can use it to validate a set of ref updates before a push occurs (a non-zero exit code will abort the push).
The class structure of the pre-push hooks is the same as the post-commit hook shown above, but implementing \Igorsgm\GitHooks\Contracts\PrePushHook interface.
🧪 Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Original Authors
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-git-hooks with dependencies
illuminate/config Version ^11.0|^12.0|^13.0
illuminate/console Version ^11.0|^12.0|^13.0
illuminate/container Version ^11.0|^12.0|^13.0
illuminate/contracts Version ^11.0|^12.0|^13.0
illuminate/pipeline Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0