1
0
Fork 0

Display branches and tags if verbose is specified

pull/8137/head
Sam L 2019-05-01 11:25:26 -04:00 committed by Rob
parent 5d615a16d1
commit 8288d2c456
1 changed files with 32 additions and 29 deletions

View File

@ -30,7 +30,8 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
{ {
protected $url; protected $url;
protected $packageName; protected $packageName;
protected $verbose; protected $isVerbose;
protected $isVeryVerbose;
protected $io; protected $io;
protected $config; protected $config;
protected $versionParser; protected $versionParser;
@ -64,7 +65,8 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
$this->url = $repoConfig['url']; $this->url = $repoConfig['url'];
$this->io = $io; $this->io = $io;
$this->type = isset($repoConfig['type']) ? $repoConfig['type'] : 'vcs'; $this->type = isset($repoConfig['type']) ? $repoConfig['type'] : 'vcs';
$this->verbose = $io->isVeryVerbose(); $this->isVerbose = $io->isVerbose();
$this->isVeryVerbose = $io->isVeryVerbose();
$this->config = $config; $this->config = $config;
$this->repoConfig = $repoConfig; $this->repoConfig = $repoConfig;
$this->versionCache = $versionCache; $this->versionCache = $versionCache;
@ -127,7 +129,8 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
{ {
parent::initialize(); parent::initialize();
$verbose = $this->verbose; $isVerbose = $this->isVerbose;
$isVeryVerbose = $this->isVeryVerbose;
$driver = $this->getDriver(); $driver = $this->getDriver();
if (!$driver) { if (!$driver) {
@ -145,23 +148,23 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
$this->packageName = !empty($data['name']) ? $data['name'] : null; $this->packageName = !empty($data['name']) ? $data['name'] : null;
} }
} catch (\Exception $e) { } catch (\Exception $e) {
if ($verbose) { if ($isVeryVerbose) {
$this->io->writeError('<error>Skipped parsing '.$driver->getRootIdentifier().', '.$e->getMessage().'</error>'); $this->io->writeError('<error>Skipped parsing '.$driver->getRootIdentifier().', '.$e->getMessage().'</error>');
} }
} }
foreach ($driver->getTags() as $tag => $identifier) { foreach ($driver->getTags() as $tag => $identifier) {
$msg = 'Reading composer.json of <info>' . ($this->packageName ?: $this->url) . '</info> (<comment>' . $tag . '</comment>)'; $msg = 'Reading composer.json of <info>' . ($this->packageName ?: $this->url) . '</info> (<comment>' . $tag . '</comment>)';
if ($verbose) { if ($isVeryVerbose) {
$this->io->writeError($msg); $this->io->writeError($msg);
} else { } elseif ($isVerbose) {
$this->io->overwriteError($msg, false); $this->io->overwriteError($msg, false);
} }
// strip the release- prefix from tags if present // strip the release- prefix from tags if present
$tag = str_replace('release-', '', $tag); $tag = str_replace('release-', '', $tag);
$cachedPackage = $this->getCachedPackageVersion($tag, $identifier, $verbose); $cachedPackage = $this->getCachedPackageVersion($tag, $identifier, $isVerbose, $isVeryVerbose);
if ($cachedPackage) { if ($cachedPackage) {
$this->addPackage($cachedPackage); $this->addPackage($cachedPackage);
@ -173,7 +176,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
} }
if (!$parsedTag = $this->validateTag($tag)) { if (!$parsedTag = $this->validateTag($tag)) {
if ($verbose) { if ($isVeryVerbose) {
$this->io->writeError('<warning>Skipped tag '.$tag.', invalid tag name</warning>'); $this->io->writeError('<warning>Skipped tag '.$tag.', invalid tag name</warning>');
} }
continue; continue;
@ -181,7 +184,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
try { try {
if (!$data = $driver->getComposerInformation($identifier)) { if (!$data = $driver->getComposerInformation($identifier)) {
if ($verbose) { if ($isVeryVerbose) {
$this->io->writeError('<warning>Skipped tag '.$tag.', no composer file</warning>'); $this->io->writeError('<warning>Skipped tag '.$tag.', no composer file</warning>');
} }
$this->emptyReferences[] = $identifier; $this->emptyReferences[] = $identifier;
@ -203,7 +206,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
// broken package, version doesn't match tag // broken package, version doesn't match tag
if ($data['version_normalized'] !== $parsedTag) { if ($data['version_normalized'] !== $parsedTag) {
if ($verbose) { if ($isVeryVerbose) {
$this->io->writeError('<warning>Skipped tag '.$tag.', tag ('.$parsedTag.') does not match version ('.$data['version_normalized'].') in composer.json</warning>'); $this->io->writeError('<warning>Skipped tag '.$tag.', tag ('.$parsedTag.') does not match version ('.$data['version_normalized'].') in composer.json</warning>');
} }
continue; continue;
@ -211,13 +214,13 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
$tagPackageName = isset($data['name']) ? $data['name'] : $this->packageName; $tagPackageName = isset($data['name']) ? $data['name'] : $this->packageName;
if ($existingPackage = $this->findPackage($tagPackageName, $data['version_normalized'])) { if ($existingPackage = $this->findPackage($tagPackageName, $data['version_normalized'])) {
if ($verbose) { if ($isVeryVerbose) {
$this->io->writeError('<warning>Skipped tag '.$tag.', it conflicts with an another tag ('.$existingPackage->getPrettyVersion().') as both resolve to '.$data['version_normalized'].' internally</warning>'); $this->io->writeError('<warning>Skipped tag '.$tag.', it conflicts with an another tag ('.$existingPackage->getPrettyVersion().') as both resolve to '.$data['version_normalized'].' internally</warning>');
} }
continue; continue;
} }
if ($verbose) { if ($isVeryVerbose) {
$this->io->writeError('Importing tag '.$tag.' ('.$data['version_normalized'].')'); $this->io->writeError('Importing tag '.$tag.' ('.$data['version_normalized'].')');
} }
@ -226,35 +229,35 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
if ($e instanceof TransportException && $e->getCode() === 404) { if ($e instanceof TransportException && $e->getCode() === 404) {
$this->emptyReferences[] = $identifier; $this->emptyReferences[] = $identifier;
} }
if ($verbose) { if ($isVeryVerbose) {
$this->io->writeError('<warning>Skipped tag '.$tag.', '.($e instanceof TransportException ? 'no composer file was found' : $e->getMessage()).'</warning>'); $this->io->writeError('<warning>Skipped tag '.$tag.', '.($e instanceof TransportException ? 'no composer file was found' : $e->getMessage()).'</warning>');
} }
continue; continue;
} }
} }
if (!$verbose) { if (!$isVeryVerbose) {
$this->io->overwriteError('', false); $this->io->overwriteError('', false);
} }
$branches = $driver->getBranches(); $branches = $driver->getBranches();
foreach ($branches as $branch => $identifier) { foreach ($branches as $branch => $identifier) {
$msg = 'Reading composer.json of <info>' . ($this->packageName ?: $this->url) . '</info> (<comment>' . $branch . '</comment>)'; $msg = 'Reading composer.json of <info>' . ($this->packageName ?: $this->url) . '</info> (<comment>' . $branch . '</comment>)';
if ($verbose) { if ($isVeryVerbose) {
$this->io->writeError($msg); $this->io->writeError($msg);
} else { } elseif ($isVerbose) {
$this->io->overwriteError($msg, false); $this->io->overwriteError($msg, false);
} }
if ($branch === 'trunk' && isset($branches['master'])) { if ($branch === 'trunk' && isset($branches['master'])) {
if ($verbose) { if ($isVeryVerbose) {
$this->io->writeError('<warning>Skipped branch '.$branch.', can not parse both master and trunk branches as they both resolve to 9999999-dev internally</warning>'); $this->io->writeError('<warning>Skipped branch '.$branch.', can not parse both master and trunk branches as they both resolve to 9999999-dev internally</warning>');
} }
continue; continue;
} }
if (!$parsedBranch = $this->validateBranch($branch)) { if (!$parsedBranch = $this->validateBranch($branch)) {
if ($verbose) { if ($isVeryVerbose) {
$this->io->writeError('<warning>Skipped branch '.$branch.', invalid name</warning>'); $this->io->writeError('<warning>Skipped branch '.$branch.', invalid name</warning>');
} }
continue; continue;
@ -268,7 +271,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
$version = $prefix . preg_replace('{(\.9{7})+}', '.x', $parsedBranch); $version = $prefix . preg_replace('{(\.9{7})+}', '.x', $parsedBranch);
} }
$cachedPackage = $this->getCachedPackageVersion($version, $identifier, $verbose); $cachedPackage = $this->getCachedPackageVersion($version, $identifier, $isVerbose, $isVeryVerbose);
if ($cachedPackage) { if ($cachedPackage) {
$this->addPackage($cachedPackage); $this->addPackage($cachedPackage);
@ -281,7 +284,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
try { try {
if (!$data = $driver->getComposerInformation($identifier)) { if (!$data = $driver->getComposerInformation($identifier)) {
if ($verbose) { if ($isVeryVerbose) {
$this->io->writeError('<warning>Skipped branch '.$branch.', no composer file</warning>'); $this->io->writeError('<warning>Skipped branch '.$branch.', no composer file</warning>');
} }
$this->emptyReferences[] = $identifier; $this->emptyReferences[] = $identifier;
@ -292,7 +295,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
$data['version'] = $version; $data['version'] = $version;
$data['version_normalized'] = $parsedBranch; $data['version_normalized'] = $parsedBranch;
if ($verbose) { if ($isVeryVerbose) {
$this->io->writeError('Importing branch '.$branch.' ('.$data['version'].')'); $this->io->writeError('Importing branch '.$branch.' ('.$data['version'].')');
} }
@ -306,12 +309,12 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
if ($e->getCode() === 404) { if ($e->getCode() === 404) {
$this->emptyReferences[] = $identifier; $this->emptyReferences[] = $identifier;
} }
if ($verbose) { if ($isVeryVerbose) {
$this->io->writeError('<warning>Skipped branch '.$branch.', no composer file was found</warning>'); $this->io->writeError('<warning>Skipped branch '.$branch.', no composer file was found</warning>');
} }
continue; continue;
} catch (\Exception $e) { } catch (\Exception $e) {
if (!$verbose) { if (!$isVeryVerbose) {
$this->io->writeError(''); $this->io->writeError('');
} }
$this->branchErrorOccurred = true; $this->branchErrorOccurred = true;
@ -322,7 +325,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
} }
$driver->cleanup(); $driver->cleanup();
if (!$verbose) { if (!$isVeryVerbose) {
$this->io->overwriteError('', false); $this->io->overwriteError('', false);
} }
@ -367,7 +370,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
return false; return false;
} }
private function getCachedPackageVersion($version, $identifier, $verbose) private function getCachedPackageVersion($version, $identifier, $isVerbose, $isVeryVerbose)
{ {
if (!$this->versionCache) { if (!$this->versionCache) {
return; return;
@ -375,7 +378,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
$cachedPackage = $this->versionCache->getVersionPackage($version, $identifier); $cachedPackage = $this->versionCache->getVersionPackage($version, $identifier);
if ($cachedPackage === false) { if ($cachedPackage === false) {
if ($verbose) { if ($isVeryVerbose) {
$this->io->writeError('<warning>Skipped '.$version.', no composer file (cached from ref '.$identifier.')</warning>'); $this->io->writeError('<warning>Skipped '.$version.', no composer file (cached from ref '.$identifier.')</warning>');
} }
@ -384,14 +387,14 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
if ($cachedPackage) { if ($cachedPackage) {
$msg = 'Found cached composer.json of <info>' . ($this->packageName ?: $this->url) . '</info> (<comment>' . $version . '</comment>)'; $msg = 'Found cached composer.json of <info>' . ($this->packageName ?: $this->url) . '</info> (<comment>' . $version . '</comment>)';
if ($verbose) { if ($isVeryVerbose) {
$this->io->writeError($msg); $this->io->writeError($msg);
} else { } elseif ($isVerbose) {
$this->io->overwriteError($msg, false); $this->io->overwriteError($msg, false);
} }
if ($existingPackage = $this->findPackage($cachedPackage['name'], $cachedPackage['version_normalized'])) { if ($existingPackage = $this->findPackage($cachedPackage['name'], $cachedPackage['version_normalized'])) {
if ($verbose) { if ($isVeryVerbose) {
$this->io->writeError('<warning>Skipped cached version '.$version.', it conflicts with an another tag ('.$existingPackage->getPrettyVersion().') as both resolve to '.$cachedPackage['version_normalized'].' internally</warning>'); $this->io->writeError('<warning>Skipped cached version '.$version.', it conflicts with an another tag ('.$existingPackage->getPrettyVersion().') as both resolve to '.$cachedPackage['version_normalized'].' internally</warning>');
} }
$cachedPackage = null; $cachedPackage = null;