diff --git a/src/Composer/Compiler.php b/src/Composer/Compiler.php index 69e98e91a..6fccb8e96 100644 --- a/src/Composer/Compiler.php +++ b/src/Composer/Compiler.php @@ -164,10 +164,24 @@ class Compiler $util->save($pharFile, \Phar::SHA1); } - private function addFile($phar, $file, $strip = true) + /** + * @param \SplFileInfo $file + * @return string + */ + private function getRelativeFilePath($file) { - $path = strtr(str_replace(dirname(dirname(__DIR__)).DIRECTORY_SEPARATOR, '', $file->getRealPath()), '\\', '/'); + $realPath = $file->getRealPath(); + $pathPrefix = dirname(dirname(__DIR__)).DIRECTORY_SEPARATOR; + + $pos = strpos($realPath, $pathPrefix); + $relativePath = ($pos !== false) ? substr_replace($realPath, '', $pos, strlen($pathPrefix)) : $realPath; + return strtr($relativePath, '\\', '/'); + } + + private function addFile($phar, $file, $strip = true) + { + $path = $this->getRelativeFilePath($file); $content = file_get_contents($file); if ($strip) { $content = $this->stripWhitespace($content); diff --git a/src/Composer/Downloader/PathDownloader.php b/src/Composer/Downloader/PathDownloader.php index 213be04a1..250a01c3f 100644 --- a/src/Composer/Downloader/PathDownloader.php +++ b/src/Composer/Downloader/PathDownloader.php @@ -12,12 +12,14 @@ namespace Composer\Downloader; +use Composer\Package\Archiver\ArchivableFilesFinder; use Composer\Package\Dumper\ArrayDumper; use Composer\Package\PackageInterface; use Composer\Package\Version\VersionGuesser; use Composer\Package\Version\VersionParser; use Composer\Util\Platform; use Composer\Util\ProcessExecutor; +use Composer\Util\Filesystem as ComposerFilesystem; use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Filesystem; @@ -118,8 +120,12 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter // Fallback if symlink failed or if symlink is not allowed for the package if (self::STRATEGY_MIRROR == $currentStrategy) { + $fs = new ComposerFilesystem(); + $realUrl = $fs->normalizePath($realUrl); + $this->io->writeError(sprintf('%sMirroring from %s', $isFallback ? ' ' : '', $url), false); - $fileSystem->mirror($realUrl, $path); + $iterator = new ArchivableFilesFinder($realUrl, array()); + $fileSystem->mirror($realUrl, $path, $iterator); } $this->io->writeError(''); diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index ca7deb3ac..55ec51baf 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -1309,7 +1309,7 @@ class Installer $skipPackages[$require->getTarget()] = true; } - $pool = new Pool; + $pool = new Pool('dev'); $pool->addRepository($localOrLockRepo); $seen = array(); diff --git a/src/Composer/Repository/Vcs/GitLabDriver.php b/src/Composer/Repository/Vcs/GitLabDriver.php index f2813db54..45cdac717 100644 --- a/src/Composer/Repository/Vcs/GitLabDriver.php +++ b/src/Composer/Repository/Vcs/GitLabDriver.php @@ -308,7 +308,12 @@ class GitLabDriver extends VcsDriver // we need to fetch the default branch from the api $resource = $this->getApiUrl(); $this->project = JsonFile::parseJson($this->getContents($resource, true), $resource); - $this->isPrivate = $this->project['visibility'] !== 'public'; + if (isset($this->project['visibility'])) { + $this->isPrivate = $this->project['visibility'] !== 'public'; + } else { + // client is not authendicated, therefore repository has to be public + $this->isPrivate = false; + } } protected function attemptCloneFallback() diff --git a/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php index 1564412d8..25634138f 100644 --- a/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php @@ -142,6 +142,44 @@ JSON; return $driver; } + /** + * @dataProvider getInitializeUrls + */ + public function testInitializePublicProjectAsAnonymous($url, $apiUrl) + { + // @link http://doc.gitlab.com/ce/api/projects.html#get-single-project + $projectData = <<remoteFilesystem + ->getContents('gitlab.com', $apiUrl, false, array()) + ->willReturn($projectData) + ->shouldBeCalledTimes(1) + ; + + $driver = new GitLabDriver(array('url' => $url), $this->io->reveal(), $this->config, $this->process->reveal(), $this->remoteFilesystem->reveal()); + $driver->initialize(); + + $this->assertEquals($apiUrl, $driver->getApiUrl(), 'API URL is derived from the repository URL'); + $this->assertEquals('mymaster', $driver->getRootIdentifier(), 'Root identifier is the default branch in GitLab'); + $this->assertEquals('https://gitlab.com/mygroup/myproject.git', $driver->getRepositoryUrl(), 'The repository URL is the SSH one by default'); + $this->assertEquals('https://gitlab.com/mygroup/myproject', $driver->getUrl()); + + return $driver; + } + public function testGetDist() { $driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject');