基于可执行文件不是 git repo的预提交钩子

问题描述

我想运行来自 pip 的可执行文件,但它不能作为 git 存储库使用。文档似乎假定您想运行的任何内容都来自 git 存储库:https://pre-commit.com/#plugins。如何将任意 shell 命令作为预提交钩子运行?

解决方法

预提交允许对回购部分使用 local 哨兵。下面的示例配置在系统上安装时运行黑色:

repos:
-   repo: local
    hooks:
    - id: black
      name: black
      language: system
      entry: black
      types: [python]