Merge pull request #9273 from nicolas-grekas/dev-version
Add support for "extra.branch-version"pull/9280/head
commit
d2d606ced2
|
@ -658,6 +658,17 @@ 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, you should use
|
||||
the special `branch-version` entry under `extra` instead of `version`:
|
||||
|
||||
```json
|
||||
{
|
||||
"extra": {
|
||||
"branch-version": "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
|
||||
|
|
|
@ -81,8 +81,10 @@ class RootPackageLoader extends ArrayLoader
|
|||
if (!isset($config['version'])) {
|
||||
$commit = null;
|
||||
|
||||
// override with env var if available
|
||||
if (getenv('COMPOSER_ROOT_VERSION')) {
|
||||
if (isset($config['extra']['branch-version'])) {
|
||||
$config['version'] = preg_replace('{(\.x)?(-dev)?$}', '.x-dev', $config['extra']['branch-version']);
|
||||
} elseif (getenv('COMPOSER_ROOT_VERSION')) {
|
||||
// override with env var if available
|
||||
$config['version'] = getenv('COMPOSER_ROOT_VERSION');
|
||||
} else {
|
||||
$versionData = $this->versionGuesser->guessVersion($config, $cwd ?: getcwd());
|
||||
|
|
|
@ -165,6 +165,11 @@ class PathRepository extends ArrayRepository implements ConfigurableRepositoryIn
|
|||
);
|
||||
$package['transport-options'] = $this->options;
|
||||
|
||||
// use the branch-version as the package version if available
|
||||
if (!isset($package['version']) && isset($package['extra']['branch-version'])) {
|
||||
$package['version'] = preg_replace('{(\.x)?(-dev)?$}', '.x-dev', $package['extra']['branch-version']);
|
||||
}
|
||||
|
||||
// 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'))) {
|
||||
if (
|
||||
|
|
|
@ -201,4 +201,15 @@ class RootPackageLoaderTest extends TestCase
|
|||
|
||||
$this->assertEquals("dev-latest-production", $package->getPrettyVersion());
|
||||
}
|
||||
|
||||
public function testLoadExtraBranchVersion()
|
||||
{
|
||||
$package = $this->loadPackage(array(
|
||||
'extra' => array(
|
||||
'branch-version' => '1.2',
|
||||
),
|
||||
));
|
||||
|
||||
$this->assertEquals('1.2.x-dev', $package->getPrettyVersion());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "test/path-branch-versioned",
|
||||
"extra": {
|
||||
"branch-version": "1.2"
|
||||
}
|
||||
}
|
|
@ -72,6 +72,23 @@ class PathRepositoryTest extends TestCase
|
|||
$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()
|
||||
{
|
||||
$ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
|
||||
|
@ -85,7 +102,7 @@ class PathRepositoryTest extends TestCase
|
|||
$packages = $repository->getPackages();
|
||||
$names = array();
|
||||
|
||||
$this->assertEquals(2, $repository->count());
|
||||
$this->assertEquals(3, $repository->count());
|
||||
|
||||
$package = $packages[0];
|
||||
$names[] = $package->getName();
|
||||
|
@ -93,8 +110,11 @@ class PathRepositoryTest extends TestCase
|
|||
$package = $packages[1];
|
||||
$names[] = $package->getName();
|
||||
|
||||
$package = $packages[2];
|
||||
$names[] = $package->getName();
|
||||
|
||||
sort($names);
|
||||
$this->assertEquals(array('test/path-unversioned', 'test/path-versioned'), $names);
|
||||
$this->assertEquals(array('test/path-branch-versioned', 'test/path-unversioned', 'test/path-versioned'), $names);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue