Skip to content

Commit

Permalink
bug #866 Fix BC with upgrading from flex < 1.18 (nicolas-grekas)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.x branch.

Discussion
----------

Fix BC with upgrading from flex < 1.18

Fix #863

Commits
-------

a0a2080 Fix BC with upgrading from flex < 1.18
  • Loading branch information
nicolas-grekas committed Feb 16, 2022
2 parents 910a5c5 + a0a2080 commit ea2a03c
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/Flex.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public function install(Event $event)
foreach ($recipes as $recipe) {
if ('install' === $recipe->getJob() && !$installContribs && $recipe->isContrib()) {
$warning = $this->io->isInteractive() ? 'WARNING' : 'IGNORING';
$this->io->writeError(sprintf(' - <warning> %s </> %s', $warning, $recipe->getFormattedOrigin()));
$this->io->writeError(sprintf(' - <warning> %s </> %s', $warning, $this->formatOrigin($recipe)));
$question = sprintf(' The recipe for this package comes from the "contrib" repository, which is open to community contributions.
Review the recipe at %s
Expand Down Expand Up @@ -474,7 +474,7 @@ function ($value) {

switch ($recipe->getJob()) {
case 'install':
$this->io->writeError(sprintf(' - Configuring %s', $recipe->getFormattedOrigin()));
$this->io->writeError(sprintf(' - Configuring %s', $this->formatOrigin($recipe)));
$this->configurator->install($recipe, $this->lock, [
'force' => $event instanceof UpdateEvent && $event->force(),
]);
Expand All @@ -491,7 +491,7 @@ function ($value) {
case 'update':
break;
case 'uninstall':
$this->io->writeError(sprintf(' - Unconfiguring %s', $recipe->getFormattedOrigin()));
$this->io->writeError(sprintf(' - Unconfiguring %s', $this->formatOrigin($recipe)));
$this->configurator->unconfigure($recipe, $this->lock);
break;
}
Expand Down Expand Up @@ -834,6 +834,23 @@ private function initOptions(): Options
return new Options($options, $this->io);
}

private function formatOrigin(Recipe $recipe): string
{
if (method_exists($recipe, 'getFormattedOrigin')) {
return $recipe->getFormattedOrigin();
}

// BC with upgrading from flex < 1.18
$origin = $recipe->getOrigin();

// symfony/translation:3.3@github.com/symfony/recipes:branch
if (!preg_match('/^([^:]++):([^@]++)@(.+)$/', $origin, $matches)) {
return $origin;
}

return sprintf('<info>%s</> (<comment>>=%s</>): From %s', $matches[1], $matches[2], 'auto-generated recipe' === $matches[3] ? '<comment>'.$matches[3].'</>' : $matches[3]);
}

private function shouldRecordOperation(PackageEvent $event): bool
{
$operation = $event->getOperation();
Expand Down

0 comments on commit ea2a03c

Please sign in to comment.