diff --git a/src/Composer/Package/Loader/RootPackageLoader.php b/src/Composer/Package/Loader/RootPackageLoader.php index 536d461ad..ac3d8f433 100644 --- a/src/Composer/Package/Loader/RootPackageLoader.php +++ b/src/Composer/Package/Loader/RootPackageLoader.php @@ -110,11 +110,6 @@ class RootPackageLoader extends ArrayLoader } } - $defaultBranch = $this->versionGuesser->getDefaultBranchName($cwd ?: getcwd()); - if ($defaultBranch && $config['version'] === 'dev-'.$defaultBranch) { - $config['default-branch'] = true; - } - $realPackage = $package = parent::load($config, $class); if ($realPackage instanceof AliasPackage) { $realPackage = $package->getAliasOf(); diff --git a/src/Composer/Package/Version/VersionGuesser.php b/src/Composer/Package/Version/VersionGuesser.php index 24bd33b75..6cf185685 100644 --- a/src/Composer/Package/Version/VersionGuesser.php +++ b/src/Composer/Package/Version/VersionGuesser.php @@ -111,43 +111,6 @@ class VersionGuesser return $versionData; } - /** - * Tries to find name of default branch from VCS info - * - * @param string $path Path to guess into - */ - public function getDefaultBranchName($path) - { - if (version_compare(GitUtil::getVersion($this->process), '2.3.0-rc0', '>=')) { - GitUtil::cleanEnv(); - $oldVal = getenv('GIT_SSH_COMMAND'); - putenv("GIT_SSH_COMMAND=ssh".(Platform::isWindows() ? '.exe' : '')." -o StrictHostKeyChecking=yes"); - $hasGitRemote = 0 === $this->process->execute('git remote show origin', $output, $path); - if ($oldVal) { - putenv("GIT_SSH_COMMAND=$oldVal"); - } else { - putenv("GIT_SSH_COMMAND"); - } - if ($hasGitRemote && preg_match('{^ HEAD branch: (.+)$}m', $output, $match)) { - return trim($match[1]); - } - } - - if (is_dir($path.'/.git')) { - return 'master'; - } - - if (is_dir($path.'/.hg')) { - return 'default'; - } - - if (is_dir($path.'/.svn')) { - return 'trunk'; - } - - return null; - } - private function guessGitVersion(array $packageConfig, $path) { GitUtil::cleanEnv(); @@ -292,11 +255,9 @@ class VersionGuesser return array('version' => $version, 'pretty_version' => $prettyVersion); } - $defaultBranch = $this->getDefaultBranchName($path); - foreach ($branches as $candidate) { // do not compare against itself or other feature branches - if ($candidate === $branch || !preg_match('{^(' . $nonFeatureBranches . ($defaultBranch ? '|'.preg_quote($defaultBranch) : '').'|master|main|latest|next|current|support|tip|trunk|default|develop|\d+\..+)$}', $candidate, $match)) { + if ($candidate === $branch || !preg_match('{^(' . $nonFeatureBranches . '|master|main|latest|next|current|support|tip|trunk|default|develop|\d+\..+)$}', $candidate, $match)) { continue; } diff --git a/tests/Composer/Test/Mock/VersionGuesserMock.php b/tests/Composer/Test/Mock/VersionGuesserMock.php index bcfa1d19d..d2fe1236c 100644 --- a/tests/Composer/Test/Mock/VersionGuesserMock.php +++ b/tests/Composer/Test/Mock/VersionGuesserMock.php @@ -24,10 +24,4 @@ class VersionGuesserMock extends VersionGuesser { return null; } - - public function getDefaultBranchName($path) - { - return null; - } - } diff --git a/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php b/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php index e5aebd1d0..25d39270c 100644 --- a/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php @@ -105,8 +105,6 @@ class RootPackageLoaderTest extends TestCase 'pretty_version' => '3.0-dev', 'commit' => 'aabbccddee', )); - $versionGuesser->getDefaultBranchName(Argument::cetera()) - ->willReturn('main'); $config = new Config; $config->merge(array('repositories' => array('packagist' => false))); $loader = new RootPackageLoader($manager->reveal(), $config, null, $versionGuesser->reveal()); @@ -115,28 +113,6 @@ class RootPackageLoaderTest extends TestCase $this->assertEquals('3.0-dev', $package->getPrettyVersion()); } - public function testDefaultBranchIsSetForRootPackageInDefaultBranch() - { - // see #6845 - $manager = $this->prophesize('\\Composer\\Repository\\RepositoryManager'); - $versionGuesser = $this->prophesize('\\Composer\\Package\\Version\\VersionGuesser'); - $versionGuesser->guessVersion(Argument::cetera()) - ->willReturn(array( - 'name' => 'A', - 'version' => 'dev-main', - 'pretty_version' => 'dev-main', - 'commit' => 'aabbccddee', - )); - $versionGuesser->getDefaultBranchName(Argument::cetera()) - ->willReturn('main'); - $config = new Config; - $config->merge(array('repositories' => array('packagist' => false))); - $loader = new RootPackageLoader($manager->reveal(), $config, null, $versionGuesser->reveal()); - $package = $loader->load(array()); - - $this->assertTrue($package->isDefaultBranch()); - } - public function testFeatureBranchPrettyVersion() { if (!function_exists('proc_open')) { @@ -171,17 +147,6 @@ class RootPackageLoaderTest extends TestCase $executor ->expects($this->at(1)) ->method('execute') - ->willReturnCallback(function ($command, &$output) use ($self) { - $self->assertEquals('git remote show origin', $command); - $output = " HEAD branch: master"; - - return 0; - }) - ; - - $executor - ->expects($this->at(2)) - ->method('execute') ->willReturnCallback(function ($command, &$output) use ($self) { $self->assertEquals('git rev-list master..latest-production', $command); $output = ""; @@ -195,8 +160,6 @@ class RootPackageLoaderTest extends TestCase $loader = new RootPackageLoader($manager, $config, null, new VersionGuesser($config, $executor, new VersionParser())); $package = $loader->load(array('require' => array('foo/bar' => 'self.version'))); - $this->assertEquals("9999999-dev", $package->getPrettyVersion()); - $package = $package->getAliasOf(); $this->assertEquals("dev-master", $package->getPrettyVersion()); } diff --git a/tests/Composer/Test/Package/Version/VersionGuesserTest.php b/tests/Composer/Test/Package/Version/VersionGuesserTest.php index 0b7486afd..cedd697ce 100644 --- a/tests/Composer/Test/Package/Version/VersionGuesserTest.php +++ b/tests/Composer/Test/Package/Version/VersionGuesserTest.php @@ -135,7 +135,7 @@ class VersionGuesserTest extends TestCase $this->assertEquals($commitHash, $versionArray['commit']); } - public function testGuessVersionReadsAndRespectsDefaultBranchAsNonFeatureBranch() + public function testGuessVersionDoesNotSeeCustomDefaultBranchAsNonFeatureBranch() { $commitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea'; $anotherCommitHash = '13a15d220da53c52eddd5f32ffca64a7b3801bea'; @@ -149,6 +149,7 @@ class VersionGuesserTest extends TestCase $self = $this; + // Assumption here is that arbitrary would be the default branch $executor ->expects($this->at(0)) ->method('execute') @@ -160,37 +161,13 @@ class VersionGuesserTest extends TestCase }) ; - $executor - ->expects($this->at(1)) - ->method('execute') - ->willReturnCallback(function ($command, &$output) use ($self) { - $self->assertEquals('git remote show origin', $command); - $output = " HEAD branch: arbitrary\r\n"; - - return 0; - }) - ; - - $executor - ->expects($this->at(2)) - ->method('execute') - ->willReturnCallback(function ($command, &$output, $path) use ($self, $anotherCommitHash) { - $self->assertEquals('git rev-list arbitrary..current', $command); - $output = "$anotherCommitHash\n"; - - return 0; - }) - ; - $config = new Config; $config->merge(array('repositories' => array('packagist' => false))); $guesser = new VersionGuesser($config, $executor, new VersionParser()); $versionArray = $guesser->guessVersion(array('version' => 'self.version'), 'dummy/path'); - $this->assertEquals("dev-arbitrary", $versionArray['version']); + $this->assertEquals("dev-current", $versionArray['version']); $this->assertEquals($anotherCommitHash, $versionArray['commit']); - $this->assertEquals("dev-current", $versionArray['feature_version']); - $this->assertEquals("dev-current", $versionArray['feature_pretty_version']); } public function testGuessVersionReadsAndRespectsNonFeatureBranchesConfigurationForArbitraryNaming() @@ -221,17 +198,6 @@ class VersionGuesserTest extends TestCase $executor ->expects($this->at(1)) ->method('execute') - ->willReturnCallback(function ($command, &$output) use ($self) { - $self->assertEquals('git remote show origin', $command); - $output = " HEAD branch: foo\r\n"; - - return 0; - }) - ; - - $executor - ->expects($this->at(2)) - ->method('execute') ->willReturnCallback(function ($command, &$output, $path) use ($self, $anotherCommitHash) { $self->assertEquals('git rev-list arbitrary..current', $command); $output = "$anotherCommitHash\n"; @@ -278,16 +244,6 @@ class VersionGuesserTest extends TestCase $executor ->expects($this->at(1)) ->method('execute') - ->willReturnCallback(function ($command, &$output) use ($self) { - $self->assertEquals('git remote show origin', $command); - $output = " HEAD branch: foo\r\n"; - - return 0; - }) - ; - $executor - ->expects($this->at(2)) - ->method('execute') ->willReturnCallback(function ($command, &$output, $path) use ($self, $anotherCommitHash) { $self->assertEquals('git rev-list latest-testing..current', $command); $output = "$anotherCommitHash\n"; @@ -459,16 +415,6 @@ class VersionGuesserTest extends TestCase $executor ->expects($this->at(1)) ->method('execute') - ->willReturnCallback(function ($command, &$output) use ($self) { - $self->assertEquals('git remote show origin', $command); - $output = " HEAD branch: foo\r\n"; - - return 0; - }) - ; - $executor - ->expects($this->at(2)) - ->method('execute') ->willReturnCallback(function ($command, &$output) use ($self) { $self->assertEquals('git describe --exact-match --tags', $command); $output = "v2.0.5-alpha2"; @@ -509,16 +455,6 @@ class VersionGuesserTest extends TestCase $executor ->expects($this->at(1)) ->method('execute') - ->willReturnCallback(function ($command, &$output) use ($self) { - $self->assertEquals('git remote show origin', $command); - $output = " HEAD branch: foo\r\n"; - - return 0; - }) - ; - $executor - ->expects($this->at(2)) - ->method('execute') ->willReturnCallback(function ($command, &$output) use ($self) { $self->assertEquals('git describe --exact-match --tags', $command); $output = '1.0.0';