Skip to content

Require --major for cross-major wp cli update#6355

Draft
schlessera wants to merge 1 commit into
mainfrom
fix/cli-update-require-major-for-cross-major
Draft

Require --major for cross-major wp cli update#6355
schlessera wants to merge 1 commit into
mainfrom
fix/cli-update-require-major-for-cross-major

Conversation

@schlessera

Copy link
Copy Markdown
Member

What

By default, wp cli update no longer crosses a major version boundary. A major update is only performed when --major is passed. When a major update is available but withheld, the command announces it and names the --major flag.

Why

Today wp cli update picks the newest available release of any type, so a user on 2.x is automatically offered (and with --yes, moved to) the next major. A major can raise the minimum PHP version or change behavior, so an unattended wp cli update should not step across that line on its own. Requiring --major makes crossing a major a deliberate choice, while routine wp cli update keeps a user current within their major.

This is a deliberate behavior change for 3.0.0.

Behavior

Before, on 2.12.0 with 3.0.0 available:

$ wp cli update
You have version 2.12.0. Would you like to update to 3.0.0? [y/n]

After:

$ wp cli update
A new major version (3.0.0) is available. Run `wp cli update --major` to update across major versions.
Success: WP-CLI is at the latest version.

$ wp cli update --major
You have version 2.12.0. Would you like to update to 3.0.0? [y/n]

Within-major updates (minor and patch) work exactly as before with no flag.

Scope

  • --stable and --nightly are unchanged. They are an explicit request for a specific channel or build, not the default "is there an update?" path.
  • wp cli check-update still lists all available updates, including majors. This PR only changes which update the default wp cli update will apply.

Implementation

The version-selection logic is pulled out of update() into select_update_offer(), which excludes a major update unless it has been requested and reports a withheld major separately so the caller can hint at --major. This keeps the network fetch (get_updates()) and the selection policy apart, and makes the policy unit-testable.

Tests

tests/CLICommandTest.php gains unit tests for select_update_offer(): the default skips a major and picks the newest minor/patch, falls back to patch when there is no minor, --major offers the major, a lone major is withheld with a hint, and an unavailable major produces no hint.

By default `wp cli update` offered the newest available release of any
type, so it would jump across a major version boundary automatically.
That can silently move a user onto a major that drops support for their
PHP version or changes behavior.

Keep the update within the current major version by default. A major
update is only applied when `--major` is passed explicitly. When a major
update is available but withheld, announce it and point at the `--major`
flag so the jump stays a deliberate choice.

The `--stable` and `--nightly` channels are unchanged, since they are an
explicit request for a specific build.

The selection logic is extracted into `select_update_offer()` and covered
by unit tests.
@schlessera schlessera added this to the 3.0.0 milestone Jul 21, 2026
@schlessera schlessera added breaking-change command:cli Related to 'cli' command labels Jul 21, 2026
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0372091b-1623-40b6-bdb0-5c6d71f8bd58

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/cli-update-require-major-for-cross-major

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added command:cli-check-update Related to 'cli check-update' command command:cli-update Related to 'cli update' command labels Jul 21, 2026
@swissspidy

Copy link
Copy Markdown
Member

A major can raise the minimum PHP version or change behavior, so an unattended wp cli update should not step across that line on its own

Just noting/clarifying that we have PHP version requirement checks in place (using the manifest.json file) to avoid such surprises.

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.38462% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
php/commands/src/CLI_Command.php 65.38% 9 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change command:cli Related to 'cli' command command:cli-check-update Related to 'cli check-update' command command:cli-update Related to 'cli update' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants