This repository contains some useful and documented pre-commit hooks to use with git.
NOTE: The scripts in this repository are currently not actively being developed. They have served me well though and work as they are. pre-commit.com looks like a well-maintained alternative with a similar approach. Also, live linters like w0rp/ale are pretty awesome!
hook | description |
---|---|
pre-commit | Allow to run multiple pre-commit hooks as specified in the script. |
pre-commit-compile | Compile the project and abort commit if it fails. |
pre-commit-uncrustify | Run Uncrustify on your sourcefiles and abort the commit if style violations have been detected. Generate a patch to fix these violations. |
Sometimes pictures say more than a thousand words. Below is an exemplary workflow using the Uncrustify hook.
Clone the repository
git clone git://github.com/ddddavidmartin/Pre-commit-hooks.git
cd Pre-commit-hooks
Every script comes with a <script>.example.cfg
configuration file. Here you will find relevant configuration options. For starters create a pre-commit.cfg
and update the configuration section in it with the hooks that you want to install and use.
cp pre-commit.example.cfg pre-commit.cfg
vim pre-commit.cfg # update with desired hooks
Copy the pre-commit hooks into your repository. Note that the script will ask before overwriting any existing hooks. By default it installs the example config for each hook.
./install_hooks.sh /path/to/repository
The pre-commit hooks live in the .git/hooks
subdirectory of your git repository. Update their configuration files if required and you are good to go. By default the hooks will abort the commit and print a notice if any required configuration is missing.
Work on your code as usual and the hooks should be run automatically when calling git commit
.
Profit!
Thanks to everyone who contributed with fixes, ideas and extensions!
Feel free to open issues or pull requests if you come across something that can be improved or does not work. Input is always appreciated.
Licensed as per LICENSE file.