Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ pre-commit.com integration

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-commit not found. Did you forget to activate your virtualenv?

My virtualenv is active:

activate your virtualenv

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

like image 561
lior.i Avatar asked Apr 22 '26 09:04

lior.i


1 Answers

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

Git binary from the WSL

I tried this on my ENV - windows 10 with IntelliJ IDEA 2023.1.4 (Ultimate Edition) and WSL - and this working just fine.

like image 158
DeamonMV Avatar answered Apr 25 '26 22:04

DeamonMV



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!