Merge branch '1.5'
commit
6256e17149
|
@ -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' => '',
|
||||
|
|
|
@ -59,30 +59,43 @@ class VersionGuesser
|
|||
* @param array $packageConfig
|
||||
* @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)
|
||||
{
|
||||
if (function_exists('proc_open')) {
|
||||
$versionData = $this->guessGitVersion($packageConfig, $path);
|
||||
if (null !== $versionData && null !== $versionData['version']) {
|
||||
return $versionData;
|
||||
return $this->postprocess($versionData);
|
||||
}
|
||||
|
||||
$versionData = $this->guessHgVersion($packageConfig, $path);
|
||||
if (null !== $versionData && null !== $versionData['version']) {
|
||||
return $versionData;
|
||||
return $this->postprocess($versionData);
|
||||
}
|
||||
|
||||
$versionData = $this->guessFossilVersion($packageConfig, $path);
|
||||
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)
|
||||
{
|
||||
GitUtil::cleanEnv();
|
||||
|
|
|
@ -311,7 +311,7 @@ class GitLabDriver extends VcsDriver
|
|||
if (isset($this->project['visibility'])) {
|
||||
$this->isPrivate = $this->project['visibility'] !== 'public';
|
||||
} else {
|
||||
// client is not authendicated, therefore repository has to be public
|
||||
// client is not authendicated, therefore repository has to be public
|
||||
$this->isPrivate = false;
|
||||
}
|
||||
}
|
||||
|
@ -351,7 +351,7 @@ class GitLabDriver extends VcsDriver
|
|||
|
||||
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)
|
||||
|
|
|
@ -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')) {
|
||||
|
|
|
@ -412,4 +412,35 @@ class VersionGuesserTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$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