Merge branch '1.5'
commit
6256e17149
|
@ -68,22 +68,25 @@ class RootPackageLoader extends ArrayLoader
|
||||||
}
|
}
|
||||||
$autoVersioned = false;
|
$autoVersioned = false;
|
||||||
if (!isset($config['version'])) {
|
if (!isset($config['version'])) {
|
||||||
|
$commit = null;
|
||||||
|
|
||||||
// override with env var if available
|
// override with env var if available
|
||||||
if (getenv('COMPOSER_ROOT_VERSION')) {
|
if (getenv('COMPOSER_ROOT_VERSION')) {
|
||||||
$version = getenv('COMPOSER_ROOT_VERSION');
|
$config['version'] = getenv('COMPOSER_ROOT_VERSION');
|
||||||
$commit = null;
|
|
||||||
} else {
|
} else {
|
||||||
$versionData = $this->versionGuesser->guessVersion($config, $cwd ?: getcwd());
|
$versionData = $this->versionGuesser->guessVersion($config, $cwd ?: getcwd());
|
||||||
$version = $versionData['version'];
|
if ($versionData) {
|
||||||
$commit = $versionData['commit'];
|
$config['version'] = $versionData['pretty_version'];
|
||||||
|
$config['version_normalized'] = $versionData['version'];
|
||||||
|
$commit = $versionData['commit'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$version) {
|
if (!isset($config['version'])) {
|
||||||
$version = '1.0.0';
|
$config['version'] = '1.0.0';
|
||||||
$autoVersioned = true;
|
$autoVersioned = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$config['version'] = $version;
|
|
||||||
if ($commit) {
|
if ($commit) {
|
||||||
$config['source'] = array(
|
$config['source'] = array(
|
||||||
'type' => '',
|
'type' => '',
|
||||||
|
|
|
@ -59,30 +59,43 @@ class VersionGuesser
|
||||||
* @param array $packageConfig
|
* @param array $packageConfig
|
||||||
* @param string $path Path to guess into
|
* @param string $path Path to guess into
|
||||||
*
|
*
|
||||||
* @return array versionData, 'version', 'pretty_version' and 'commit' keys
|
* @return null|array versionData, 'version', 'pretty_version' and 'commit' keys
|
||||||
*/
|
*/
|
||||||
public function guessVersion(array $packageConfig, $path)
|
public function guessVersion(array $packageConfig, $path)
|
||||||
{
|
{
|
||||||
if (function_exists('proc_open')) {
|
if (function_exists('proc_open')) {
|
||||||
$versionData = $this->guessGitVersion($packageConfig, $path);
|
$versionData = $this->guessGitVersion($packageConfig, $path);
|
||||||
if (null !== $versionData && null !== $versionData['version']) {
|
if (null !== $versionData && null !== $versionData['version']) {
|
||||||
return $versionData;
|
return $this->postprocess($versionData);
|
||||||
}
|
}
|
||||||
|
|
||||||
$versionData = $this->guessHgVersion($packageConfig, $path);
|
$versionData = $this->guessHgVersion($packageConfig, $path);
|
||||||
if (null !== $versionData && null !== $versionData['version']) {
|
if (null !== $versionData && null !== $versionData['version']) {
|
||||||
return $versionData;
|
return $this->postprocess($versionData);
|
||||||
}
|
}
|
||||||
|
|
||||||
$versionData = $this->guessFossilVersion($packageConfig, $path);
|
$versionData = $this->guessFossilVersion($packageConfig, $path);
|
||||||
if (null !== $versionData && null !== $versionData['version']) {
|
if (null !== $versionData && null !== $versionData['version']) {
|
||||||
return $versionData;
|
return $this->postprocess($versionData);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->guessSvnVersion($packageConfig, $path);
|
$versionData = $this->guessSvnVersion($packageConfig, $path);
|
||||||
|
if (null !== $versionData && null !== $versionData['version']) {
|
||||||
|
return $this->postprocess($versionData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function postprocess(array $versionData)
|
||||||
|
{
|
||||||
|
// make sure that e.g. dev-1.5 gets converted to 1.5.x-dev
|
||||||
|
if ('dev-' !== substr($versionData['version'], 0, 4)) {
|
||||||
|
$versionData['pretty_version'] = preg_replace('{(\.9{7})+}', '.x', $versionData['version']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $versionData;
|
||||||
|
}
|
||||||
|
|
||||||
private function guessGitVersion(array $packageConfig, $path)
|
private function guessGitVersion(array $packageConfig, $path)
|
||||||
{
|
{
|
||||||
GitUtil::cleanEnv();
|
GitUtil::cleanEnv();
|
||||||
|
|
|
@ -351,7 +351,7 @@ class GitLabDriver extends VcsDriver
|
||||||
|
|
||||||
protected function generatePublicUrl()
|
protected function generatePublicUrl()
|
||||||
{
|
{
|
||||||
return 'https://' . $this->originUrl . '/'.$this->namespace.'/'.$this->repository.'.git';
|
return $this->scheme . '://' . $this->originUrl . '/'.$this->namespace.'/'.$this->repository.'.git';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setupGitDriver($url)
|
protected function setupGitDriver($url)
|
||||||
|
|
|
@ -17,6 +17,7 @@ use Composer\Package\Loader\RootPackageLoader;
|
||||||
use Composer\Package\BasePackage;
|
use Composer\Package\BasePackage;
|
||||||
use Composer\Package\Version\VersionGuesser;
|
use Composer\Package\Version\VersionGuesser;
|
||||||
use Composer\Semver\VersionParser;
|
use Composer\Semver\VersionParser;
|
||||||
|
use Prophecy\Argument;
|
||||||
|
|
||||||
class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
|
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());
|
$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()
|
public function testFeatureBranchPrettyVersion()
|
||||||
{
|
{
|
||||||
if (!function_exists('proc_open')) {
|
if (!function_exists('proc_open')) {
|
||||||
|
|
|
@ -412,4 +412,35 @@ class VersionGuesserTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$this->assertEquals("dev-foo", $versionData['version']);
|
$this->assertEquals("dev-foo", $versionData['version']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNumericBranchesShowNicely()
|
||||||
|
{
|
||||||
|
$executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')
|
||||||
|
->setMethods(array('execute'))
|
||||||
|
->disableArgumentCloning()
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock()
|
||||||
|
;
|
||||||
|
|
||||||
|
$self = $this;
|
||||||
|
|
||||||
|
$executor
|
||||||
|
->expects($this->at(0))
|
||||||
|
->method('execute')
|
||||||
|
->willReturnCallback(function ($command, &$output) use ($self) {
|
||||||
|
$self->assertEquals('git branch --no-color --no-abbrev -v', $command);
|
||||||
|
$output = "* 1.5 03a15d220da53c52eddd5f32ffca64a7b3801bea Commit message\n";
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
})
|
||||||
|
;
|
||||||
|
|
||||||
|
$config = new Config;
|
||||||
|
$config->merge(array('repositories' => array('packagist' => false)));
|
||||||
|
$guesser = new VersionGuesser($config, $executor, new VersionParser());
|
||||||
|
$versionData = $guesser->guessVersion(array(), 'dummy/path');
|
||||||
|
|
||||||
|
$this->assertEquals("1.5.x-dev", $versionData['pretty_version']);
|
||||||
|
$this->assertEquals("1.5.9999999.9999999-dev", $versionData['version']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue