Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions features/plugin-update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,36 @@ Feature: Update WordPress plugins
"""
Success: Updated 2 of 2 plugins.
"""

@require-wp-5.2
Scenario: Skip plugin update when plugin directory is a VCS checkout
Given a WP install
And I run `wp plugin install wordpress-importer --version=0.5 --force`
And I run `wp plugin path wordpress-importer --dir`
And save STDOUT as {PLUGIN_DIR}

When I run `mkdir {PLUGIN_DIR}/.git`
And I try `wp plugin update wordpress-importer`
Then STDERR should contain:
"""
Warning: wordpress-importer: Skipped update because a VCS checkout was detected. Use --include-vcs to override.
"""
And STDERR should contain:
"""
Error: No plugins updated.
"""
And the return code should be 1

@require-wp-5.2
Scenario: Update plugin in VCS checkout when --include-vcs is set
Given a WP install
And I run `wp plugin install wordpress-importer --version=0.5 --force`
And I run `wp plugin path wordpress-importer --dir`
And save STDOUT as {PLUGIN_DIR}

When I run `mkdir {PLUGIN_DIR}/.git`
And I run `wp plugin update wordpress-importer --include-vcs`
Then STDOUT should contain:
"""
Success: Updated 1 of 1 plugins.
"""
31 changes: 31 additions & 0 deletions features/theme-update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,34 @@ Feature: Update WordPress themes
"""
Success: Updated 2 of 2 themes.
"""

Scenario: Skip theme update when theme directory is a VCS checkout
Given a WP install
And I run `wp theme install twentytwelve --version=3.0 --force`
And I run `wp theme path twentytwelve --dir`
And save STDOUT as {THEME_DIR}

When I run `mkdir {THEME_DIR}/.git`
And I try `wp theme update twentytwelve`
Then STDERR should contain:
"""
Warning: twentytwelve: Skipped update because a VCS checkout was detected. Use --include-vcs to override.
"""
And STDERR should contain:
"""
Error: No themes updated.
"""
And the return code should be 1

Scenario: Update theme in VCS checkout when --include-vcs is set
Given a WP install
And I run `wp theme install twentytwelve --version=3.0 --force`
And I run `wp theme path twentytwelve --dir`
And save STDOUT as {THEME_DIR}

When I run `mkdir {THEME_DIR}/.git`
And I run `wp theme update twentytwelve --include-vcs`
Then STDOUT should contain:
"""
Success: Updated 1 of 1 themes.
"""
3 changes: 3 additions & 0 deletions src/Plugin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,9 @@ protected function install_from_repo( $slug, $assoc_args ) {
* [--auto-update-indicated]
* : Only update plugins where the server response indicates an automatic update. Updates to the version indicated by the server, not necessarily the latest version. Cannot be used with `--version`, `--minor`, or `--patch`.
*
* [--include-vcs]
* : Include plugins that are version-controlled with a VCS (e.g. git, svn, hg). Skipped by default.
*
* ## EXAMPLES
*
* $ wp plugin update bbpress --version=dev
Expand Down
3 changes: 3 additions & 0 deletions src/Theme_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,9 @@ public function get( $args, $assoc_args ) {
* [--auto-update-indicated]
* : Only update themes where the server response indicates an automatic update. Updates to the version indicated by the server, not necessarily the latest version. Cannot be used with `--version`, `--minor`, or `--patch`.
*
* [--include-vcs]
* : Include themes that are version-controlled with a VCS (e.g. git, svn, hg). Skipped by default.
*
* ## EXAMPLES
*
* # Update multiple themes
Expand Down
24 changes: 24 additions & 0 deletions src/WP_CLI/CommandWithUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,30 @@ function ( $item ) {
}
}

// Skip VCS-controlled items unless --include-vcs is set.
if ( ! Utils\get_flag_value( $assoc_args, 'include-vcs', false ) && in_array( $this->item_type, [ 'plugin', 'theme' ], true ) ) {
if ( ! class_exists( 'WP_Automatic_Updater' ) ) {
if ( file_exists( ABSPATH . 'wp-admin/includes/class-wp-automatic-updater.php' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-automatic-updater.php';
} else {
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
}
}
$automatic_updater = new \WP_Automatic_Updater();
foreach ( $items_to_update as $item_key => $item_info ) {
if ( 'plugin' === $this->item_type ) {
$item_dir = WP_PLUGIN_DIR . '/' . dirname( $item_key );
} else {
$item_dir = get_theme_root( $item_key ) . '/' . $item_key;
}
if ( $automatic_updater->is_vcs_checkout( $item_dir ) ) {
WP_CLI::warning( "{$item_info['name']}: Skipped update because a VCS checkout was detected. Use --include-vcs to override." );
++$skipped;
unset( $items_to_update[ $item_key ] );
}
}
}

if ( Utils\get_flag_value( $assoc_args, 'dry-run' ) ) {
if ( empty( $items_to_update ) ) {
WP_CLI::log( "No {$this->item_type} updates available." );
Expand Down
Loading