2

我有以下内容composer.json

{
    "require": {
        "php": ">=5.2.0",
        "queueit/KnownUser.V3.PHP": "dev-master"
    },
    "config": {
        "autoloader-suffix": "ComposerManager",
        "vendor-dir": "../../../all/libraries/composer"
    },
    "prefer-stable": true,
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "queueit/KnownUser.V3.PHP",
                "version": "dev-master",
                "source": {
                    "type": "git",
                    "url": "https://github.com/queueit/KnownUser.V3.PHP.git",
                    "reference": "master"
                }
            }
        }
    ]
}

但是,当我运行时:

$ composer -vvv update
...
Cloning master
Executing command (CWD): git clone --no-checkout 'https://github.com/queueit/KnownUser.V3.PHP.git' '.../sites/all/libraries/composer/queueit/KnownUser.V3.PHP' && cd '.../sites/all/libraries/composer/queueit/KnownUser.V3.PHP' && git remote add composer 'https://github.com/queueit/KnownUser.V3.PHP.git' && git fetch composer

克隆过程需要很长时间,并且存储库的大小超过 25MB:

$ du -hs ~/.composer/cache/vcs/https---github.com-queueit-KnownUser.V3.PHP.git/
25M ~/.composer/cache/vcs/https---github.com-queueit-KnownUser.V3.PHP.git/

然后 Composer 因超时而停止:

[Symfony\Component\Process\Exception\ProcessTimedOutException]
进程“ git clone --no-checkout 'https://github.com/queueit/KnownUser.V3.PHP.git' '.../sites/all/libraries/composer/queueit/KnownUser.V3.PHP' && cd '.../sites/all/libraries/composer/queueit/KnownUser.V3.PHP' && git remote add composer 'https://github.com/queueit/KnownUser.V3.PHP.git' && git fetch composer”超过了 300 秒的超时时间。

我假设存储库太大而无法克隆所有 git 对象。


如何使用浅克隆更快地克隆存储库?

例如,通过将额外--depth 1--single-branchgit 参数传递给 Git 命令,以便 Composer 可以自动获取它?

我希望更改在文件中是自包含的composer.json,因此在其他系统上调用此文件或由其他用户在运行composer install.

4

1 回答 1

5

由于git参数是硬编码的,因此官方不支持使用Composer进行浅克隆(没有任何补丁) 。

已经有一个功能请求添加这个:添加对 git shallow clones 的支持。但是,实现此功能可能会导致一些问题(例如,如果深度不是那么高@stof等,则无法达到锁定的提交)。

此外,还有一个拉取请求,它试图通过添加一个额外的--git-clone-depth参数来实现浅克隆(测试显示了一些好的结果)。然而,由于使用 cache 更快的 git 克隆,该更改已被放弃。


对于快速破解,可以在doDownload()in 中编辑 git 参数src/Composer/Downloader/GitDownloader.php,例如通过更改--depth 1 --single-branch此行:

$command = 'git clone --no-checkout ...'

或者找到将深度 1 设置应用到 git config 的方法。


对于较大的存储库,最简单的解决方法(没有任何技巧)只是通过指定如下变量来增加超时:

COMPOSER_PROCESS_TIMEOUT=0 composer install
于 2017-11-17T12:57:13.230 回答