Merge remote-tracking branch 'nicolas-grekas/path-version' into 1.10
commit
37c5e9961c
|
@ -658,14 +658,23 @@ 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
|
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`.
|
cannot be resolved by these means, it is assumed to be `dev-master`.
|
||||||
|
|
||||||
When the version cannot be inferred from the local VCS repository, you should use
|
When the version cannot be inferred from the local VCS repository, or when you
|
||||||
the special `branch-version` entry under `extra` instead of `version`:
|
want to override the version, you can use the `versions` option when declaring
|
||||||
|
the repository:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"extra": {
|
"repositories": [
|
||||||
"branch-version": "4.2-dev"
|
{
|
||||||
|
"type": "path",
|
||||||
|
"url": "../../packages/my-package",
|
||||||
|
"options": {
|
||||||
|
"versions": {
|
||||||
|
"my/package": "4.2-dev"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -81,10 +81,8 @@ class RootPackageLoader extends ArrayLoader
|
||||||
if (!isset($config['version'])) {
|
if (!isset($config['version'])) {
|
||||||
$commit = null;
|
$commit = null;
|
||||||
|
|
||||||
if (isset($config['extra']['branch-version'])) {
|
|
||||||
$config['version'] = preg_replace('{(\.x)?(-dev)?$}', '', $config['extra']['branch-version']).'.x-dev';
|
|
||||||
} elseif (getenv('COMPOSER_ROOT_VERSION')) {
|
|
||||||
// override with env var if available
|
// override with env var if available
|
||||||
|
if (getenv('COMPOSER_ROOT_VERSION')) {
|
||||||
$config['version'] = getenv('COMPOSER_ROOT_VERSION');
|
$config['version'] = getenv('COMPOSER_ROOT_VERSION');
|
||||||
} else {
|
} else {
|
||||||
$versionData = $this->versionGuesser->guessVersion($config, $cwd ?: getcwd());
|
$versionData = $this->versionGuesser->guessVersion($config, $cwd ?: getcwd());
|
||||||
|
|
|
@ -164,10 +164,11 @@ class PathRepository extends ArrayRepository implements ConfigurableRepositoryIn
|
||||||
'reference' => sha1($json . serialize($this->options)),
|
'reference' => sha1($json . serialize($this->options)),
|
||||||
);
|
);
|
||||||
$package['transport-options'] = $this->options;
|
$package['transport-options'] = $this->options;
|
||||||
|
unset($package['transport-options']['versions']);
|
||||||
|
|
||||||
// use the branch-version as the package version if available
|
// use the version provided as option if available
|
||||||
if (!isset($package['version']) && isset($package['extra']['branch-version'])) {
|
if (isset($package['name'], $this->options['versions'][$package['name']])) {
|
||||||
$package['version'] = preg_replace('{(\.x)?(-dev)?$}', '', $package['extra']['branch-version']).'.x-dev';
|
$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
|
// carry over the root package version if this path repo is in the same git repository as root package
|
||||||
|
|
|
@ -201,28 +201,4 @@ class RootPackageLoaderTest extends TestCase
|
||||||
|
|
||||||
$this->assertEquals("dev-latest-production", $package->getPrettyVersion());
|
$this->assertEquals("dev-latest-production", $package->getPrettyVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider provideExtraBranchVersion
|
|
||||||
*/
|
|
||||||
public function testLoadExtraBranchVersion($branchVersion)
|
|
||||||
{
|
|
||||||
$package = $this->loadPackage(array(
|
|
||||||
'extra' => array(
|
|
||||||
'branch-version' => $branchVersion,
|
|
||||||
),
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->assertEquals('1.2.x-dev', $package->getPrettyVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function provideExtraBranchVersion()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
array('1.2'),
|
|
||||||
array('1.2.x'),
|
|
||||||
array('1.2-dev'),
|
|
||||||
array('1.2.x-dev'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"name": "test/path-branch-versioned",
|
|
||||||
"extra": {
|
|
||||||
"branch-version": "1.2"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -72,23 +72,6 @@ class PathRepositoryTest extends TestCase
|
||||||
$this->assertNotEmpty($packageVersion);
|
$this->assertNotEmpty($packageVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLoadPackageFromFileSystemWithExtraBranchVersion()
|
|
||||||
{
|
|
||||||
$ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
$config = new \Composer\Config();
|
|
||||||
$versionGuesser = null;
|
|
||||||
|
|
||||||
$repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', 'with-branch-version'));
|
|
||||||
$repository = new PathRepository(array('url' => $repositoryUrl), $ioInterface, $config);
|
|
||||||
$packages = $repository->getPackages();
|
|
||||||
|
|
||||||
$this->assertEquals(1, $repository->count());
|
|
||||||
|
|
||||||
$this->assertTrue($repository->hasPackage($this->getPackage('test/path-branch-versioned', '1.2.x-dev')));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testLoadPackageFromFileSystemWithWildcard()
|
public function testLoadPackageFromFileSystemWithWildcard()
|
||||||
{
|
{
|
||||||
$ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
|
$ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
|
||||||
|
@ -102,7 +85,7 @@ class PathRepositoryTest extends TestCase
|
||||||
$packages = $repository->getPackages();
|
$packages = $repository->getPackages();
|
||||||
$names = array();
|
$names = array();
|
||||||
|
|
||||||
$this->assertEquals(3, $repository->count());
|
$this->assertEquals(2, $repository->count());
|
||||||
|
|
||||||
$package = $packages[0];
|
$package = $packages[0];
|
||||||
$names[] = $package->getName();
|
$names[] = $package->getName();
|
||||||
|
@ -110,11 +93,39 @@ class PathRepositoryTest extends TestCase
|
||||||
$package = $packages[1];
|
$package = $packages[1];
|
||||||
$names[] = $package->getName();
|
$names[] = $package->getName();
|
||||||
|
|
||||||
$package = $packages[2];
|
|
||||||
$names[] = $package->getName();
|
|
||||||
|
|
||||||
sort($names);
|
sort($names);
|
||||||
$this->assertEquals(array('test/path-branch-versioned', 'test/path-unversioned', 'test/path-versioned'), $names);
|
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue