Fix detection of tags when the current tag is not a valid version
parent
8b293633ae
commit
0044c75ca0
|
@ -190,7 +190,10 @@ class RootPackageLoader extends ArrayLoader
|
||||||
|
|
||||||
// try to fetch current version from git tags
|
// try to fetch current version from git tags
|
||||||
if (0 === $this->process->execute('git describe --exact-match --tags', $output)) {
|
if (0 === $this->process->execute('git describe --exact-match --tags', $output)) {
|
||||||
return $this->versionParser->normalize(trim($output));
|
try {
|
||||||
|
return $this->versionParser->normalize(trim($output));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to fetch current version from git branch
|
// try to fetch current version from git branch
|
||||||
|
|
|
@ -85,6 +85,39 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->assertEquals("2.0.5.0-alpha2", $package->getVersion());
|
$this->assertEquals("2.0.5.0-alpha2", $package->getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testInvalidTagBecomesVersion()
|
||||||
|
{
|
||||||
|
if (!function_exists('proc_open')) {
|
||||||
|
$this->markTestSkipped('proc_open() is not available');
|
||||||
|
}
|
||||||
|
|
||||||
|
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$self = $this;
|
||||||
|
|
||||||
|
/* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
|
||||||
|
$processExecutor = new ProcessExecutorMock(function($command, &$output = null, $cwd = null) use ($self) {
|
||||||
|
if ('git describe --exact-match --tags' === $command) {
|
||||||
|
$output = "foo-bar";
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = "* foo 03a15d220da53c52eddd5f32ffca64a7b3801bea Commit message\n";
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
$config = new Config;
|
||||||
|
$config->merge(array('repositories' => array('packagist' => false)));
|
||||||
|
$loader = new RootPackageLoader($manager, $config, null, $processExecutor);
|
||||||
|
$package = $loader->load(array());
|
||||||
|
|
||||||
|
$this->assertEquals("dev-foo", $package->getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
protected function loadPackage($data)
|
protected function loadPackage($data)
|
||||||
{
|
{
|
||||||
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
||||||
|
|
Loading…
Reference in New Issue