No description
Find a file
2026-01-26 09:16:02 +02:00
.gitignore Add first hook pre-commit 2025-09-25 15:37:15 +03:00
.gitmodules remove hooks from here 2025-11-27 15:11:37 +02:00
Dockerfile Add first hook pre-commit 2025-09-25 15:37:15 +03:00
install.sh Fix English 2025-12-15 12:47:50 +02:00
pre-commit Add check for python version of the project 2026-01-26 09:16:02 +02:00
README.md Add option to not create venvs 2025-12-08 15:15:43 +02:00
yamllint.yaml Don't check Ansible and add yaml lint configuration 2025-12-02 10:59:50 +02:00

Pouta's GIT hooks

Description

Collection of Git hooks to use in Pouta's repositories. This hooks should be added to new Pouta's repositories. Unless differently agree by the team.

Requirements

The hooks require this tools:

  • yamllint
  • python
  • python venv module (python3-venv in Ubuntu)
  • python pip module (python3-pip in Ubuntu)
  • puppet-lint
  • shellcheck
  • jq

Installation

Run ./install -d <DIRECTORY_CONTAINING_YOUR_REPOSITORIES> to add the git configuration for the repository in the specified directory with the path to the repository hooks. You can add --recursive to do it recursively to all children of the directory.

You can just run git config --local core.hooksPath ~/src/dev/pouta_git_hooks if the hooks are in that folder.

Uninstallation

For each repository restore or remove the line hooksPath from the core section of the file .git/config.

Usage

When you execute a git command cover by one of these hooks, GIT will execute the hooks before your command. For example (from the Git documentation linked above), "the pre-commit hook is run first, before you even type in a commit message.". If any of the tests fails, you commit won't be completed and the errors will be shown.

You can always do a commit skipping the hook with git commit --no-verify.

Hooks

Pre-commit

This hook will check code basic syntax and style according to some standards.

You can exclude python files from been checked for non-errors by adding a comment in your files with a line starting with (note that there must be a comment/reason for the file to be excluded):

  • For Python: # Pylint-Only-Errors <YOUR COMMENT/REASON>
  • For Shell scripts: # ShellCheck-Only-Errors <YOUR COMMENT/REASON>
  • For Puppet: # PuppetLint-Only-Errors <YOUR COMMENT/REASON>
  • For YAML: # Yamllint-Only-Errors <YOUR COMMENT/REASON>

You can exclude a repository from having Python virtual environments created creating a file or folder called .no_venv in the root of the repository. If there is any requirements.txt file and Python files changed and there is no .no_venv file, the pre-commit will create a virtual environment in the folder venv to install all requirements. Otherwise Pylint would complaint of any missing Python module imported that is not present in your system.

Types of code/configuration covered

  • Python
  • Shell scripts
  • Ansible
  • Puppet
  • JSON
  • YAML

Security

Be aware of the hooks code, that code will run for each commit in your local machine. Don't add untrusted hooks to your repositories.