我对位桶私有仓库有一些问题...所以我在我的项目根目录中添加了这样的东西composer.json
:
"require": {
"php" : ">=5.4.0",
...,
"author/my-package": "0.2"
},
"repositories": [
{
"type": "vcs",
"url": "ssh://hg@bitbucket.org/author/my-package"
}
...
]
因此,在composer.phar update
之后,它会在vendor
中创建回购目录...但是在私有存储库中进行新提交并在项目根目录中更新 composer.phar 后,它不会拉取最后一个变更集......它保留在第一次存储库导入时的头部
结论
在 composer.phar 调试之后,我知道如果包版本没有更改,它不会更新(拉取)最后一个变更集。
我创建了脚本,该脚本在每次运行作曲家更新后更新我的每个存储库。信息在这里 https://getcomposer.org/doc/articles/scripts.md
<?php
namespace ComposerScript;
use ComposerRepositoryRepositoryManager;
use ComposerScriptEvent;
use ComposerRepositoryPackageRepository;
use ComposerPackageCompletePackage;
use ComposerUtilProcessExecutor;
class EventListener
{
/**
* @var ProcessExecutor
*/
protected static $processExecutor;
protected static $command = 'hg pull -u';
public static function getProcessExecutor()
{
if (self::$processExecutor == null) {
self::$processExecutor = new ProcessExecutor();
}
return self::$processExecutor;
}
public static function postUpdateCmd(Event $event)
{
$composer = $event->getComposer();
/** @var RepositoryManager $repositoryManager */
$repositoryManager = $composer->getRepositoryManager();
$cwd = getcwd();
foreach ($repositoryManager->getRepositories() as $repository) {
if ($repository instanceof PackageRepository) {
foreach ($repository->getPackages() as $package) {
/** @var CompletePackage $package */
$vendorName = explode('/', $package->getName())[0];
$repositoryPath = $cwd . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . $package->getName();
if ($package->getSourceType() == 'hg' && $vendorName == 'myvendor' && is_dir($repositoryPath)) {
echo PHP_EOL . "Trying to execute '".self::$command."' in '".$repositoryPath . "'" . PHP_EOL;
$exitCode = self::getProcessExecutor()->execute(self::$command, $output, $repositoryPath);
if ($exitCode !== 0) {
echo "Unable to execute '" . self::$command . "' command in '" . $repositoryPath . "' dir" .
PHP_EOL .
"Message: " .
PHP_EOL .
$output;
} else {
echo 'Success';
}
}
}
echo PHP_EOL;
}
}
}
}
并在 composer.json 中添加了几行
"autoload" : {
"psr-0": {
"ComposerScript\EventListener" : ""
}
},
"scripts" : {
"post-update-cmd" : [
"ComposerScript\EventListener::postUpdateCmd"
]
}
你已经告诉作曲家安装你的软件包的 0.2 版,所以这就是它所做的。如果运行更新,这不会更改。如果要改为跟踪分支,请将版本更改为dev-master
:
"require": {
"php": ">=5.4.0",
...,
"author/my-package": "dev-master"
},