diff --git a/doc/05-repositories.md b/doc/05-repositories.md index 95881b078..4c1c7e000 100644 --- a/doc/05-repositories.md +++ b/doc/05-repositories.md @@ -658,6 +658,26 @@ the branch or tag that is currently checked out. Otherwise, the version should be explicitly defined in the package's `composer.json` file. If the version cannot be resolved by these means, it is assumed to be `dev-master`. +When the version cannot be inferred from the local VCS repository, or when you +want to override the version, you can use the `versions` option when declaring +the repository: + +```json +{ + "repositories": [ + { + "type": "path", + "url": "../../packages/my-package", + "options": { + "versions": { + "my/package": "4.2-dev" + } + } + } + ] +} +``` + The local package will be symlinked if possible, in which case the output in the console will read `Symlinking from ../../packages/my-package`. If symlinking is _not_ possible the package will be copied. In that case, the console will diff --git a/src/Composer/Repository/PathRepository.php b/src/Composer/Repository/PathRepository.php index a0a6835b8..b6601f883 100644 --- a/src/Composer/Repository/PathRepository.php +++ b/src/Composer/Repository/PathRepository.php @@ -164,6 +164,12 @@ class PathRepository extends ArrayRepository implements ConfigurableRepositoryIn 'reference' => sha1($json . serialize($this->options)), ); $package['transport-options'] = $this->options; + unset($package['transport-options']['versions']); + + // use the version provided as option if available + if (isset($package['name'], $this->options['versions'][$package['name']])) { + $package['version'] = $this->options['versions'][$package['name']]; + } // carry over the root package version if this path repo is in the same git repository as root package if (!isset($package['version']) && ($rootVersion = getenv('COMPOSER_ROOT_VERSION'))) { diff --git a/tests/Composer/Test/Repository/PathRepositoryTest.php b/tests/Composer/Test/Repository/PathRepositoryTest.php index 159d8cc97..f2c8a9192 100644 --- a/tests/Composer/Test/Repository/PathRepositoryTest.php +++ b/tests/Composer/Test/Repository/PathRepositoryTest.php @@ -97,6 +97,37 @@ class PathRepositoryTest extends TestCase $this->assertEquals(array('test/path-unversioned', 'test/path-versioned'), $names); } + public function testLoadPackageWithExplicitVersions() + { + $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface') + ->getMock(); + + $config = new \Composer\Config(); + $versionGuesser = null; + + $options = array( + 'versions' => array( + 'test/path-unversioned' => '4.3.2.1', + 'test/path-versioned' => '3.2.1.0', + ), + ); + $repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', '*')); + $repository = new PathRepository(array('url' => $repositoryUrl, 'options' => $options), $ioInterface, $config); + $packages = $repository->getPackages(); + $versions = array(); + + $this->assertEquals(2, $repository->count()); + + $package = $packages[0]; + $versions[$package->getName()] = $package->getVersion(); + + $package = $packages[1]; + $versions[$package->getName()] = $package->getVersion(); + + ksort($versions); + $this->assertSame(array('test/path-unversioned' => '4.3.2.1', 'test/path-versioned' => '3.2.1.0'), $versions); + } + /** * Verify relative repository URLs remain relative, see #4439 */