Get rid of default branch handling in version guesser as it is way too time intensive at every initialization
parent
05eec0b02f
commit
74d89d7110
|
@ -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);
|
$realPackage = $package = parent::load($config, $class);
|
||||||
if ($realPackage instanceof AliasPackage) {
|
if ($realPackage instanceof AliasPackage) {
|
||||||
$realPackage = $package->getAliasOf();
|
$realPackage = $package->getAliasOf();
|
||||||
|
|
|
@ -111,43 +111,6 @@ class VersionGuesser
|
||||||
return $versionData;
|
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)
|
private function guessGitVersion(array $packageConfig, $path)
|
||||||
{
|
{
|
||||||
GitUtil::cleanEnv();
|
GitUtil::cleanEnv();
|
||||||
|
@ -292,11 +255,9 @@ class VersionGuesser
|
||||||
return array('version' => $version, 'pretty_version' => $prettyVersion);
|
return array('version' => $version, 'pretty_version' => $prettyVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
$defaultBranch = $this->getDefaultBranchName($path);
|
|
||||||
|
|
||||||
foreach ($branches as $candidate) {
|
foreach ($branches as $candidate) {
|
||||||
// do not compare against itself or other feature branches
|
// 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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,4 @@ class VersionGuesserMock extends VersionGuesser
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDefaultBranchName($path)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,8 +105,6 @@ class RootPackageLoaderTest extends TestCase
|
||||||
'pretty_version' => '3.0-dev',
|
'pretty_version' => '3.0-dev',
|
||||||
'commit' => 'aabbccddee',
|
'commit' => 'aabbccddee',
|
||||||
));
|
));
|
||||||
$versionGuesser->getDefaultBranchName(Argument::cetera())
|
|
||||||
->willReturn('main');
|
|
||||||
$config = new Config;
|
$config = new Config;
|
||||||
$config->merge(array('repositories' => array('packagist' => false)));
|
$config->merge(array('repositories' => array('packagist' => false)));
|
||||||
$loader = new RootPackageLoader($manager->reveal(), $config, null, $versionGuesser->reveal());
|
$loader = new RootPackageLoader($manager->reveal(), $config, null, $versionGuesser->reveal());
|
||||||
|
@ -115,28 +113,6 @@ class RootPackageLoaderTest extends TestCase
|
||||||
$this->assertEquals('3.0-dev', $package->getPrettyVersion());
|
$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()
|
public function testFeatureBranchPrettyVersion()
|
||||||
{
|
{
|
||||||
if (!function_exists('proc_open')) {
|
if (!function_exists('proc_open')) {
|
||||||
|
@ -171,17 +147,6 @@ class RootPackageLoaderTest extends TestCase
|
||||||
$executor
|
$executor
|
||||||
->expects($this->at(1))
|
->expects($this->at(1))
|
||||||
->method('execute')
|
->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) {
|
->willReturnCallback(function ($command, &$output) use ($self) {
|
||||||
$self->assertEquals('git rev-list master..latest-production', $command);
|
$self->assertEquals('git rev-list master..latest-production', $command);
|
||||||
$output = "";
|
$output = "";
|
||||||
|
@ -195,8 +160,6 @@ class RootPackageLoaderTest extends TestCase
|
||||||
$loader = new RootPackageLoader($manager, $config, null, new VersionGuesser($config, $executor, new VersionParser()));
|
$loader = new RootPackageLoader($manager, $config, null, new VersionGuesser($config, $executor, new VersionParser()));
|
||||||
$package = $loader->load(array('require' => array('foo/bar' => 'self.version')));
|
$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());
|
$this->assertEquals("dev-master", $package->getPrettyVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,7 @@ class VersionGuesserTest extends TestCase
|
||||||
$this->assertEquals($commitHash, $versionArray['commit']);
|
$this->assertEquals($commitHash, $versionArray['commit']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGuessVersionReadsAndRespectsDefaultBranchAsNonFeatureBranch()
|
public function testGuessVersionDoesNotSeeCustomDefaultBranchAsNonFeatureBranch()
|
||||||
{
|
{
|
||||||
$commitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea';
|
$commitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea';
|
||||||
$anotherCommitHash = '13a15d220da53c52eddd5f32ffca64a7b3801bea';
|
$anotherCommitHash = '13a15d220da53c52eddd5f32ffca64a7b3801bea';
|
||||||
|
@ -149,6 +149,7 @@ class VersionGuesserTest extends TestCase
|
||||||
|
|
||||||
$self = $this;
|
$self = $this;
|
||||||
|
|
||||||
|
// Assumption here is that arbitrary would be the default branch
|
||||||
$executor
|
$executor
|
||||||
->expects($this->at(0))
|
->expects($this->at(0))
|
||||||
->method('execute')
|
->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 = new Config;
|
||||||
$config->merge(array('repositories' => array('packagist' => false)));
|
$config->merge(array('repositories' => array('packagist' => false)));
|
||||||
$guesser = new VersionGuesser($config, $executor, new VersionParser());
|
$guesser = new VersionGuesser($config, $executor, new VersionParser());
|
||||||
$versionArray = $guesser->guessVersion(array('version' => 'self.version'), 'dummy/path');
|
$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($anotherCommitHash, $versionArray['commit']);
|
||||||
$this->assertEquals("dev-current", $versionArray['feature_version']);
|
|
||||||
$this->assertEquals("dev-current", $versionArray['feature_pretty_version']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGuessVersionReadsAndRespectsNonFeatureBranchesConfigurationForArbitraryNaming()
|
public function testGuessVersionReadsAndRespectsNonFeatureBranchesConfigurationForArbitraryNaming()
|
||||||
|
@ -221,17 +198,6 @@ class VersionGuesserTest extends TestCase
|
||||||
$executor
|
$executor
|
||||||
->expects($this->at(1))
|
->expects($this->at(1))
|
||||||
->method('execute')
|
->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) {
|
->willReturnCallback(function ($command, &$output, $path) use ($self, $anotherCommitHash) {
|
||||||
$self->assertEquals('git rev-list arbitrary..current', $command);
|
$self->assertEquals('git rev-list arbitrary..current', $command);
|
||||||
$output = "$anotherCommitHash\n";
|
$output = "$anotherCommitHash\n";
|
||||||
|
@ -278,16 +244,6 @@ class VersionGuesserTest extends TestCase
|
||||||
$executor
|
$executor
|
||||||
->expects($this->at(1))
|
->expects($this->at(1))
|
||||||
->method('execute')
|
->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) {
|
->willReturnCallback(function ($command, &$output, $path) use ($self, $anotherCommitHash) {
|
||||||
$self->assertEquals('git rev-list latest-testing..current', $command);
|
$self->assertEquals('git rev-list latest-testing..current', $command);
|
||||||
$output = "$anotherCommitHash\n";
|
$output = "$anotherCommitHash\n";
|
||||||
|
@ -459,16 +415,6 @@ class VersionGuesserTest extends TestCase
|
||||||
$executor
|
$executor
|
||||||
->expects($this->at(1))
|
->expects($this->at(1))
|
||||||
->method('execute')
|
->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) {
|
->willReturnCallback(function ($command, &$output) use ($self) {
|
||||||
$self->assertEquals('git describe --exact-match --tags', $command);
|
$self->assertEquals('git describe --exact-match --tags', $command);
|
||||||
$output = "v2.0.5-alpha2";
|
$output = "v2.0.5-alpha2";
|
||||||
|
@ -509,16 +455,6 @@ class VersionGuesserTest extends TestCase
|
||||||
$executor
|
$executor
|
||||||
->expects($this->at(1))
|
->expects($this->at(1))
|
||||||
->method('execute')
|
->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) {
|
->willReturnCallback(function ($command, &$output) use ($self) {
|
||||||
$self->assertEquals('git describe --exact-match --tags', $command);
|
$self->assertEquals('git describe --exact-match --tags', $command);
|
||||||
$output = '1.0.0';
|
$output = '1.0.0';
|
||||||
|
|
Loading…
Reference in New Issue