忽略 "git clone" 中的 fsck / 零填充文件模式错误

Ignore fsck / zero-padded file mode errors in "git clone"

我的全局 Git 配置中有以下设置:

[transfer]
    fsckobjects = true

[fetch]
    fsckobjects = true

[receive]
    fsckobjects = true

这些验证克隆数据库中的所有对象是否有效且可访问。

但是,我想检查的一些回购有错误,比如 oh-my-zsh:

git clone https://github.com/robbyrussell/oh-my-zsh.git .oh-my-zsh 
Cloning into '.oh-my-zsh'...
remote: Counting objects: 15624, done.
error: object 2b7227859263b6aabcc28355b0b994995b7148b6: zeroPaddedFilemode: contains zero-padded file modes
fatal: Error in object
fatal: index-pack failed

有没有一种方法可以覆盖单个 "git clone" 操作的全局 fsckobjects 设置?

使用git clone --config key=value并传递所有你想跳过的参数。对于 oh-my-zsh,它看起来像这样:

git clone --config transfer.fsckobjects=false \
    --config receive.fsckobjects=false \
    --config fetch.fsckobjects=false \
    git://github.com/robbyrussell/oh-my-zsh.git

如果您只需要最新版本——例如自动安装——我一直在我的脚本中使用它 (for example):

git clone --depth 1 https://github.com/ohmyzsh/ohmyzsh

它不会克隆整个存储库历史记录,只会克隆最新版本,对于自动安装来说应该没问题。

(我很确定这不是我自己想出来的,但我无法追溯到原始来源)。

Git 2.19(2018 年第 3 季度)现在将允许克服该错误(转换为警告)。

在“git push”的接收端执行的防止坏对象进入存储库的测试可以通过receive.fsck.*配置变量进行自定义。
我们现在已经获得了在 "git fetch" 方面做同样事情的对手, fetch.fsck.* 配置变量。

参见 commit 8a6d052, commit 65a836f, commit d786da1, commit 1362df0, commit 8b55b9d, commit 720dae5, commit 456bab8, commit b2558ab, commit 5180dd2, commit 95d9d4b (27 Jul 2018) by Ævar Arnfjörð Bjarmason (avar)
(由 Junio C Hamano -- gitster -- in commit f8ca718 合并,2018 年 8 月 17 日)

fetch: implement fetch.fsck.*

Implement support for fetch.fsck.* corresponding with the existing receive.fsck.*. This allows for pedantically cloning repositories with specific issues without turning off fetch.fsckObjects.

One such repository is https://github.com/robbyrussell/oh-my-zsh.git which before this change will emit this error when cloned with fetch.fsckObjects:

error: object 2b7227859263b6aabcc28355b0b994995b7148b6: zeroPaddedFilemode: contains zero-padded file modes
fatal: Error in object
fatal: index-pack failed

Now with fetch.fsck.zeroPaddedFilemode=warn we'll warn about that issue, but the clone will succeed:

warning: object 2b7227859263b6aabcc28355b0b994995b7148b6: zeroPaddedFilemode: contains zero-padded file modes
warning: object a18c4d13c2a5fa2d4ecd5346c50e119b999b807d: zeroPaddedFilemode: contains zero-padded file modes
warning: object 84df066176c8da3fd59b13731a86d90f4f1e5c9d: zeroPaddedFilemode: contains zero-padded file modes

The motivation for this is to be able to turn on fetch.fsckObjects globally across a fleet of computers but still be able to manually clone various legacy repositories by either white-listing specific issues, or better yet whitelist specific objects.