Skip to content

ph1zix/pre-commit-hooks

 
 

Repository files navigation

Custom python/ bash pre-commit-hooks for Git repositories

Pre-commit hooks are a powerful way to automate checks and actions before each commit in your Git repository. This README guides you through the process of setting up and using custom pre-commit hooks using the pre-commit framework.

Prerequisites

Before you start, ensure you have the required dependencies installed:

pip install -r requirements.txt

Usage

  1. Create a file named .pre-commit-config.yaml in the repo where you want the pre-commit hooks to run:
repos:
-   repo: https://github.com/ph1zix/pre-commit-hooks
    rev: v1.0.0
    hooks:
        -   id: pyflakes
        -   id: double-quote-string-fixer

Replace the rev value with the specific commit hash you want to use. You can find the id values for the hooks in the .pre-commit-hooks.yaml file.

  1. Install the pre-commit hook into your local .git/hooks/ directory:
pre-commit install
  1. Test if the hooks work by making a commit:
git commit -a

Contribution

Expand this repository by adding your own bash or python scripts into the pre_commit_hooks directory and update the .pre-commit-hooks.yaml file to tell pre-commit about it. You can choose at which git stage the hooks should run. You may need to extend setup.cfg as well for the hook's entry point. If you make changes and push them to the master branch, get the current commit hash using:

git rev-parse HEAD

Replace the rev value in your .pre-commit.config.yaml file with the hash and don't forget to install the hook again.

Links

Feel free to improve this README.md to help others better understand the setup process.

About

Some out-of-the-box hooks for pre-commit

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 76.6%
  • Shell 23.4%