mirror of
https://github.com/composer/composer
synced 2025-05-10 00:53:06 +00:00
Merge remote-tracking branch 'GromNaN/git-dir'
This commit is contained in:
commit
115dc407fa
12 changed files with 62 additions and 82 deletions
|
@ -27,20 +27,14 @@ class GitBitbucketDriver extends VcsDriver implements VcsDriverInterface
|
|||
protected $rootIdentifier;
|
||||
protected $infoCache = array();
|
||||
|
||||
public function __construct($url, IOInterface $io)
|
||||
{
|
||||
preg_match('#^https://bitbucket\.org/([^/]+)/(.+?)\.git$#', $url, $match);
|
||||
$this->owner = $match[1];
|
||||
$this->repository = $match[2];
|
||||
|
||||
parent::__construct($url, $io);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
preg_match('#^https://bitbucket\.org/([^/]+)/(.+?)\.git$#', $this->url, $match);
|
||||
$this->owner = $match[1];
|
||||
$this->repository = $match[2];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,11 +28,6 @@ class GitDriver extends VcsDriver
|
|||
protected $repoDir;
|
||||
protected $infoCache = array();
|
||||
|
||||
public function __construct($url, IOInterface $io, ProcessExecutor $process = null)
|
||||
{
|
||||
parent::__construct($url, $io, $process);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -41,7 +36,7 @@ class GitDriver extends VcsDriver
|
|||
if (static::isLocalUrl($this->url)) {
|
||||
$this->repoDir = str_replace('file://', '', $this->url);
|
||||
} else {
|
||||
$this->repoDir = sys_get_temp_dir() . '/composer-' . preg_replace('{[^a-z0-9.]}i', '-', $this->url) . '/';
|
||||
$this->repoDir = $this->config->get('home') . '/cache.git/' . preg_replace('{[^a-z0-9.]}i', '-', $this->url) . '/';
|
||||
|
||||
// update the repo if it is a valid git repository
|
||||
if (is_dir($this->repoDir) && 0 === $this->process->execute('git remote', $output, $this->repoDir)) {
|
||||
|
|
|
@ -38,28 +38,15 @@ class GitHubDriver extends VcsDriver
|
|||
*/
|
||||
protected $gitDriver;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $url
|
||||
* @param IOInterface $io
|
||||
* @param ProcessExecutor $process
|
||||
* @param RemoteFilesystem $remoteFilesystem
|
||||
*/
|
||||
public function __construct($url, IOInterface $io, ProcessExecutor $process = null, RemoteFilesystem $remoteFilesystem = null)
|
||||
{
|
||||
preg_match('#^(?:https?|git)://github\.com/([^/]+)/(.+?)(?:\.git)?$#', $url, $match);
|
||||
$this->owner = $match[1];
|
||||
$this->repository = $match[2];
|
||||
|
||||
parent::__construct($url, $io, $process, $remoteFilesystem);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
preg_match('#^(?:https?|git)://github\.com/([^/]+)/(.+?)(?:\.git)?$#', $this->url, $match);
|
||||
$this->owner = $match[1];
|
||||
$this->repository = $match[2];
|
||||
|
||||
$this->fetchRootIdentifier();
|
||||
}
|
||||
|
||||
|
@ -248,6 +235,7 @@ class GitHubDriver extends VcsDriver
|
|||
$this->gitDriver = new GitDriver(
|
||||
$this->generateSshUrl(),
|
||||
$this->io,
|
||||
$this->config,
|
||||
$this->process,
|
||||
$this->remoteFilesystem
|
||||
);
|
||||
|
|
|
@ -27,20 +27,14 @@ class HgBitbucketDriver extends VcsDriver
|
|||
protected $rootIdentifier;
|
||||
protected $infoCache = array();
|
||||
|
||||
public function __construct($url, IOInterface $io)
|
||||
{
|
||||
preg_match('#^https://bitbucket\.org/([^/]+)/([^/]+)/?$#', $url, $match);
|
||||
$this->owner = $match[1];
|
||||
$this->repository = $match[2];
|
||||
|
||||
parent::__construct($url, $io);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
preg_match('#^https://bitbucket\.org/([^/]+)/([^/]+)/?$#', $this->url, $match);
|
||||
$this->owner = $match[1];
|
||||
$this->repository = $match[2];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,24 +26,21 @@ class HgDriver extends VcsDriver
|
|||
protected $rootIdentifier;
|
||||
protected $infoCache = array();
|
||||
|
||||
public function __construct($url, IOInterface $io, ProcessExecutor $process = null)
|
||||
{
|
||||
$this->tmpDir = sys_get_temp_dir() . '/composer-' . preg_replace('{[^a-z0-9]}i', '-', $url) . '/';
|
||||
|
||||
parent::__construct($url, $io, $process);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
$url = escapeshellarg($this->url);
|
||||
$tmpDir = escapeshellarg($this->tmpDir);
|
||||
$this->tmpDir = $this->config->get('home') . '/cache.hg/' . preg_replace('{[^a-z0-9]}i', '-', $this->url) . '/';
|
||||
|
||||
if (is_dir($this->tmpDir)) {
|
||||
$this->process->execute(sprintf('cd %s && hg pull -u', $tmpDir), $output);
|
||||
$this->process->execute(sprintf('cd %s && hg pull -u', escapeshellarg($this->tmpDir)), $output);
|
||||
} else {
|
||||
$this->process->execute(sprintf('cd %s && hg clone %s %s', escapeshellarg(sys_get_temp_dir()), $url, $tmpDir), $output);
|
||||
$dir = dirname($this->tmpDir);
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir, 0777, true);
|
||||
}
|
||||
$this->process->execute(sprintf('cd %s && hg clone %s %s', escapeshellarg($dir), escapeshellarg($this->url), escapeshellarg($this->tmpDir)), $output);
|
||||
}
|
||||
|
||||
$this->getTags();
|
||||
|
|
|
@ -33,25 +33,7 @@ class SvnDriver extends VcsDriver
|
|||
/**
|
||||
* @var \Composer\Util\Svn
|
||||
*/
|
||||
protected $util;
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @param IOInterface $io
|
||||
* @param ProcessExecutor $process
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function __construct($url, IOInterface $io, ProcessExecutor $process = null)
|
||||
{
|
||||
$url = self::normalizeUrl($url);
|
||||
parent::__construct($this->baseUrl = rtrim($url, '/'), $io, $process);
|
||||
|
||||
if (false !== ($pos = strrpos($url, '/trunk'))) {
|
||||
$this->baseUrl = substr($url, 0, $pos);
|
||||
}
|
||||
$this->util = new SvnUtil($this->baseUrl, $io, $this->process);
|
||||
}
|
||||
private $util;
|
||||
|
||||
/**
|
||||
* Execute an SVN command and try to fix up the process with credentials
|
||||
|
@ -64,6 +46,10 @@ class SvnDriver extends VcsDriver
|
|||
*/
|
||||
protected function execute($command, $url)
|
||||
{
|
||||
if (null === $this->util) {
|
||||
$this->util = new SvnUtil($this->baseUrl, $this->io, $this->process);
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->util->execute($command, $url);
|
||||
} catch (\RuntimeException $e) {
|
||||
|
@ -78,6 +64,12 @@ class SvnDriver extends VcsDriver
|
|||
*/
|
||||
public function initialize()
|
||||
{
|
||||
$this->url = rtrim(self::normalizeUrl($this->url), '/');
|
||||
|
||||
if (false !== ($pos = strrpos($this->url, '/trunk'))) {
|
||||
$this->baseUrl = substr($this->url, 0, $pos);
|
||||
}
|
||||
|
||||
$this->getBranches();
|
||||
$this->getTags();
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
namespace Composer\Repository\Vcs;
|
||||
|
||||
use Composer\Downloader\TransportException;
|
||||
use Composer\Config;
|
||||
use Composer\IO\IOInterface;
|
||||
use Composer\Util\ProcessExecutor;
|
||||
use Composer\Util\RemoteFilesystem;
|
||||
|
@ -26,6 +27,7 @@ abstract class VcsDriver implements VcsDriverInterface
|
|||
{
|
||||
protected $url;
|
||||
protected $io;
|
||||
protected $config;
|
||||
protected $process;
|
||||
protected $remoteFilesystem;
|
||||
|
||||
|
@ -34,13 +36,15 @@ abstract class VcsDriver implements VcsDriverInterface
|
|||
*
|
||||
* @param string $url The URL
|
||||
* @param IOInterface $io The IO instance
|
||||
* @param Config $config The composer configuration
|
||||
* @param ProcessExecutor $process Process instance, injectable for mocking
|
||||
* @param callable $remoteFilesystem Remote Filesystem, injectable for mocking
|
||||
*/
|
||||
public function __construct($url, IOInterface $io, ProcessExecutor $process = null, $remoteFilesystem = null)
|
||||
final public function __construct($url, IOInterface $io, Config $config, ProcessExecutor $process = null, $remoteFilesystem = null)
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->io = $io;
|
||||
$this->config = $config;
|
||||
$this->process = $process ?: new ProcessExecutor;
|
||||
$this->remoteFilesystem = $remoteFilesystem ?: new RemoteFilesystem($io);
|
||||
}
|
||||
|
@ -58,7 +62,6 @@ abstract class VcsDriver implements VcsDriverInterface
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the https or http protocol depending on SSL support.
|
||||
*
|
||||
|
|
|
@ -30,6 +30,7 @@ class VcsRepository extends ArrayRepository
|
|||
protected $packageName;
|
||||
protected $verbose;
|
||||
protected $io;
|
||||
protected $config;
|
||||
protected $versionParser;
|
||||
protected $type;
|
||||
|
||||
|
@ -48,20 +49,21 @@ class VcsRepository extends ArrayRepository
|
|||
$this->io = $io;
|
||||
$this->type = isset($repoConfig['type']) ? $repoConfig['type'] : 'vcs';
|
||||
$this->verbose = $io->isVerbose();
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function getDriver()
|
||||
{
|
||||
if (isset($this->drivers[$this->type])) {
|
||||
$class = $this->drivers[$this->type];
|
||||
$driver = new $class($this->url, $this->io);
|
||||
$driver = new $class($this->url, $this->io, $this->config);
|
||||
$driver->initialize();
|
||||
return $driver;
|
||||
}
|
||||
|
||||
foreach ($this->drivers as $driver) {
|
||||
if ($driver::supports($this->io, $this->url)) {
|
||||
$driver = new $driver($this->url, $this->io);
|
||||
$driver = new $driver($this->url, $this->io, $this->config);
|
||||
$driver->initialize();
|
||||
return $driver;
|
||||
}
|
||||
|
@ -69,7 +71,7 @@ class VcsRepository extends ArrayRepository
|
|||
|
||||
foreach ($this->drivers as $driver) {
|
||||
if ($driver::supports($this->io, $this->url, true)) {
|
||||
$driver = new $driver($this->url, $this->io);
|
||||
$driver = new $driver($this->url, $this->io, $this->config);
|
||||
$driver->initialize();
|
||||
return $driver;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue