From c0a20c3d30a287a78dfda4edcfbeebd7355bf0ec Mon Sep 17 00:00:00 2001 From: Beau Simensen Date: Mon, 20 May 2013 12:47:52 -0500 Subject: [PATCH 1/3] Detect version based on tag if HEAD points to a tag. --- src/Composer/Package/Loader/RootPackageLoader.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Composer/Package/Loader/RootPackageLoader.php b/src/Composer/Package/Loader/RootPackageLoader.php index 17f49e4b3..dae3ffdad 100644 --- a/src/Composer/Package/Loader/RootPackageLoader.php +++ b/src/Composer/Package/Loader/RootPackageLoader.php @@ -184,6 +184,11 @@ class RootPackageLoader extends ArrayLoader private function guessGitVersion(array $config) { + // try to fetch current version from git branch as a tag + if (0 === $this->process->execute('git describe --exact-match', $output)) { + return $this->versionParser->normalize(rtrim($output)); + } + // try to fetch current version from git branch if (0 === $this->process->execute('git branch --no-color --no-abbrev -v', $output)) { $branches = array(); From f9fe39e6243365b8c222ff0e840de406e72962a1 Mon Sep 17 00:00:00 2001 From: Beau Simensen Date: Tue, 21 May 2013 06:14:34 -0500 Subject: [PATCH 2/3] Fixed the existing test and added a new one for git tag version guessing. --- .../Package/Loader/RootPackageLoaderTest.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php b/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php index 6f4f53e19..dd22bcd0f 100644 --- a/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php @@ -35,6 +35,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 */ $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); $output = "* (no branch) $commitHash Commit message\n"; @@ -49,4 +54,33 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase $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', $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()); + } } From 215556df7cd2e5e09df8a0984d86f19659e4bdc7 Mon Sep 17 00:00:00 2001 From: Beau Simensen Date: Tue, 21 May 2013 09:59:41 -0500 Subject: [PATCH 3/3] Use --tags to get non-annotated tags as well. --- src/Composer/Package/Loader/RootPackageLoader.php | 2 +- tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Composer/Package/Loader/RootPackageLoader.php b/src/Composer/Package/Loader/RootPackageLoader.php index dae3ffdad..057afd170 100644 --- a/src/Composer/Package/Loader/RootPackageLoader.php +++ b/src/Composer/Package/Loader/RootPackageLoader.php @@ -185,7 +185,7 @@ class RootPackageLoader extends ArrayLoader private function guessGitVersion(array $config) { // try to fetch current version from git branch as a tag - if (0 === $this->process->execute('git describe --exact-match', $output)) { + if (0 === $this->process->execute('git describe --exact-match --tags', $output)) { return $this->versionParser->normalize(rtrim($output)); } diff --git a/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php b/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php index dd22bcd0f..a9422d91a 100644 --- a/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php @@ -69,7 +69,7 @@ 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 */ $processExecutor = new ProcessExecutorMock(function($command, &$output = null, $cwd = null) use ($self) { - $self->assertEquals('git describe --exact-match', $command); + $self->assertEquals('git describe --exact-match --tags', $command); $output = "v2.0.5-alpha2";