Set protocols for github in composer config file
parent
0689e24e83
commit
3b6bd761ec
|
@ -89,12 +89,13 @@ EOT
|
||||||
|
|
||||||
public function installProject(IOInterface $io, $packageName, $directory = null, $packageVersion = null, $preferSource = false, $installDevPackages = false, $repositoryUrl = null, $disableCustomInstallers = false, $noScripts = false)
|
public function installProject(IOInterface $io, $packageName, $directory = null, $packageVersion = null, $preferSource = false, $installDevPackages = false, $repositoryUrl = null, $disableCustomInstallers = false, $noScripts = false)
|
||||||
{
|
{
|
||||||
$dm = $this->createDownloadManager($io);
|
$config = Factory::createConfig();
|
||||||
|
|
||||||
|
$dm = $this->createDownloadManager($io, $config);
|
||||||
if ($preferSource) {
|
if ($preferSource) {
|
||||||
$dm->setPreferSource(true);
|
$dm->setPreferSource(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$config = Factory::createConfig();
|
|
||||||
if (null === $repositoryUrl) {
|
if (null === $repositoryUrl) {
|
||||||
$sourceRepo = new CompositeRepository(Factory::createDefaultRepositories($io, $config));
|
$sourceRepo = new CompositeRepository(Factory::createDefaultRepositories($io, $config));
|
||||||
} elseif ("json" === pathinfo($repositoryUrl, PATHINFO_EXTENSION)) {
|
} elseif ("json" === pathinfo($repositoryUrl, PATHINFO_EXTENSION)) {
|
||||||
|
@ -183,10 +184,10 @@ EOT
|
||||||
$installer->run();
|
$installer->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createDownloadManager(IOInterface $io)
|
protected function createDownloadManager(IOInterface $io, Config $config)
|
||||||
{
|
{
|
||||||
$factory = new Factory();
|
$factory = new Factory();
|
||||||
|
|
||||||
return $factory->createDownloadManager($io);
|
return $factory->createDownloadManager($io, $config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ class Config
|
||||||
'vendor-dir' => 'vendor',
|
'vendor-dir' => 'vendor',
|
||||||
'bin-dir' => '{$vendor-dir}/bin',
|
'bin-dir' => '{$vendor-dir}/bin',
|
||||||
'notify-on-install' => true,
|
'notify-on-install' => true,
|
||||||
|
'github-protocols' => array('git', 'https', 'http'),
|
||||||
);
|
);
|
||||||
|
|
||||||
public static $defaultRepositories = array(
|
public static $defaultRepositories = array(
|
||||||
|
|
|
@ -12,6 +12,10 @@
|
||||||
|
|
||||||
namespace Composer\Downloader;
|
namespace Composer\Downloader;
|
||||||
|
|
||||||
|
use Composer\IO\IOInterface;
|
||||||
|
use Composer\Config;
|
||||||
|
use Composer\Util\Filesystem;
|
||||||
|
use Composer\Util\ProcessExecutor;
|
||||||
use Composer\Package\PackageInterface;
|
use Composer\Package\PackageInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,6 +23,14 @@ use Composer\Package\PackageInterface;
|
||||||
*/
|
*/
|
||||||
class GitDownloader extends VcsDownloader
|
class GitDownloader extends VcsDownloader
|
||||||
{
|
{
|
||||||
|
private $config;
|
||||||
|
|
||||||
|
public function __construct(IOInterface $io, Config $config, ProcessExecutor $process = null, Filesystem $fs = null)
|
||||||
|
{
|
||||||
|
parent::__construct($io, $process, $fs);
|
||||||
|
$this->config = $config;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -150,8 +162,8 @@ class GitDownloader extends VcsDownloader
|
||||||
$handler = array($this, 'outputHandler');
|
$handler = array($this, 'outputHandler');
|
||||||
|
|
||||||
// public github, autoswitch protocols
|
// public github, autoswitch protocols
|
||||||
if (preg_match('{^(?:https?|git)(://github.com/.*)}', $url, $match)) {
|
if (preg_match('{^(?:https?|git)(://github.com/.*)}', $url, $match) && $this->config->has('github-protocols')) {
|
||||||
$protocols = array('git', 'https', 'http');
|
$protocols = (array) $this->config->get('github-protocols');
|
||||||
$messages = array();
|
$messages = array();
|
||||||
foreach ($protocols as $protocol) {
|
foreach ($protocols as $protocol) {
|
||||||
$url = $protocol . $match[1];
|
$url = $protocol . $match[1];
|
||||||
|
|
|
@ -155,7 +155,7 @@ class Factory
|
||||||
$package = $loader->load($localConfig);
|
$package = $loader->load($localConfig);
|
||||||
|
|
||||||
// initialize download manager
|
// initialize download manager
|
||||||
$dm = $this->createDownloadManager($io);
|
$dm = $this->createDownloadManager($io, $config);
|
||||||
|
|
||||||
// initialize installation manager
|
// initialize installation manager
|
||||||
$im = $this->createInstallationManager($config);
|
$im = $this->createInstallationManager($config);
|
||||||
|
@ -219,10 +219,10 @@ class Factory
|
||||||
* @param IO\IOInterface $io
|
* @param IO\IOInterface $io
|
||||||
* @return Downloader\DownloadManager
|
* @return Downloader\DownloadManager
|
||||||
*/
|
*/
|
||||||
public function createDownloadManager(IOInterface $io)
|
public function createDownloadManager(IOInterface $io, Config $config)
|
||||||
{
|
{
|
||||||
$dm = new Downloader\DownloadManager();
|
$dm = new Downloader\DownloadManager();
|
||||||
$dm->setDownloader('git', new Downloader\GitDownloader($io));
|
$dm->setDownloader('git', new Downloader\GitDownloader($io, $config));
|
||||||
$dm->setDownloader('svn', new Downloader\SvnDownloader($io));
|
$dm->setDownloader('svn', new Downloader\SvnDownloader($io));
|
||||||
$dm->setDownloader('hg', new Downloader\HgDownloader($io));
|
$dm->setDownloader('hg', new Downloader\HgDownloader($io));
|
||||||
$dm->setDownloader('zip', new Downloader\ZipDownloader($io));
|
$dm->setDownloader('zip', new Downloader\ZipDownloader($io));
|
||||||
|
|
|
@ -13,16 +13,23 @@
|
||||||
namespace Composer\Test\Downloader;
|
namespace Composer\Test\Downloader;
|
||||||
|
|
||||||
use Composer\Downloader\GitDownloader;
|
use Composer\Downloader\GitDownloader;
|
||||||
|
use Composer\Config;
|
||||||
|
|
||||||
class GitDownloaderTest extends \PHPUnit_Framework_TestCase
|
class GitDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
protected function getDownloaderMock($io = null, $executor = null, $filesystem = null)
|
protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null)
|
||||||
{
|
{
|
||||||
$io = $io ?: $this->getMock('Composer\IO\IOInterface');
|
$io = $io ?: $this->getMock('Composer\IO\IOInterface');
|
||||||
$executor = $executor ?: $this->getMock('Composer\Util\ProcessExecutor');
|
$executor = $executor ?: $this->getMock('Composer\Util\ProcessExecutor');
|
||||||
$filesystem = $filesystem ?: $this->getMock('Composer\Util\Filesystem');
|
$filesystem = $filesystem ?: $this->getMock('Composer\Util\Filesystem');
|
||||||
|
if (!$config) {
|
||||||
|
$config = $this->getMock('Composer\Config');
|
||||||
|
$config->expects($this->any())
|
||||||
|
->method('has')
|
||||||
|
->will($this->returnValue(false));
|
||||||
|
}
|
||||||
|
|
||||||
return new GitDownloader($io, $executor, $filesystem);
|
return new GitDownloader($io, $config, $executor, $filesystem);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,7 +71,7 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($this->equalTo($this->getCmd("git checkout '1234567890123456789012345678901234567890' && git reset --hard '1234567890123456789012345678901234567890'")), $this->equalTo(null), $this->equalTo('composerPath'))
|
->with($this->equalTo($this->getCmd("git checkout '1234567890123456789012345678901234567890' && git reset --hard '1234567890123456789012345678901234567890'")), $this->equalTo(null), $this->equalTo('composerPath'))
|
||||||
->will($this->returnValue(0));
|
->will($this->returnValue(0));
|
||||||
|
|
||||||
$downloader = $this->getDownloaderMock(null, $processExecutor);
|
$downloader = $this->getDownloaderMock(null, null, $processExecutor);
|
||||||
$downloader->download($packageMock, 'composerPath');
|
$downloader->download($packageMock, 'composerPath');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +123,38 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($this->equalTo($this->getCmd("git checkout 'ref' && git reset --hard 'ref'")), $this->equalTo(null), $this->equalTo('composerPath'))
|
->with($this->equalTo($this->getCmd("git checkout 'ref' && git reset --hard 'ref'")), $this->equalTo(null), $this->equalTo('composerPath'))
|
||||||
->will($this->returnValue(0));
|
->will($this->returnValue(0));
|
||||||
|
|
||||||
$downloader = $this->getDownloaderMock(null, $processExecutor);
|
$downloader = $this->getDownloaderMock(null, new Config(), $processExecutor);
|
||||||
|
$downloader->download($packageMock, 'composerPath');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDownloadUsesCustomVariousProtocolsForGithub()
|
||||||
|
{
|
||||||
|
$packageMock = $this->getMock('Composer\Package\PackageInterface');
|
||||||
|
$packageMock->expects($this->any())
|
||||||
|
->method('getSourceReference')
|
||||||
|
->will($this->returnValue('ref'));
|
||||||
|
$packageMock->expects($this->any())
|
||||||
|
->method('getSourceUrl')
|
||||||
|
->will($this->returnValue('https://github.com/composer/composer'));
|
||||||
|
$packageMock->expects($this->any())
|
||||||
|
->method('getPrettyVersion')
|
||||||
|
->will($this->returnValue('1.0.0'));
|
||||||
|
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
|
||||||
|
|
||||||
|
$expectedGitCommand = $this->getCmd("git clone 'http://github.com/composer/composer' 'composerPath' && cd 'composerPath' && git remote add composer 'http://github.com/composer/composer' && git fetch composer");
|
||||||
|
$processExecutor->expects($this->at(0))
|
||||||
|
->method('execute')
|
||||||
|
->with($this->equalTo($expectedGitCommand))
|
||||||
|
->will($this->returnValue(0));
|
||||||
|
|
||||||
|
$processExecutor->expects($this->exactly(4))
|
||||||
|
->method('execute')
|
||||||
|
->will($this->returnValue(0));
|
||||||
|
|
||||||
|
$config = new Config();
|
||||||
|
$config->merge(array('config' => array('github-protocols' => 'http')));
|
||||||
|
|
||||||
|
$downloader = $this->getDownloaderMock(null, $config, $processExecutor);
|
||||||
$downloader->download($packageMock, 'composerPath');
|
$downloader->download($packageMock, 'composerPath');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +177,7 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($this->equalTo($expectedGitCommand))
|
->with($this->equalTo($expectedGitCommand))
|
||||||
->will($this->returnValue(1));
|
->will($this->returnValue(1));
|
||||||
|
|
||||||
$downloader = $this->getDownloaderMock(null, $processExecutor);
|
$downloader = $this->getDownloaderMock(null, null, $processExecutor);
|
||||||
$downloader->download($packageMock, 'composerPath');
|
$downloader->download($packageMock, 'composerPath');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +233,7 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($this->equalTo($this->getCmd("git checkout 'ref' && git reset --hard 'ref'")), $this->equalTo(null), $this->equalTo('composerPath'))
|
->with($this->equalTo($this->getCmd("git checkout 'ref' && git reset --hard 'ref'")), $this->equalTo(null), $this->equalTo('composerPath'))
|
||||||
->will($this->returnValue(0));
|
->will($this->returnValue(0));
|
||||||
|
|
||||||
$downloader = $this->getDownloaderMock(null, $processExecutor);
|
$downloader = $this->getDownloaderMock(null, new Config(), $processExecutor);
|
||||||
$downloader->update($packageMock, $packageMock, 'composerPath');
|
$downloader->update($packageMock, $packageMock, 'composerPath');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,7 +266,7 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($this->equalTo($expectedGitUpdateCommand))
|
->with($this->equalTo($expectedGitUpdateCommand))
|
||||||
->will($this->returnValue(1));
|
->will($this->returnValue(1));
|
||||||
|
|
||||||
$downloader = $this->getDownloaderMock(null, $processExecutor);
|
$downloader = $this->getDownloaderMock(null, new Config(), $processExecutor);
|
||||||
$downloader->update($packageMock, $packageMock, 'composerPath');
|
$downloader->update($packageMock, $packageMock, 'composerPath');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,7 +286,7 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($this->equalTo('composerPath'))
|
->with($this->equalTo('composerPath'))
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
$downloader = $this->getDownloaderMock(null, $processExecutor, $filesystem);
|
$downloader = $this->getDownloaderMock(null, null, $processExecutor, $filesystem);
|
||||||
$downloader->remove($packageMock, 'composerPath');
|
$downloader->remove($packageMock, 'composerPath');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue