Repository navigation
De-duplicate packages list on wp package update - #269
Merged
swissspidy merged 2 commits intoDec 2, 2026
Merged
Conversation
`wp package update A A` kept the duplicate name in `$packages_to_update`. `count()` and `array_intersect()` both kept the duplicate, so the two counts matched and the plural message "All 2 packages updated successfully." was printed for one package. Remove duplicate names after the validation loop with `array_unique()`. Add a Behat scenario that names one package twice and expects "Package updated successfully.". Fixes wp-cli#267
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
swissspidy
reviewed
Dec 2, 2026
Comment on lines
+705
to
+706
| // Report each package once, even if it was named more than once. | ||
| $packages_to_update = array_values( array_unique( $packages_to_update ) ); |
Member
There was a problem hiding this comment.
Why not do array_unique( $args ) before trying to update packages? Otherwise a bit wasteful...
Contributor
Author
There was a problem hiding this comment.
Good point, thanks. Done in a341aef: array_unique( $args ) now runs before the lookup loop, and I removed the second array_unique() after it. Each package is now looked up once. The PR description is updated to match.
Call array_unique() on the arguments before the validation loop, instead of on the resolved names after it. Each package is now looked up once, so a repeated name no longer costs extra composer.json reads. Addresses review feedback on wp-cli#269.
swissspidy
approved these changes
Dec 2, 2026
update names it twicewp package update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #267
What changed
src/Package_Command.php: inupdate(), the package arguments now go througharray_unique()before the validation loop. Before, a package named twice was looked up twice and stayed in$packages_to_updatetwice.features/package-update.feature: new scenario "Update a package named more than once counts it once".Why
wp package update A AprintedSuccess: All 2 packages updated successfully.for one package.count( $packages_to_update )was2, andarray_intersect()also kept the duplicate, so$num_updatedwas2and the plural message was chosen. When the package had no update, the output was the plural "Packages already at latest versions." instead of "Package already at latest version.".Only exact repeats are removed. Two different spellings of one package (a legacy lowercase name and its pretty name) are not merged. That case is rare and is out of scope here.
About the test
The scenario installs
wp-cli-test/updateable-package:v3.0.0, relaxes the constraint to>=3.0.0, and runswp package updatewith the same name twice. It expectsSuccess: Package updated successfully.and noAll 2 packages. Without the fix the scenario fails withSuccess: All 2 packages updated successfully.. With the fix it passes.Out of scope
updatebuilds a package list from arguments.Test plan
Run locally with
WP_CLI_PHP_ARGScleared.GITHUB_TOKENwas not set, so the@github-apiscenarios did not run.features/package-update.feature(all scenarios that can run withoutGITHUB_TOKEN): 11 passed, 0 failed.vendor/bin/run-php-unit-tests: 87 tests OK. The 1 PHPUnit deprecation is the same without this change.parallel-lint,phpstan analyse,lint-gherkin: no errors.phpcs: no errors in the changed files.@github-apiscenarios, the other feature files, and Windows.Summary by CodeRabbit