Many Git fixup commits are for forgetting to check project code standards like:
- PEP8 compliance
- type annotation checks
git commit fixup clutter by making a Git pre-commit hook that applies to all repositories.
The pre-commit hook also does a simple check for YaML syntax.
This procedure works across operating systems since Python script is used.
Tell Git the directory for Git hooks:
git config --global core.hooksPath ~/.git/hooks
Create executable file
this Python pre-commit script.
This global pre-commit check hook does several things:
- get a list of Python file names that changed.
- check PEP8, mypy type hinting and that Python breakpoint debug statements are not present.
- check YaML syntax
- clears IPython notebook output cells
- Checks for trailing whitespaces in any code language
One can easily extend the concept of lint-checking for other programming languages.
These checks can be bypassed at any time for a commit by:
git commit -n
Override this global pre-commit check, substituting a per-repo .git/hooks/pre-commit by in that repo directory typing:
git config core.hooksPath .git/hooks
For example, a website made of Markdown files may wish to run a local-link check via Linkchecker-Markdown.
If on Windows failure occurs like:
cannot spawn .git/hooks/pre-commit: exec format error
Try changing the shebang to:
especially if the command “python3” is not found when typing it in Terminal.