From d489d2aa3ce66b66ece33522c7216be81b68eafb Mon Sep 17 00:00:00 2001 From: Jerome Tamarelle Date: Tue, 24 Apr 2012 14:39:30 +0200 Subject: [PATCH 01/11] Store cached git repositories in user HOME to avoid file permission issues --- src/Composer/Repository/Vcs/GitDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Repository/Vcs/GitDriver.php b/src/Composer/Repository/Vcs/GitDriver.php index 73f9e1aed..4fe4fafb4 100644 --- a/src/Composer/Repository/Vcs/GitDriver.php +++ b/src/Composer/Repository/Vcs/GitDriver.php @@ -41,7 +41,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 = getenv('HOME') . '/.composer/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)) { From 017ebabcb5e9470c044bdbd3514c7bf93bc79b24 Mon Sep 17 00:00:00 2001 From: Jerome Tamarelle Date: Tue, 24 Apr 2012 16:56:03 +0200 Subject: [PATCH 02/11] Pass composer configuration to VcsDriver --- src/Composer/Repository/Vcs/VcsDriver.php | 7 +++++-- src/Composer/Repository/VcsRepository.php | 8 +++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Composer/Repository/Vcs/VcsDriver.php b/src/Composer/Repository/Vcs/VcsDriver.php index 99c705c50..f8d9893b9 100644 --- a/src/Composer/Repository/Vcs/VcsDriver.php +++ b/src/Composer/Repository/Vcs/VcsDriver.php @@ -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) + 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. * diff --git a/src/Composer/Repository/VcsRepository.php b/src/Composer/Repository/VcsRepository.php index b70e7c09d..ecc435582 100644 --- a/src/Composer/Repository/VcsRepository.php +++ b/src/Composer/Repository/VcsRepository.php @@ -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; } From 949728f81274cf2d828b52c1342f90b959c70ed2 Mon Sep 17 00:00:00 2001 From: Jerome Tamarelle Date: Tue, 24 Apr 2012 16:58:29 +0200 Subject: [PATCH 03/11] Remove redundant __contruct from VcsDriver implementations and move init code to initialize method --- .../Repository/Vcs/GitBitbucketDriver.php | 12 +++------ src/Composer/Repository/Vcs/GitDriver.php | 5 ---- src/Composer/Repository/Vcs/GitHubDriver.php | 21 +++------------- .../Repository/Vcs/HgBitbucketDriver.php | 12 +++------ src/Composer/Repository/Vcs/HgDriver.php | 9 ++----- src/Composer/Repository/Vcs/SvnDriver.php | 25 ++++++------------- src/Composer/Repository/Vcs/VcsDriver.php | 2 +- 7 files changed, 20 insertions(+), 66 deletions(-) diff --git a/src/Composer/Repository/Vcs/GitBitbucketDriver.php b/src/Composer/Repository/Vcs/GitBitbucketDriver.php index c0132cd10..b5cb8960d 100644 --- a/src/Composer/Repository/Vcs/GitBitbucketDriver.php +++ b/src/Composer/Repository/Vcs/GitBitbucketDriver.php @@ -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]; } /** diff --git a/src/Composer/Repository/Vcs/GitDriver.php b/src/Composer/Repository/Vcs/GitDriver.php index 4fe4fafb4..dd927fd1c 100644 --- a/src/Composer/Repository/Vcs/GitDriver.php +++ b/src/Composer/Repository/Vcs/GitDriver.php @@ -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} */ diff --git a/src/Composer/Repository/Vcs/GitHubDriver.php b/src/Composer/Repository/Vcs/GitHubDriver.php index 42633aafe..61a0589ac 100644 --- a/src/Composer/Repository/Vcs/GitHubDriver.php +++ b/src/Composer/Repository/Vcs/GitHubDriver.php @@ -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(); } diff --git a/src/Composer/Repository/Vcs/HgBitbucketDriver.php b/src/Composer/Repository/Vcs/HgBitbucketDriver.php index 993ece82d..43fff9aba 100644 --- a/src/Composer/Repository/Vcs/HgBitbucketDriver.php +++ b/src/Composer/Repository/Vcs/HgBitbucketDriver.php @@ -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]; } /** diff --git a/src/Composer/Repository/Vcs/HgDriver.php b/src/Composer/Repository/Vcs/HgDriver.php index 833669cf9..17310d630 100644 --- a/src/Composer/Repository/Vcs/HgDriver.php +++ b/src/Composer/Repository/Vcs/HgDriver.php @@ -26,18 +26,13 @@ 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() { + $this->tmpDir = sys_get_temp_dir() . '/composer-' . preg_replace('{[^a-z0-9]}i', '-', $url) . '/'; + $url = escapeshellarg($this->url); $tmpDir = escapeshellarg($this->tmpDir); if (is_dir($this->tmpDir)) { diff --git a/src/Composer/Repository/Vcs/SvnDriver.php b/src/Composer/Repository/Vcs/SvnDriver.php index 6f13296ce..f5c3e04cd 100644 --- a/src/Composer/Repository/Vcs/SvnDriver.php +++ b/src/Composer/Repository/Vcs/SvnDriver.php @@ -35,24 +35,6 @@ class SvnDriver extends VcsDriver */ 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); - } - /** * Execute an SVN command and try to fix up the process with credentials * if necessary. @@ -78,6 +60,13 @@ class SvnDriver extends VcsDriver */ public function initialize() { + $this->url = rtrim(self::normalizeUrl($this->url), '/'); + + if (false !== ($pos = strrpos($url, '/trunk'))) { + $this->baseUrl = substr($url, 0, $pos); + } + $this->util = new SvnUtil($this->baseUrl, $this->io, $this->process); + $this->getBranches(); $this->getTags(); } diff --git a/src/Composer/Repository/Vcs/VcsDriver.php b/src/Composer/Repository/Vcs/VcsDriver.php index f8d9893b9..d13b4b4a1 100644 --- a/src/Composer/Repository/Vcs/VcsDriver.php +++ b/src/Composer/Repository/Vcs/VcsDriver.php @@ -40,7 +40,7 @@ abstract class VcsDriver implements VcsDriverInterface * @param ProcessExecutor $process Process instance, injectable for mocking * @param callable $remoteFilesystem Remote Filesystem, injectable for mocking */ - public function __construct($url, IOInterface $io, Config $config, 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; From da823f5f19c055e13ad001e01a4ee956e55398ce Mon Sep 17 00:00:00 2001 From: Jerome Tamarelle Date: Tue, 24 Apr 2012 17:03:15 +0200 Subject: [PATCH 04/11] Store vcs repositories in composer home to prevent permission issues --- src/Composer/Repository/Vcs/GitDriver.php | 2 +- src/Composer/Repository/Vcs/HgDriver.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Composer/Repository/Vcs/GitDriver.php b/src/Composer/Repository/Vcs/GitDriver.php index dd927fd1c..94ccb61ce 100644 --- a/src/Composer/Repository/Vcs/GitDriver.php +++ b/src/Composer/Repository/Vcs/GitDriver.php @@ -36,7 +36,7 @@ class GitDriver extends VcsDriver if (static::isLocalUrl($this->url)) { $this->repoDir = str_replace('file://', '', $this->url); } else { - $this->repoDir = getenv('HOME') . '/.composer/cache.git/' . 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)) { diff --git a/src/Composer/Repository/Vcs/HgDriver.php b/src/Composer/Repository/Vcs/HgDriver.php index 17310d630..aa0ee6bfd 100644 --- a/src/Composer/Repository/Vcs/HgDriver.php +++ b/src/Composer/Repository/Vcs/HgDriver.php @@ -31,14 +31,14 @@ class HgDriver extends VcsDriver */ public function initialize() { - $this->tmpDir = sys_get_temp_dir() . '/composer-' . preg_replace('{[^a-z0-9]}i', '-', $url) . '/'; + $this->tmpDir = $this->config->get('home') . '/cache.hg/' . preg_replace('{[^a-z0-9]}i', '-', $url) . '/'; $url = escapeshellarg($this->url); $tmpDir = escapeshellarg($this->tmpDir); if (is_dir($this->tmpDir)) { $this->process->execute(sprintf('cd %s && hg pull -u', $tmpDir), $output); } else { - $this->process->execute(sprintf('cd %s && hg clone %s %s', escapeshellarg(sys_get_temp_dir()), $url, $tmpDir), $output); + $this->process->execute(sprintf('cd %s && hg clone %s %s', escapeshellarg(dirname($this->tmpDir)), $url, $tmpDir), $output); } $this->getTags(); From cc6e1397b2230a553a69dde6f2d353918c5870cc Mon Sep 17 00:00:00 2001 From: Jerome Tamarelle Date: Tue, 24 Apr 2012 17:15:31 +0200 Subject: [PATCH 05/11] Fix var scope --- src/Composer/Repository/Vcs/SvnDriver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Composer/Repository/Vcs/SvnDriver.php b/src/Composer/Repository/Vcs/SvnDriver.php index f5c3e04cd..388b21f34 100644 --- a/src/Composer/Repository/Vcs/SvnDriver.php +++ b/src/Composer/Repository/Vcs/SvnDriver.php @@ -62,8 +62,8 @@ class SvnDriver extends VcsDriver { $this->url = rtrim(self::normalizeUrl($this->url), '/'); - if (false !== ($pos = strrpos($url, '/trunk'))) { - $this->baseUrl = substr($url, 0, $pos); + if (false !== ($pos = strrpos($this->url, '/trunk'))) { + $this->baseUrl = substr($this->url, 0, $pos); } $this->util = new SvnUtil($this->baseUrl, $this->io, $this->process); From d2004810370e89840c608c4b0e86896b81fae7e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 25 Apr 2012 09:49:05 +0300 Subject: [PATCH 06/11] Fix tmp dir for HgDriver --- src/Composer/Repository/Vcs/HgDriver.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Composer/Repository/Vcs/HgDriver.php b/src/Composer/Repository/Vcs/HgDriver.php index aa0ee6bfd..08f34be9a 100644 --- a/src/Composer/Repository/Vcs/HgDriver.php +++ b/src/Composer/Repository/Vcs/HgDriver.php @@ -34,11 +34,10 @@ class HgDriver extends VcsDriver $this->tmpDir = $this->config->get('home') . '/cache.hg/' . preg_replace('{[^a-z0-9]}i', '-', $url) . '/'; $url = escapeshellarg($this->url); - $tmpDir = escapeshellarg($this->tmpDir); 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(dirname($this->tmpDir)), $url, $tmpDir), $output); + $this->process->execute(sprintf('cd %s && hg clone %s %s', escapeshellarg(dirname($this->tmpDir)), $url, escapeshellarg($this->tmpDir)), $output); } $this->getTags(); From 23ef8a419a8f65fee30a1acc036929ef1ee52ed5 Mon Sep 17 00:00:00 2001 From: Jerome Tamarelle Date: Wed, 25 Apr 2012 10:09:31 +0200 Subject: [PATCH 07/11] Fix var scope in HgDriver --- src/Composer/Repository/Vcs/HgDriver.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Composer/Repository/Vcs/HgDriver.php b/src/Composer/Repository/Vcs/HgDriver.php index 08f34be9a..ddfdbe69b 100644 --- a/src/Composer/Repository/Vcs/HgDriver.php +++ b/src/Composer/Repository/Vcs/HgDriver.php @@ -31,13 +31,12 @@ class HgDriver extends VcsDriver */ public function initialize() { - $this->tmpDir = $this->config->get('home') . '/cache.hg/' . preg_replace('{[^a-z0-9]}i', '-', $url) . '/'; + $this->tmpDir = $this->config->get('home') . '/cache.hg/' . preg_replace('{[^a-z0-9]}i', '-', $this->url) . '/'; - $url = escapeshellarg($this->url); if (is_dir($this->tmpDir)) { $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(dirname($this->tmpDir)), $url, escapeshellarg($this->tmpDir)), $output); + $this->process->execute(sprintf('cd %s && hg clone %s %s', escapeshellarg(dirname($this->tmpDir)), escapeshellarg($this->url), escapeshellarg($this->tmpDir)), $output); } $this->getTags(); From 8b408449f6cd52c82354599b0ba4591f73c568de Mon Sep 17 00:00:00 2001 From: Jerome Tamarelle Date: Wed, 25 Apr 2012 10:13:02 +0200 Subject: [PATCH 08/11] Create ~/.composer/cache.hg directory if not exists --- src/Composer/Repository/Vcs/HgDriver.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Composer/Repository/Vcs/HgDriver.php b/src/Composer/Repository/Vcs/HgDriver.php index ddfdbe69b..a59407d48 100644 --- a/src/Composer/Repository/Vcs/HgDriver.php +++ b/src/Composer/Repository/Vcs/HgDriver.php @@ -36,7 +36,11 @@ class HgDriver extends VcsDriver if (is_dir($this->tmpDir)) { $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(dirname($this->tmpDir)), escapeshellarg($this->url), escapeshellarg($this->tmpDir)), $output); + $dir = dirname($this->tmpDir); + if (!is_dir($dir)) { + mkdir($dir, 0777 & ~umask(), true); + } + $this->process->execute(sprintf('cd %s && hg clone %s %s', escapeshellarg($dir), escapeshellarg($this->url), escapeshellarg($this->tmpDir)), $output); } $this->getTags(); From f0ea097134d9d20837d4203f50f952017b13716a Mon Sep 17 00:00:00 2001 From: Jerome Tamarelle Date: Wed, 25 Apr 2012 10:13:02 +0200 Subject: [PATCH 09/11] Remove umask --- src/Composer/Repository/Vcs/HgDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Repository/Vcs/HgDriver.php b/src/Composer/Repository/Vcs/HgDriver.php index a59407d48..45186da7c 100644 --- a/src/Composer/Repository/Vcs/HgDriver.php +++ b/src/Composer/Repository/Vcs/HgDriver.php @@ -38,7 +38,7 @@ class HgDriver extends VcsDriver } else { $dir = dirname($this->tmpDir); if (!is_dir($dir)) { - mkdir($dir, 0777 & ~umask(), true); + mkdir($dir, 0777, true); } $this->process->execute(sprintf('cd %s && hg clone %s %s', escapeshellarg($dir), escapeshellarg($this->url), escapeshellarg($this->tmpDir)), $output); } From 1139b5c306ca7348c5aaac398d0bcb6f02da1a5d Mon Sep 17 00:00:00 2001 From: Jerome Tamarelle Date: Wed, 25 Apr 2012 16:36:18 +0200 Subject: [PATCH 10/11] Protect composer home against web access --- src/Composer/Factory.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index 2996c50a5..8929481c6 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -38,6 +38,11 @@ class Factory } } + // Protect directory against web access + if (!file_exists($home . '/.htaccess')) { + @mkdir($home, 0777, true) && @file_put_contents($home . '/.htaccess', 'deny from all'); + } + $config = new Config(); $file = new JsonFile($home.'/config.json'); From 610f15a768ec6fc4e896fff8ef913ce5d8a55475 Mon Sep 17 00:00:00 2001 From: Jerome Tamarelle Date: Wed, 25 Apr 2012 17:35:47 +0200 Subject: [PATCH 11/11] Fix unit tests for VcsRepository --- src/Composer/Repository/Vcs/GitHubDriver.php | 1 + src/Composer/Repository/Vcs/SvnDriver.php | 7 +++++-- .../Test/Repository/Vcs/GitHubDriverTest.php | 16 ++++++++++++---- .../Test/Repository/Vcs/SvnDriverTest.php | 3 ++- .../Test/Repository/VcsRepositoryTest.php | 3 ++- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/Composer/Repository/Vcs/GitHubDriver.php b/src/Composer/Repository/Vcs/GitHubDriver.php index 61a0589ac..9091d0c6f 100644 --- a/src/Composer/Repository/Vcs/GitHubDriver.php +++ b/src/Composer/Repository/Vcs/GitHubDriver.php @@ -235,6 +235,7 @@ class GitHubDriver extends VcsDriver $this->gitDriver = new GitDriver( $this->generateSshUrl(), $this->io, + $this->config, $this->process, $this->remoteFilesystem ); diff --git a/src/Composer/Repository/Vcs/SvnDriver.php b/src/Composer/Repository/Vcs/SvnDriver.php index 388b21f34..d431cb288 100644 --- a/src/Composer/Repository/Vcs/SvnDriver.php +++ b/src/Composer/Repository/Vcs/SvnDriver.php @@ -33,7 +33,7 @@ class SvnDriver extends VcsDriver /** * @var \Composer\Util\Svn */ - protected $util; + private $util; /** * Execute an SVN command and try to fix up the process with credentials @@ -46,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) { @@ -65,7 +69,6 @@ class SvnDriver extends VcsDriver if (false !== ($pos = strrpos($this->url, '/trunk'))) { $this->baseUrl = substr($this->url, 0, $pos); } - $this->util = new SvnUtil($this->baseUrl, $this->io, $this->process); $this->getBranches(); $this->getTags(); diff --git a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php index 845fb990f..88483bff8 100644 --- a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php @@ -15,6 +15,7 @@ namespace Composer\Test\Repository\Vcs; use Composer\Downloader\TransportException; use Composer\Repository\Vcs\GitHubDriver; use Composer\Util\Filesystem; +use Composer\Config; /** * @author Beau Simensen @@ -64,7 +65,7 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase ->with($this->equalTo($repoUrl), $this->equalTo($repoApiUrl), $this->equalTo(false)) ->will($this->returnValue('{"master_branch": "test_master"}')); - $gitHubDriver = new GitHubDriver($repoUrl, $io, null, $remoteFilesystem); + $gitHubDriver = new GitHubDriver($repoUrl, $io, new Config(), null, $remoteFilesystem); $gitHubDriver->initialize(); $this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha)); @@ -114,7 +115,7 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase ->with($this->equalTo($repoUrl), $this->equalTo($repoApiUrl), $this->equalTo(false)) ->will($this->returnValue('{"master_branch": "test_master"}')); - $gitHubDriver = new GitHubDriver($repoUrl, $io, null, $remoteFilesystem); + $gitHubDriver = new GitHubDriver($repoUrl, $io, new Config(), null, $remoteFilesystem); $gitHubDriver->initialize(); $this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha)); @@ -171,7 +172,14 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase // clean local clone if present $fs = new Filesystem(); - $fs->removeDirectory(sys_get_temp_dir() . '/composer-' . preg_replace('{[^a-z0-9.]}i', '-', $repoSshUrl) . '/'); + $fs->removeDirectory(sys_get_temp_dir() . '/composer-test'); + + $config = new Config(); + $config->merge(array( + 'config' => array( + 'home' => sys_get_temp_dir() . '/composer-test', + ), + )); $process->expects($this->at(0)) ->method('execute') @@ -202,7 +210,7 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase ->method('splitLines') ->will($this->returnValue(array('* test_master'))); - $gitHubDriver = new GitHubDriver($repoUrl, $io, $process, $remoteFilesystem); + $gitHubDriver = new GitHubDriver($repoUrl, $io, $config, $process, $remoteFilesystem); $gitHubDriver->initialize(); $this->assertEquals('test_master', $gitHubDriver->getRootIdentifier()); diff --git a/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php b/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php index 5399c394e..6f85faa0c 100644 --- a/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php @@ -14,6 +14,7 @@ namespace Composer\Test\Repository\Vcs; use Composer\Repository\Vcs\SvnDriver; use Composer\IO\NullIO; +use Composer\Config; class SvnDriverTest extends \PHPUnit_Framework_TestCase { @@ -39,7 +40,7 @@ class SvnDriverTest extends \PHPUnit_Framework_TestCase ->method('getErrorOutput') ->will($this->returnValue($output)); - $svn = new SvnDriver('http://till:secret@corp.svn.local/repo', $console, $process); + $svn = new SvnDriver('http://till:secret@corp.svn.local/repo', $console, new Config(), $process); $svn->getTags(); } diff --git a/tests/Composer/Test/Repository/VcsRepositoryTest.php b/tests/Composer/Test/Repository/VcsRepositoryTest.php index 9c09db0a2..c2060d5b7 100644 --- a/tests/Composer/Test/Repository/VcsRepositoryTest.php +++ b/tests/Composer/Test/Repository/VcsRepositoryTest.php @@ -19,6 +19,7 @@ use Composer\Repository\Vcs\GitDriver; use Composer\Util\Filesystem; use Composer\Util\ProcessExecutor; use Composer\IO\NullIO; +use Composer\Config; class VcsRepositoryTest extends \PHPUnit_Framework_TestCase { @@ -123,7 +124,7 @@ class VcsRepositoryTest extends \PHPUnit_Framework_TestCase 'dev-master' => true, ); - $repo = new VcsRepository(array('url' => self::$gitRepo, 'type' => 'vcs'), new NullIO); + $repo = new VcsRepository(array('url' => self::$gitRepo, 'type' => 'vcs'), new NullIO, new Config()); $packages = $repo->getPackages(); $dumper = new ArrayDumper();