Composer Git Hooks

Composer Git Hooks

You can easily manage git hooks in your composer configuration file with the Composer Git Hooks package by Ezinwa Okpoechi:

Manage git hooks easily in your composer configuration. This command line tool makes it easy to implement a consistent project-wide usage of git hooks. Specifying hooks in the composer file makes them available for every member of the project team. This provides a consistent environment and behavior for everyone which is great. It is also possible to use to manage git hooks globally for every repository on your computer. That way you have a reliable set of hooks crafted by yourself for every project you choose to work on.

By using the composer configuration file everyone that checks out the project will have the same behavior instead of each developer having to set up hooks individually.

Here’s an example of how you can configure git hooks in the composer extra configuration:

"extra": {
    "hooks": {
        "pre-commit": [
            "echo committing as $(git config user.name)",
            "php-cs-fixer fix ." // fix style
        ],
        // verify commit message. ex: ABC-123: Fix everything
        "commit-msg": "grep -q '[A-Z]+-[0-9]+.*' $1",
        "pre-push": [
            "php-cs-fixer fix --dry-run .", // check style
            "phpunit"
        ],
        "post-merge": "composer update"
    }
}

If you follow along in the project’s readme, you can add the following events to run cghooks every time the following events happen:

"scripts": {
    "post-install-cmd": "cghooks add --ignore-lock",
    "post-update-cmd": "cghooks update"
}

To learn more about this package, including source code, documentation, and examples, check out the project on GitHub at BrainMaestro/composer-git-hooks.


Filed in: News


Newsletter

Join the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Software Engineer Lead (PHP)
Remote
CivicPlus, LLC
Full-time Senior Web Developer
Detroit, MI
Wayne State University
Senior Software Engineer
Sydney, Australia
FoodByUs
Full Stack Engineer
Remote or Medford, Oregon
Empire Medical
Laravel Developer (fulltime - Dutch only)
Netherlands
Qbixx | Webservices
Full Stack or Back-End Developer
Alexandria, VA; Tallahassee, FL; Orlando, FL
Marketing for Change
Senior Quality Assurance Engineer
Remote
Bisnow Media