From 0e8c5fa62e215471d425740bcd3ef4556e127daa Mon Sep 17 00:00:00 2001 From: Samuel ROZE Date: Mon, 14 Sep 2015 09:58:07 +0100 Subject: [PATCH 1/2] Store path from composer.json with the `path` repository to ensure lock file to be reused --- src/Composer/Downloader/PathDownloader.php | 7 +++++++ src/Composer/Repository/PathRepository.php | 23 +++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/Composer/Downloader/PathDownloader.php b/src/Composer/Downloader/PathDownloader.php index 3ae458d71..88b860c54 100644 --- a/src/Composer/Downloader/PathDownloader.php +++ b/src/Composer/Downloader/PathDownloader.php @@ -39,6 +39,13 @@ class PathDownloader extends FileDownloader $package->getDistUrl() )); + if (!file_exists($path) || !is_dir($path)) { + throw new \RuntimeException(sprintf( + 'Path "%s" is not found', + $path + )); + } + try { $fileSystem->symlink($package->getDistUrl(), $path); } catch (IOException $e) { diff --git a/src/Composer/Repository/PathRepository.php b/src/Composer/Repository/PathRepository.php index 970edac72..8e0b2edca 100644 --- a/src/Composer/Repository/PathRepository.php +++ b/src/Composer/Repository/PathRepository.php @@ -60,7 +60,7 @@ class PathRepository extends ArrayRepository /** * @var string */ - private $path; + private $url; /** * @var ProcessExecutor @@ -81,7 +81,7 @@ class PathRepository extends ArrayRepository } $this->loader = new ArrayLoader(); - $this->path = realpath(rtrim($repoConfig['url'], '/')) . '/'; + $this->url = $repoConfig['url']; $this->process = new ProcessExecutor($io); $this->versionGuesser = new VersionGuesser($config, $this->process, new VersionParser()); @@ -97,27 +97,36 @@ class PathRepository extends ArrayRepository { parent::initialize(); - $composerFilePath = $this->path.'composer.json'; + $path = $this->getPath(); + $composerFilePath = $path.'composer.json'; if (!file_exists($composerFilePath)) { - throw new \RuntimeException(sprintf('No `composer.json` file found in path repository "%s"', $this->path)); + throw new \RuntimeException(sprintf('No `composer.json` file found in path repository "%s"', $path)); } $json = file_get_contents($composerFilePath); $package = JsonFile::parseJson($json, $composerFilePath); $package['dist'] = array( 'type' => 'path', - 'url' => $this->path, + 'url' => $this->url, 'reference' => '', ); if (!isset($package['version'])) { - $package['version'] = $this->versionGuesser->guessVersion($package, $this->path) ?: 'dev-master'; + $package['version'] = $this->versionGuesser->guessVersion($package, $path) ?: 'dev-master'; } - if (is_dir($this->path.'/.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $this->path)) { + if (is_dir($path.'/.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $path)) { $package['dist']['reference'] = trim($output); } $package = $this->loader->load($package); $this->addPackage($package); } + + /** + * @return string + */ + private function getPath() + { + return realpath(rtrim($this->url, '/')) . '/'; + } } From a3f5f603591e1866481877ed065787af1690c0b1 Mon Sep 17 00:00:00 2001 From: Samuel ROZE Date: Mon, 14 Sep 2015 10:17:13 +0100 Subject: [PATCH 2/2] Update output to have a coherent one --- src/Composer/Downloader/PathDownloader.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Composer/Downloader/PathDownloader.php b/src/Composer/Downloader/PathDownloader.php index 88b860c54..c58a3f23a 100644 --- a/src/Composer/Downloader/PathDownloader.php +++ b/src/Composer/Downloader/PathDownloader.php @@ -33,13 +33,13 @@ class PathDownloader extends FileDownloader $this->filesystem->removeDirectory($path); $this->io->writeError(sprintf( - ' - Installing %s (%s) from %s', + ' - Installing %s (%s)', $package->getName(), - $package->getFullPrettyVersion(), - $package->getDistUrl() + $package->getFullPrettyVersion() )); - if (!file_exists($path) || !is_dir($path)) { + $url = $package->getDistUrl(); + if (!file_exists($url) || !is_dir($url)) { throw new \RuntimeException(sprintf( 'Path "%s" is not found', $path @@ -47,9 +47,13 @@ class PathDownloader extends FileDownloader } try { - $fileSystem->symlink($package->getDistUrl(), $path); + $fileSystem->symlink($url, $path); + $this->io->writeError(sprintf(' Symlinked from %s', $url)); } catch (IOException $e) { - $fileSystem->mirror($package->getDistUrl(), $path); + $fileSystem->mirror($url, $path); + $this->io->writeError(sprintf(' Mirrored from %s', $url)); } + + $this->io->writeError(''); } }