Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 15, 2026

Implementation Complete: Auto-rerun command after Phar update

Summary

This PR resolves the issue where users had to manually re-run their WP-CLI command after an auto-update was installed. The implementation automatically re-executes the original command with the updated Phar, providing a seamless update experience.

Changes Implemented

Environment Variable for Auto-Confirmation (WP_CLI_AUTO_UPDATE_PROMPT)

  • Set to 'no' to skip the update confirmation prompt
  • Automatically passes --yes to the cli update command
  • Enables fully automated update workflows

Automatic Command Re-execution

  • Re-executes the original command after successful update
  • Uses modification time comparison to verify Phar was actually updated
  • Only reruns if the Phar file was replaced (not if update declined or no update available)
  • Uses passthru() for subprocess execution
  • Properly escapes all arguments with escapeshellarg()
  • Passes through exit codes correctly
  • Includes debug logging for troubleshooting

Safety Mechanisms

  • Skips re-execution for CLI commands (prevents infinite loops)
  • Skips re-execution when no command provided
  • Validates realpath() result and shows error if it fails
  • Uses consistent $_SERVER['argv'] throughout
  • Checks if update actually occurred before rerunning

Testing

  • ✅ Linting passed
  • ✅ PHPCS code style checks passed
  • ✅ PHPUnit tests passed (unrelated failures in network tests)
  • ✅ Code review feedback addressed
  • ✅ Security analysis completed

Benefits

  • Better UX: No need to re-run commands after updates
  • Seamless: Update process is transparent to users
  • Configurable: Can disable prompts for automation
  • Backward Compatible: Default behavior preserved
  • Smart: Only reruns when update actually happened

Technical Details

  • Uses $GLOBALS['argv'] to retrieve original arguments
  • Uses $_SERVER['argv'][0] for Phar path (consistent with existing code)
  • Compares file modification times to detect if update occurred
  • All shell arguments properly escaped
  • Exit codes properly propagated
  • Comprehensive error handling
Original prompt

This section details on the original issue you should resolve

<issue_title>Spin up new Phar after auto update</issue_title>
<issue_description>It always bugs me that I have to re-run my previous WP-CLI command when it detected & installed an auto-update.

That's because of this line in Runner::auto_check_update():

wp-cli/php/WP_CLI/Runner.php

Lines 2033 to 2036 in 28c97a9

// Looks like an update is available, so let's prompt to update.
WP_CLI::run_command( [ 'cli', 'update' ] );
// If the Phar was replaced, we can't proceed with the original process.
exit;

I'm wondering: can't we just spin up the new Phar with the originally passed arguments in a subprocess?

This way, the user would get the benefit of the new features without the hassle of having to manually re-run the previous command.

Alternatively or additonally: pass --yes to cli update by default to disable the confirmation prompt (of course this should be configurable with an env var). </issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits January 15, 2026 13:52
…confirm

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add functionality to spin up new Phar after auto update Auto-rerun command after Phar update Jan 15, 2026
Copilot AI requested a review from swissspidy January 15, 2026 13:58
@codecov
Copy link

codecov bot commented Jan 15, 2026

Codecov Report

❌ Patch coverage is 0% with 27 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
php/WP_CLI/Runner.php 0.00% 27 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances WP-CLI's auto-update feature by automatically re-executing the original command after a successful Phar update, eliminating the need for users to manually re-run their commands. It also adds an optional environment variable to skip the update confirmation prompt.

Changes:

  • Implemented automatic command re-execution after Phar updates via a new rerun_command_after_update() method
  • Added WP_CLI_AUTO_UPDATE_PROMPT environment variable to optionally skip the confirmation prompt
  • Updated the auto-update flow to call the new re-execution method instead of immediately exiting

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spin up new Phar after auto update

2 participants