1
0
Fork 0

Fix root package not having a pretty version when detecting from VCS, fixes #6845, closes #6847

pull/6804/merge
Alessandro Lai 2017-11-30 15:07:08 +01:00 committed by Jordi Boggiano
parent 40f4f6bf86
commit 3cf31da414
2 changed files with 31 additions and 7 deletions

View File

@ -68,22 +68,25 @@ class RootPackageLoader extends ArrayLoader
}
$autoVersioned = false;
if (!isset($config['version'])) {
$commit = null;
// override with env var if available
if (getenv('COMPOSER_ROOT_VERSION')) {
$version = getenv('COMPOSER_ROOT_VERSION');
$commit = null;
$config['version'] = getenv('COMPOSER_ROOT_VERSION');
} else {
$versionData = $this->versionGuesser->guessVersion($config, $cwd ?: getcwd());
$version = $versionData['version'];
$commit = $versionData['commit'];
if ($versionData) {
$config['version'] = $versionData['pretty_version'];
$config['version_normalized'] = $versionData['version'];
$commit = $versionData['commit'];
}
}
if (!$version) {
$version = '1.0.0';
if (!isset($config['version'])) {
$config['version'] = '1.0.0';
$autoVersioned = true;
}
$config['version'] = $version;
if ($commit) {
$config['source'] = array(
'type' => '',

View File

@ -17,6 +17,7 @@ use Composer\Package\Loader\RootPackageLoader;
use Composer\Package\BasePackage;
use Composer\Package\Version\VersionGuesser;
use Composer\Semver\VersionParser;
use Prophecy\Argument;
class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
{
@ -91,6 +92,26 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals("No version set (parsed as 1.0.0)", $package->getPrettyVersion());
}
public function testPrettyVersionForRootPackageInVersionBranch()
{
// see #6845
$manager = $this->prophesize('\\Composer\\Repository\\RepositoryManager');
$versionGuesser = $this->prophesize('\\Composer\\Package\\Version\\VersionGuesser');
$versionGuesser->guessVersion(Argument::cetera())
->willReturn(array(
'name' => 'A',
'version' => '3.0.9999999.9999999-dev',
'pretty_version' => '3.0-dev',
'commit' => 'aabbccddee',
));
$config = new Config;
$config->merge(array('repositories' => array('packagist' => false)));
$loader = new RootPackageLoader($manager->reveal(), $config, null, $versionGuesser->reveal());
$package = $loader->load(array());
$this->assertEquals('3.0-dev', $package->getPrettyVersion());
}
public function testFeatureBranchPrettyVersion()
{
if (!function_exists('proc_open')) {