diff --git a/src/Composer/Repository/PathRepository.php b/src/Composer/Repository/PathRepository.php index 3cb879c5c52c..f382dbf5934d 100644 --- a/src/Composer/Repository/PathRepository.php +++ b/src/Composer/Repository/PathRepository.php @@ -56,6 +56,13 @@ * "symlink": false * } * }, + * { + * "type": "path", + * "url": "../../relative/path/to/package/", + * "options": { + * "reference": "none" + * } + * }, * ] * @endcode * @@ -81,7 +88,7 @@ class PathRepository extends ArrayRepository implements ConfigurableRepositoryIn /** * @var mixed[] - * @phpstan-var array{url: string, options?: array{symlink?: bool, relative?: bool, versions?: array}} + * @phpstan-var array{url: string, options?: array{symlink?: bool, reference?: string, relative?: bool, versions?: array}} */ private $repoConfig; @@ -91,14 +98,14 @@ class PathRepository extends ArrayRepository implements ConfigurableRepositoryIn private $process; /** - * @var array{symlink?: bool, relative?: bool, versions?: array} + * @var array{symlink?: bool, reference: string, relative: bool, versions?: array} */ private $options; /** * Initializes path repository. * - * @param array{url?: string, options?: array{symlink?: bool, relative?: bool, versions?: array}} $repoConfig + * @param array{url?: string, options?: array{symlink?: bool, reference?: string, relative?: bool, versions?: array}} $repoConfig * @param IOInterface $io * @param Config $config */ @@ -171,8 +178,13 @@ protected function initialize() $package['dist'] = array( 'type' => 'path', 'url' => $url, - 'reference' => sha1($json . serialize($this->options)), ); + $reference = $this->options['reference'] ?? 'auto'; + if ('none' === $reference) { + $package['dist']['reference'] = null; + } elseif ('config' === $reference || 'auto' === $reference) { + $package['dist']['reference'] = sha1($json . serialize($this->options)); + } $package['transport-options'] = $this->options; unset($package['transport-options']['versions']); @@ -193,7 +205,7 @@ protected function initialize() } $output = ''; - if (is_dir($path . DIRECTORY_SEPARATOR . '.git') && 0 === $this->process->execute('git log -n1 --pretty=%H'.GitUtil::getNoShowSignatureFlag($this->process), $output, $path)) { + if ('auto' === $reference && is_dir($path . DIRECTORY_SEPARATOR . '.git') && 0 === $this->process->execute('git log -n1 --pretty=%H'.GitUtil::getNoShowSignatureFlag($this->process), $output, $path)) { $package['dist']['reference'] = trim($output); } diff --git a/tests/Composer/Test/Fixtures/functional/plugin-autoloading-only-loads-dependencies/vendor/composer/installed.php b/tests/Composer/Test/Fixtures/functional/plugin-autoloading-only-loads-dependencies/vendor/composer/installed.php index e088b2ffd21f..12600a6e52a6 100644 --- a/tests/Composer/Test/Fixtures/functional/plugin-autoloading-only-loads-dependencies/vendor/composer/installed.php +++ b/tests/Composer/Test/Fixtures/functional/plugin-autoloading-only-loads-dependencies/vendor/composer/installed.php @@ -16,7 +16,7 @@ 'type' => 'library', 'install_path' => __DIR__ . '/../evil/pkg', 'aliases' => array(), - 'reference' => 'a95061d7a7e3cf4466381fd1abc504279c95b231', + 'reference' => 'c78ed4017d8213c0921dbfee6ba33dbc3b23f667', 'dev_requirement' => false, ), 'root/pkg' => array( diff --git a/tests/Composer/Test/Repository/PathRepositoryTest.php b/tests/Composer/Test/Repository/PathRepositoryTest.php index cb1aa0e3f205..860164a6e53b 100644 --- a/tests/Composer/Test/Repository/PathRepositoryTest.php +++ b/tests/Composer/Test/Repository/PathRepositoryTest.php @@ -154,4 +154,50 @@ public function testUrlRemainsRelative() $relativeUrl = str_replace(DIRECTORY_SEPARATOR, '/', $relativeUrl); $this->assertSame($relativeUrl, $package->getDistUrl()); } + + public function testReferenceNone() + { + $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface') + ->getMock(); + + $config = new \Composer\Config(); + + $options = array( + 'reference' => 'none', + ); + $repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', '*')); + $repository = new PathRepository(array('url' => $repositoryUrl, 'options' => $options), $ioInterface, $config); + $packages = $repository->getPackages(); + + $this->assertGreaterThanOrEqual(2, $repository->count()); + + foreach ($packages as $package) { + $this->assertEquals($package->getDistReference(), ''); + } + } + + public function testReferenceConfig() + { + $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface') + ->getMock(); + + $config = new \Composer\Config(); + + $options = array( + 'reference' => 'config', + 'relative' => true, + ); + $repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', '*')); + $repository = new PathRepository(array('url' => $repositoryUrl, 'options' => $options), $ioInterface, $config); + $packages = $repository->getPackages(); + + $this->assertGreaterThanOrEqual(2, $repository->count()); + + foreach ($packages as $package) { + $this->assertEquals( + $package->getDistReference(), + sha1(file_get_contents($package->getDistUrl() . '/composer.json') . serialize($options)) + ); + } + } }