Last updated: 07.11.2020
The purpose of this repository is to provide examples of Git hooks. Git hooks are code executed as a result of Git actions (events). For example, when a developer checks in code on their computer, a pre-commit event causes certain code to execute that either allows the commit or denies it.
One example provided in this repository is code that checks if files are formatted correctly, and if not, the code prevents the commit. The code also helps the developer format the code properly so the developer has less work to do.
Requires Python 3.
A working knowledge of Python.
-
Run:
yum -y install ansible-lint yamllint
. These install Ansible lint and Yaml lint respectively. -
Run:
python3 -m venv venv_linting
-
Run:
source venv_linting/bin/activate
-
Run:
pip install gem
-
Run:
gem install mdl
. This installs Markdown lint. -
Copy the content of the repo down to your local machine.
-
Place the githooks directory in the root directory of your git code repository.
-
Open a terminal in your repo root directory.
-
Run
git config core.hooksPath ./githooks
-
Run
git add .
-
Run
git commit -m "added git hooks folder and contents"
. If you have any markdown in your repository directory, the code will not let you "commit" until you have fixed the lint errors.