【问题标题】:How to propertly configure my pre-commit and pre-push hooks?如何正确配置我的预提交和预推送挂钩?
【发布时间】:2019-07-08 21:51:13
【问题描述】:

我目前有一个带有单个文件的简单 python 项目。它存在于我项目的 static/cgi-bin 文件夹中。目前,在我的目录的底部,我有一个 .pre-commit-config.yaml 文件,我还没有触及 .git/hooks 文件夹中的文件。我想创建 pre-commit 和 pre-push 钩子,但我似乎无法让它工作。

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

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]

【问题讨论】:

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


【解决方案1】:

pre-commit 会将staged files which match types / files 的列表传递给列出的entry

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-20
    • 2021-09-19
    • 2020-01-06
    • 2019-06-02
    • 2019-07-12
    • 2014-07-26
    • 1970-01-01
    • 2010-12-22
    相关资源
    最近更新 更多