I'm using pre-commit hooks in my project.
When I'm doing my commits from the command-line everything is great and the hooks are working but when I try to commit from the IDE it failed with the message:
0 file committed, 2 files failed to commit: dummy commit
pre-commitnot found. Did you forget to activate your virtualenv?
My virtualenv is active:

What am I missing?
##Edit 1
Ubuntu 20.04.4 LTS
grep ^INSTALL .git/hooks/pre-commit -> INSTALL_PYTHON=/home/lioriz/anaconda3/envs/py36/bin/python
which pre-commit -> /home/lioriz/anaconda3/envs/py36/bin/pre-commit
head -1 $(which pre-commit) -> #!/home/lioriz/anaconda3/envs/py36/bin/python
pre-commit --version -> pre-commit 2.17.0
##Edit 2
.pre-commit-config.yaml:
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
.git/hooks/pre-commit:
#!/usr/bin/env bash
# File generated by pre-commit: https://pre-commit.com
# ID: 138fd403232d2ddd5efb44317e38bf03
# start templated
INSTALL_PYTHON=/home/lioriz/anaconda3/envs/py36/bin/python
ARGS=(hook-impl --config=.pre-commit-config.yaml --hook-type=pre-commit)
# end templated
HERE="$(cd "$(dirname "$0")" && pwd)"
ARGS+=(--hook-dir "$HERE" -- "$@")
if [ -x "$INSTALL_PYTHON" ]; then
exec "$INSTALL_PYTHON" -mpre_commit "${ARGS[@]}"
elif command -v pre-commit > /dev/null; then
exec pre-commit "${ARGS[@]}"
else
echo '`pre-commit` not found. Did you forget to activate your virtualenv?' 1>&2
exit 1
fi
test -x /home/lioriz/anaconda3/envs/py36/bin/python; echo $? -> 0
##Edit 3
The IntelliJ runs on Windows 11 with WSL2, and the pre-commit is installed in the wsl2 - Ubuntu 20.04.4 LTS
Look at this Thread https://youtrack.jetbrains.com/issue/PY-12988, check the last replay.
I have set path to Git executable in my case \wsl$\Ubuntu-20.04\usr\bin\git and pre-commit installed globally (not inside venv) just worked

I tried this on my ENV - windows 10 with IntelliJ IDEA 2023.1.4 (Ultimate Edition) and WSL - and this working just fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With