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
?
CodePudding user response:
there is no way to influence that text be Skipped
Skipped
only appears in the following cases:
- the hook was not run because its hookid appeared inside the
SKIP
environment variable - there were no files which matched
files
/types
/types_or
andpass_filenames
wastrue
(the default) andalways_run
wasfalse
(the default)
your best bet is to exit 0
in the non-failure case, this will appear as Passed
in the output
disclaimer: I wrote the pre-commit tool you're using