diff --git a/features/plugin-update.feature b/features/plugin-update.feature index 7f7e1e5e..73577748 100644 --- a/features/plugin-update.feature +++ b/features/plugin-update.feature @@ -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. + """ diff --git a/features/theme-update.feature b/features/theme-update.feature index a71fdb1a..09633781 100644 --- a/features/theme-update.feature +++ b/features/theme-update.feature @@ -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. + """ diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index 1f6ec83e..29258459 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -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 diff --git a/src/Theme_Command.php b/src/Theme_Command.php index a087b202..6e42cf85 100644 --- a/src/Theme_Command.php +++ b/src/Theme_Command.php @@ -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 diff --git a/src/WP_CLI/CommandWithUpgrade.php b/src/WP_CLI/CommandWithUpgrade.php index 2dfc36cc..4cd20a4c 100755 --- a/src/WP_CLI/CommandWithUpgrade.php +++ b/src/WP_CLI/CommandWithUpgrade.php @@ -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." );