From dc509b236fad2604d12b251c69884a9f3b3f4173 Mon Sep 17 00:00:00 2001 From: Fedir Kryvytskyi Date: Wed, 6 Sep 2017 21:25:12 +0200 Subject: [PATCH 1/5] Fixed error, when composer.phar was broken, if it compiled inside folder, that has /composer in path --- src/Composer/Compiler.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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); From 37addea4471fb35411f49e437a211d78e2b9776e Mon Sep 17 00:00:00 2001 From: Abyr Valg Date: Wed, 6 Sep 2017 13:26:49 +0300 Subject: [PATCH 2/5] Make composer see installed dev packages --- src/Composer/Installer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(); From 2a89d37651a3016c20089165a3f1b56351d3896c Mon Sep 17 00:00:00 2001 From: Mikk Tendermann Date: Thu, 31 Aug 2017 20:14:41 +0300 Subject: [PATCH 3/5] fix gitlab not telling visibilty if user is not logged in --- src/Composer/Repository/Vcs/GitLabDriver.php | 7 +++- .../Test/Repository/Vcs/GitLabDriverTest.php | 38 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) 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'); From b859bbcdcf3bf4ef168235fc63b67f49c7a21356 Mon Sep 17 00:00:00 2001 From: Gawain Lynch Date: Fri, 8 Sep 2017 06:35:36 +0200 Subject: [PATCH 4/5] Pass a VCS filtered iterator to mirror --- src/Composer/Downloader/PathDownloader.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Composer/Downloader/PathDownloader.php b/src/Composer/Downloader/PathDownloader.php index 213be04a1..77ca0bb13 100644 --- a/src/Composer/Downloader/PathDownloader.php +++ b/src/Composer/Downloader/PathDownloader.php @@ -12,6 +12,7 @@ namespace Composer\Downloader; +use Composer\Package\Archiver\ArchivableFilesFinder; use Composer\Package\Dumper\ArrayDumper; use Composer\Package\PackageInterface; use Composer\Package\Version\VersionGuesser; @@ -119,7 +120,8 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter // Fallback if symlink failed or if symlink is not allowed for the package if (self::STRATEGY_MIRROR == $currentStrategy) { $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(''); From 8b61315b14bef09cf39b545a897d0090ce6cf94c Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 11 Sep 2017 11:26:33 +0200 Subject: [PATCH 5/5] Normalize URL as symfony Filesystem::mirror does a straight str_replace on realUrl vs actual iteratee path without normalization and our aRchivableFilesFinder does normalize the path, refs #6667 --- src/Composer/Downloader/PathDownloader.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Composer/Downloader/PathDownloader.php b/src/Composer/Downloader/PathDownloader.php index 77ca0bb13..250a01c3f 100644 --- a/src/Composer/Downloader/PathDownloader.php +++ b/src/Composer/Downloader/PathDownloader.php @@ -19,6 +19,7 @@ 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; @@ -119,6 +120,9 @@ 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); $iterator = new ArchivableFilesFinder($realUrl, array()); $fileSystem->mirror($realUrl, $path, $iterator);