【问题标题】:Attempting to run pre-commit git hook for checkstyle returns multiple "File not found!" errors尝试为 checkstyle 运行 pre-commit git hook 返回多个“找不到文件!”错误
【发布时间】:2014-09-19 11:47:45
【问题描述】:

我可以在命令行上通过 ant 很好地运行 checkstyle。不幸的是,在安装了this pre-commit checkstyle git hook 后,当我尝试通过 git shell 或 cmd 提示符提交时,我收到以下(示例)错误:

C:\mydirectory\M:0: File not found!
C:\mydirectoryr\:100644:0: File not found!
C:\mydirectory\100644:0: File not found!
C:\mydirectory\5cc4b0103c82b3a661fdc6ff59dc8d1b61a0c40b:0: File not found!
C:\mydirectory\73993b57357353af71a1485cfbaef41e94374b8e:0: File not found!
C:\mydirectory\M:0: File not found!
C:\mydirectory\:100644:0: File not found!
C:\mydirectory\100644:0: File not found!
C:\mydirectory\e7f29d65671ddb488de68b9b5886d24efefe9fd6:0: File not found!
C:\mydirectory\aea31a8e04ae560f2278fb860d1570de0ea41c82:0: File not found!
C:\mydirectory\M:0: File not found!
C:\mydirectory\:100644:0: File not found!
C:\mydirectory\100644:0: File not found!
C:\mydirectory\752c83417a18655b6f6f5ac1f4fe31a2933f0189:0: File not found!
C:\mydirectory\5ed1470dc9d4d8e16c1c34319578609b330aa58b:0: File not found!
C:\mydirectory\M:0: File not found!
C:\mydirectory\:100644:0: File not found!
C:\mydirectory\100644:0: File not found!
C:\mydirectory\4339530856664f202ec1d770d364945d9809e5e9:0: File not found!
C:\mydirectory\ef9f65deaab96aea185f3f5fc2184d5871a5f8ee:0: File not found!

其中“mydirectory”是我的网络应用程序根目录的路径。老实说,我不知道发生了什么。我已经为此工作了几个小时,如果没有足够的信息,请道歉。问你有什么问题,我醒来后会回复你的。提前致谢。

【问题讨论】:

    标签: git ant checkstyle pre-commit-hook pre-commit


    【解决方案1】:

    我怀疑您复制(剪切和粘贴)示例代码。在此过程中,sed 命令中的关键制表符被替换为空格,这不起作用:它确实需要是一个制表符。

    通过提供--name-only 来获取文件名,可以改进示例挂钩以避免整个空格与制表符的区别,从而完全消除对sed ... | uniq 部分的需要。 (明智的做法是使用差异过滤器仅提取添加或修改的文件,并显式禁用重命名检测:添加--diff-filter=AM --no-renames--name-only。)然而,即使这样也会使示例挂钩出现微妙的错误:

    • 它使用git diff-index(拼写为git-diff-index,大改名前的旧拼写)仅查找索引中被修改的文件。这是好的和正确的。
    • 但随后它会在工作树中找到的文件上运行样式检查器。如果工作树文件与索引内容不同,这是错误的;如果他们不这样做,则不需要在第一步中使用的护理。

    解决第二个问题有点棘手:它需要:

    1. 将文件的索引版本复制到其他地方,以便样式检查器可以检查它们;或
    2. 使用git stash --keep-index 将工作树版本隐藏起来,将工作树版本替换为打算提交的版本。完成此操作后,git diff 命令必须更改,并且在运行检查后,可以恢复保存的存储,并根据需要完成或跳过提交。

    方法 2 是我经常使用的方法,但它需要格外小心,以防 git commit 在没有任何更改的情况下运行。在这种情况下,git stash 步骤什么也不做。此外,git stash 中还有一个似乎没人关心修复的错误。如果您选择方法 2,请参阅this answer

    【讨论】:

      猜你喜欢
      • 2015-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-18
      • 2011-06-17
      • 1970-01-01
      • 2023-04-11
      • 2023-01-04
      相关资源
      最近更新 更多