From 9041622b862baef250beffccf52f0c13f2845376 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 12 Apr 2018 15:16:39 +0200 Subject: [PATCH] Fix version guessing regression and a few other issues, fixes #7127 --- src/Composer/Package/Version/VersionGuesser.php | 12 +----------- src/Composer/Repository/PathRepository.php | 2 +- .../Test/Package/Version/VersionGuesserTest.php | 3 ++- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/Composer/Package/Version/VersionGuesser.php b/src/Composer/Package/Version/VersionGuesser.php index 02297a1e6..e6ff84965 100644 --- a/src/Composer/Package/Version/VersionGuesser.php +++ b/src/Composer/Package/Version/VersionGuesser.php @@ -184,7 +184,7 @@ class VersionGuesser $isFeatureBranch = 0 === strpos($version, 'dev-'); if ('9999999-dev' === $version) { - $version = 'dev-' . $branch; + return array('version' => $version, 'commit' => null, 'pretty_version' => 'dev-'.$branch); } if (!$isFeatureBranch) { @@ -240,9 +240,6 @@ class VersionGuesser $length = strlen($output); $version = $this->versionParser->normalizeBranch($candidate); $prettyVersion = 'dev-' . $match[1]; - if ('9999999-dev' === $version) { - $version = $prettyVersion; - } } } } @@ -260,10 +257,6 @@ class VersionGuesser $branch = trim($output); $version = $this->versionParser->normalizeBranch($branch); $prettyVersion = 'dev-' . $branch; - - if ('9999999-dev' === $version) { - $version = $prettyVersion; - } } // try to fetch current version from fossil tags @@ -295,9 +288,6 @@ class VersionGuesser // we are in a branches path $version = $this->versionParser->normalizeBranch($matches[3]); $prettyVersion = 'dev-' . $matches[3]; - if ('9999999-dev' === $version) { - $version = $prettyVersion; - } return array('version' => $version, 'commit' => '', 'pretty_version' => $prettyVersion); } diff --git a/src/Composer/Repository/PathRepository.php b/src/Composer/Repository/PathRepository.php index 0ce3e90d2..ee5d702fa 100644 --- a/src/Composer/Repository/PathRepository.php +++ b/src/Composer/Repository/PathRepository.php @@ -155,7 +155,7 @@ class PathRepository extends ArrayRepository implements ConfigurableRepositoryIn if (!isset($package['version'])) { $versionData = $this->versionGuesser->guessVersion($package, $path); - $package['version'] = $versionData['version'] ?: 'dev-master'; + $package['version'] = $versionData['pretty_version'] ?: 'dev-master'; } $output = ''; diff --git a/tests/Composer/Test/Package/Version/VersionGuesserTest.php b/tests/Composer/Test/Package/Version/VersionGuesserTest.php index c0b6346c8..fe229d679 100644 --- a/tests/Composer/Test/Package/Version/VersionGuesserTest.php +++ b/tests/Composer/Test/Package/Version/VersionGuesserTest.php @@ -89,7 +89,8 @@ class VersionGuesserTest extends TestCase $guesser = new VersionGuesser($config, $executor, new VersionParser()); $versionArray = $guesser->guessVersion(array(), 'dummy/path'); - $this->assertEquals('dev-' . $branch, $versionArray['version']); + $this->assertEquals("9999999-dev", $versionArray['version']); + $this->assertEquals("dev-".$branch, $versionArray['pretty_version']); $this->assertEmpty($versionArray['commit']); }