'How to return status `Skipped` in self defined pre-commit hook?
I have a self defined pre-commit hook which I want to skip if an earlier hook fails. If an earlier hook fails, a logfile named pre-commit.log is generated.
A .pre-commit-config.yaml could look like this:
repos:
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
log_file: pre-commit.log
- repo: local
hooks:
- id: skript
name: skript
entry: bash skript.sh
language: system
log_file: pre-commit.log
My bash skript.sh looks like this:
if [ -f "pre-commit.log" ]; then
echo "Error in earlier pre-commit! We skip this script."
echo "See 'pre-commit.log' for detailed information."
exit 1
else
echo "All pre-commits successful."
# some other code
fi
Right now I check if the "pre-commit.log" exists and if so I return exit 1. Because of this, the output for this hook is Failed. But I would prefer the status Skipped because there was no failure.
My goal is to see in the console or logfile the text Skipped, like in this image for jupyter-notebook-cleanup.
If I write exit 0 I get Passed like for isort and black and if I return exit 1 or another number greater 1 I get Failed like for flake8.
How can I get the message Skipped?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

