【问题标题】:How specify pre-commit --from-ref for Gitlab?如何为 Gitlab 指定 pre-commit --from-ref?
【发布时间】:2021-08-17 14:06:41
【问题描述】:

我想通过在 Gitlab CI 的 git 分支中更改的预提交文件进行检查。 --from-ref 我需要使用什么参数?

pre-commit run --from-ref=? --to-ref=HEAD

pre-commit 文档中的示例引发错误。

$ pre-commit run --from-ref=origin/HEAD --to-ref HEAD
An unexpected error has occurred: CalledProcessError: command: ('/usr/bin/git', 'diff', '--name-only', '--no-ext-diff', '-z', 'origin/HEAD...HEAD')
return code: 128
expected return code: 0
stdout: (none)
stderr:
    fatal: ambiguous argument 'origin/HEAD...HEAD': unknown revision or path not in the working tree.
    Use '--' to separate paths from revisions, like this:
    'git <command> [<revision>...] -- [<file>...]'

【问题讨论】:

    标签: gitlab gitlab-ci pre-commit.com


    【解决方案1】:

    我在为 GitLab CI/CD 管道开发预提交阶段时遇到了同样的问题。 GitLab CI/CD runner 似乎不会自动获取origin/master 分支,导致fatal: ambiguous argument 'origin/HEAD...HEAD': unknown revision or path not in the working tree. 错误。

    我的解决方法是手动获取origin

    git fetch origin;
    pre-commit run --from-ref "origin/$CI_DEFAULT_BRANCH" --to-ref "$CI_COMMIT_SHA";
    

    【讨论】:

      【解决方案2】:

      作为the documentation states

      要仅检查已更改的文件,这可能会更快,请使用 pre-commit run --from-ref origin/HEAD --to-ref HEAD 之类的内容

      顺便说一句,请不要重复帖子on the issue tracker and SO


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

      【讨论】:

      • 它会引发错误。 console $ pre-commit run --from-ref=origin/HEAD --to-ref HEAD An unexpected error has occurred: CalledProcessError: command: ('/usr/bin/git', 'diff', '--name-only', '--no-ext-diff', '-z', 'origin/HEAD...HEAD') return code: 128 expected return code: 0 stdout: (none) stderr: fatal: ambiguous argument 'origin/HEAD...HEAD': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git &lt;command&gt; [&lt;revision&gt;...] -- [&lt;file&gt;...]'
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-11
      • 1970-01-01
      • 2019-06-21
      • 2017-05-15
      • 1970-01-01
      • 1970-01-01
      • 2018-07-28
      相关资源
      最近更新 更多