Fix pretty guessed versions to show nicely on numeric branches, refs #6845
parent
3cf31da414
commit
5ba6d7d436
|
@ -66,23 +66,36 @@ class VersionGuesser
|
|||
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();
|
||||
|
|
|
@ -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