Skip to content

Commit 78a94b4

Browse files
feature #795 Add --reset flag to recipes:install to reset all installed recipes back to their initial state (nicolas-grekas)
This PR was merged into the 1.13-dev branch. Discussion ---------- Add --reset flag to recipes:install to reset all installed recipes back to their initial state Fix #777 Replaces #702, see discussion there. Commits ------- fc1998f Add --reset flag to recipes:install to reset all installed recipes back to their initial state
2 parents 6c13a9e + fc1998f commit 78a94b4

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

src/Command/InstallRecipesCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ protected function configure()
4242
->setDescription('Installs or reinstalls recipes for already installed packages.')
4343
->addArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Recipes that should be installed.')
4444
->addOption('force', null, InputOption::VALUE_NONE, 'Overwrite existing files when a new version of a recipe is available')
45+
->addOption('reset', null, InputOption::VALUE_NONE, 'Reset all recipes back to their initial state (should be combined with --force)')
4546
;
4647
}
4748

4849
protected function execute(InputInterface $input, OutputInterface $output): int
4950
{
5051
$win = '\\' === \DIRECTORY_SEPARATOR;
51-
$force = $input->getOption('force');
52+
$force = (bool) $input->getOption('force');
5253

5354
if ($force && !@is_executable(strtok(exec($win ? 'where git' : 'command -v git'), \PHP_EOL))) {
5455
throw new RuntimeException('Cannot run "sync-recipes --force": git not found.');
@@ -128,7 +129,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
128129
}
129130
}
130131

131-
$this->flex->update(new UpdateEvent($force), $operations);
132+
$this->flex->update(new UpdateEvent($force, (bool) $input->getOption('reset')), $operations);
132133

133134
if ($force) {
134135
$output = [

src/Command/RecipesCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8181
$operations[] = new InformationOperation($pkg);
8282
}
8383

84-
$recipes = $this->flex->fetchRecipes($operations);
84+
$recipes = $this->flex->fetchRecipes($operations, false);
8585
ksort($recipes);
8686

8787
$nbRecipe = \count($recipes);

src/Event/UpdateEvent.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,22 @@
1717
class UpdateEvent extends Event
1818
{
1919
private $force;
20+
private $reset;
2021

21-
public function __construct(bool $force)
22+
public function __construct(bool $force, bool $reset)
2223
{
2324
$this->name = ScriptEvents::POST_UPDATE_CMD;
2425
$this->force = $force;
26+
$this->reset = $reset;
2527
}
2628

2729
public function force(): bool
2830
{
2931
return $this->force;
3032
}
33+
34+
public function reset(): bool
35+
{
36+
return $this->reset;
37+
}
3138
}

src/Flex.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public function install(Event $event)
396396
}
397397

398398
// Execute missing recipes
399-
$recipes = ScriptEvents::POST_UPDATE_CMD === $event->getName() ? $this->fetchRecipes($this->operations) : [];
399+
$recipes = ScriptEvents::POST_UPDATE_CMD === $event->getName() ? $this->fetchRecipes($this->operations, $event instanceof UpdateEvent && $event->reset()) : [];
400400
$this->operations = []; // Reset the operation after getting recipes
401401

402402
if (2 === $this->displayThanksReminder) {
@@ -692,7 +692,7 @@ public function onFileDownload(PreFileDownloadEvent $event)
692692
/**
693693
* @return Recipe[]
694694
*/
695-
public function fetchRecipes(array $operations): array
695+
public function fetchRecipes(array $operations, bool $reset): array
696696
{
697697
if (!$this->downloader->isEnabled()) {
698698
$this->io->writeError('<warning>Symfony recipes are disabled: "symfony/flex" not found in the root composer.json</>');
@@ -735,7 +735,7 @@ public function fetchRecipes(array $operations): array
735735

736736
if ($operation instanceof InstallOperation && isset($locks[$name])) {
737737
$ref = $this->lock->get($name)['recipe']['ref'] ?? null;
738-
if ($ref && ($locks[$name]['recipe']['ref'] ?? null) === $ref) {
738+
if (!$reset && $ref && ($locks[$name]['recipe']['ref'] ?? null) === $ref) {
739739
continue;
740740
}
741741
$this->lock->set($name, $locks[$name]);

0 commit comments

Comments
 (0)