【问题标题】:Can I exclude files from every pre-commit hook except for one without repeating myself?我可以从每个预提交挂钩中排除文件,除了一个而不重复自己吗?
【发布时间】:2021-11-05 09:59:45
【问题描述】:

我想创建一个符合 REUSE 的 Git 存储库。我想使用the reuse pre-commit hook 来帮助确保我合规。 The REUSE Specification 要求我创建一个名为“LICENSES”的文件夹,其中包含我的项目使用的每个许可证。我正在使用其他几个钩子,我不希望这些钩子检查或修改 LICENSES/ 文件夹中的任何内容。我希望除重用之外的每个钩子都排除LICENSES/。 (旁注:目前,重用钩子似乎不受排除 LICENSES/ 的影响,但这应该可以修复)。以下是我目前尝试过的:

exclude: '^LICENSES/'
repos:
    -
        repo: https://github.com/pre-commit/pre-commit-hooks
        rev: v4.0.1
        hooks:
            - id: check-case-conflict
            - id: end-of-file-fixer
            - id: mixed-line-ending
            - id: trailing-whitespace
    # I’m using identity instead of reuse here for testing and to better
    # illustrate the problem.
    -
        repo: meta
        hooks:
            -
                id: identity
                exclude: "^$"

那没用。看起来除了全局模式之外,每个钩子排除模式也适用。我希望应用每个钩子排除模式而不是全局模式。

我可以在每个钩子上使用每个钩子排除模式,除了一个:

repos:
    -
        repo: https://github.com/pre-commit/pre-commit-hooks
        rev: v4.0.1
        hooks:
            -
                id: check-case-conflict
                exclude: &exclude_pattern '^LICENSES/'
            -
                id: end-of-file-fixer
                exclude: *exclude_pattern
            -
                id: mixed-line-ending
                exclude: *exclude_pattern
            -
                id: trailing-whitespace
                exclude: *exclude_pattern
    # I’m using identity instead of reuse here for testing and to better
    # illustrate the problem.
    -
        repo: meta
        hooks:
            - id: identity

但是,我会重复自己。我认为我可以使用合并键少重复自己,但是I don’t think that those are supported。有没有办法避免重复自己或少重复自己?

【问题讨论】:

    标签: git pre-commit.com


    【解决方案1】:

    正如你所发现的,在每个钩子上都指定exclude

    顶级exclude 是一个快捷方式,即applied to all hooks

    我建议将exclude 添加到修改LICENSES的钩子


    免责声明:我创建了预提交

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-29
      • 2014-12-24
      • 2011-10-27
      • 1970-01-01
      • 2015-11-28
      相关资源
      最近更新 更多