1
0
Fork 0

Merge remote-tracking branch 'simensen/non-dev-version'

Conflicts:
	src/Composer/Package/Loader/RootPackageLoader.php
	tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php
pull/2175/head
Jordi Boggiano 2013-08-12 02:33:18 +02:00
commit 8b293633ae
2 changed files with 39 additions and 0 deletions

View File

@ -188,6 +188,11 @@ class RootPackageLoader extends ArrayLoader
$util = new GitUtil; $util = new GitUtil;
$util->cleanEnv(); $util->cleanEnv();
// try to fetch current version from git tags
if (0 === $this->process->execute('git describe --exact-match --tags', $output)) {
return $this->versionParser->normalize(trim($output));
}
// try to fetch current version from git branch // try to fetch current version from git branch
if (0 === $this->process->execute('git branch --no-color --no-abbrev -v', $output)) { if (0 === $this->process->execute('git branch --no-color --no-abbrev -v', $output)) {
$branches = array(); $branches = array();

View File

@ -36,6 +36,11 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
/* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */ /* 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, $commitHash) { $processExecutor = new ProcessExecutorMock(function($command, &$output = null, $cwd = null) use ($self, $commitHash) {
if (0 === strpos($command, 'git describe')) {
// simulate not being on a tag
return 1;
}
$self->assertStringStartsWith('git branch', $command); $self->assertStringStartsWith('git branch', $command);
$output = "* (no branch) $commitHash Commit message\n"; $output = "* (no branch) $commitHash Commit message\n";
@ -51,6 +56,35 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals("dev-$commitHash", $package->getVersion()); $this->assertEquals("dev-$commitHash", $package->getVersion());
} }
public function testTagBecomesVersion()
{
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) {
$self->assertEquals('git describe --exact-match --tags', $command);
$output = "v2.0.5-alpha2";
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("2.0.5.0-alpha2", $package->getVersion());
}
protected function loadPackage($data) protected function loadPackage($data)
{ {
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager') $manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')