Intellij Idea IntelliJ pre-commit.com集成

jv4diomz  于 2023-08-03  发布在  其他
关注(0)|答案(1)|浏览(87)

我在项目中使用pre-commit hooks
当我从command-line提交时,一切都很好,钩子也在工作,但当我尝试从IDE提交时,它失败了,并显示以下消息:
0个文件已提交,2个文件未能提交:未找到虚拟提交pre-commit。你忘了激活你的virtualenv了吗?
我的virtualenv处于活动状态:
x1c 0d1x的数据
我错过了什么?

编辑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

编辑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

编辑3

IntelliJ在Windows 11WSL2上运行,pre-commit安装在wsl2-Ubuntu 20.04.4 LTS上。

7rfyedvj

7rfyedvj1#

看看这个线程https://youtrack.jetbrains.com/issue/PY-12988,检查最后一次重播。
我在我的案例中设置了Git可执行文件的路径\wsl$\Ubuntu-20.04\usr\bin\git,并且全局安装了预提交(不在venv内部)
x1c 0d1x的数据
我在我的ENV - Windows 10上用IntelliJ IDEA 2023. 1. 4(终极版)和WSL试过这个-这个工作得很好。

相关问题