如何正确配置我的预提交和预推挂钩?

时间:2019-02-14 19:23:26

标签: python pre-commit-hook pre-commit

我有一个简单的python项目,目前只有一个文件。它存在于我项目的static / cgi-bin文件夹中。当前,在目录的基础上,我有一个.pre-commit-config.yaml文件,而我没有触摸.git / hooks文件夹中的文件。我想创建预提交和预推钩子,但似乎无法正常工作。

当我尝试提交时,会发生以下情况:

isort................................................(no files to check)Skipped
flake8...............................................(no files to check)Skipped
black................................................(no files to check)Skipped

当我尝试推动时,出现以下错误:

pytest...................................................................Failed
hookid: pytest

============================= test session starts ==============================
platform darwin -- Python 2.7.15, pytest-4.0.2, py-1.7.0, pluggy-0.8.0
rootdir: /Users/.../deployment, inifile:
collected 0 items
========================= no tests ran in 0.01 seconds =========================
error: failed to push some refs to '...git'

请注意,部署是我正在使用的文件夹。

我在yaml文件中的代码是:

repos:
-   repo: local
    hooks:
    - id: isort
      name: isort
      entry: isort
      language: system
      types: [python]
      stages: [commit]
    - id: flake8
      name: flake8
      language: system
      entry: flake8
      types: [python]
      stages: [commit]
    - id: black
      language_version: python3.6
      name: black
      language: system
      entry: black
      types: [python]
      stages: [commit]
    - id: pytest
      name: pytest
      language: system
      entry: pytest
      pass_filenames: false
      always_run: true
      stages: [push]

1 个答案:

答案 0 :(得分:2)

pre-commitstaged files which match types / files的列表传递到列出的entry

您的提交显示“没有要检查的文件”,因为您的提交中没有python文件。初次引入新钩子时,您可能想运行pre-commit run --all-files

关于您的pytest钩子,pytest在不运行任何测试时退出非零状态,因此失败。

相关问题