【问题标题】:Setting up gitlint pre-commit local for a repository为存储库设置 gitlint 预提交本地
【发布时间】:2021-02-27 22:35:08
【问题描述】:

我正在尝试在存储库中添加一个 gitlint 预提交挂钩。 .pre-commit-config.yaml 文件看起来像这样:

# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
  - repo: local
    hooks:
      - id: gitlint
        name: gitlint
        entry: gitlint
        language: system

但是,我不断得到:

- hook id: gitlint
- exit code: 253

Usage: gitlint [OPTIONS] COMMAND [ARGS]...
Try 'gitlint --help' for help.

Error: No such command '.pre-commit-config.yaml'.

这是我跑完之后:

pip install gitlint
pre-commit install --hook-type commit-msg

我做错了什么?

【问题讨论】:

  • gitlint 的安装方式和位置是什么?
  • 安装在 MacOS 上。使用 pip 安装 gitlint。我真的想通了。我必须在 .pre-commit.yaml 中添加 types: [python]。现在我有一个不同的问题。我会更新问题

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


【解决方案1】:

由于以下几个原因,您的配置被破坏:

  • 您已经为所有stages 配置了gitlint,这意味着它将在您不想要的其他git 挂钩上运行(例如pre-commitpre-push 等)。要解决此问题,您将设置 stages: [commit-msg]
  • 您还缺少一些其他设置,例如 gitlint 的正确参数等。
  • 此外,您正在使用language: system,这意味着您依赖于您的贡献者来设置工具——这错过了预先提交的要点,并且是不受支持的逃生舱口。拥有托管工具的常用方法是重用现有存储库(见下文)或使用additional_dependencies 以托管方式安装该工具

支持的 gitlint 使用方式来自存储库本身

repos:
-   repo: https://github.com/jorisroovers/gitlint
    rev: ''  # pick a tag / sha to use
    hooks:
    -   id: gitlint

免责声明:我是 pre-commit 的创建者,并为 gitlint 贡献了 pre-commit 支持

【讨论】:

  • 谢谢。这很有帮助。我仍然想在本地设置它,所以我做到了。你的 cmets 帮助我做到了。
【解决方案2】:

错误消息不是很有帮助。我只是缺少 args 和 stage 字段:

# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
---
repos:
   - repo: local
     hooks:
       - id: gitlint
         name: gitlint
         language: python
         entry: gitlint
         args: [--staged, --msg-filename]
         stages: [commit-msg]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-19
    • 1970-01-01
    • 1970-01-01
    • 2011-04-14
    • 2019-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多