Skip to content

Commit 5e0ba2a

Browse files
authored
Merge branch 'main' into fix/96-theme-mod-get-format
2 parents 2d70f93 + 89767b4 commit 5e0ba2a

10 files changed

Lines changed: 122 additions & 4 deletions

.gitattributes

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/.actrc export-ignore
2+
/.distignore export-ignore
3+
/.editorconfig export-ignore
4+
/.github export-ignore
5+
/.gitignore export-ignore
6+
/.typos.toml export-ignore
7+
/AGENTS.md export-ignore
8+
/behat.yml export-ignore
9+
/features export-ignore
10+
/phpcs.xml.dist export-ignore
11+
/phpstan.neon.dist export-ignore
12+
/phpunit.xml.dist export-ignore
13+
/tests export-ignore
14+
/wp-cli.yml export-ignore

.github/workflows/copilot-setup-steps.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525

2626
- name: Set up PHP environment
2727
if: steps.check_composer_file.outputs.files_exists == 'true'
28-
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2
28+
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2
2929
with:
3030
php-version: 'latest'
3131
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
@@ -36,7 +36,7 @@ jobs:
3636

3737
- name: Install Composer dependencies & cache dependencies
3838
if: steps.check_composer_file.outputs.files_exists == 'true'
39-
uses: ramsey/composer-install@a35c6ebd3d08125aaf8852dff361e686a1a67947 # v3
39+
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # v3
4040
env:
4141
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
4242
with:

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ wp plugin uninstall [<plugin>...] [--deactivate] [--skip-delete] [--all] [--excl
858858
Updates one or more plugins.
859859

860860
~~~
861-
wp plugin update [<plugin>...] [--all] [--exclude=<name>] [--minor] [--patch] [--format=<format>] [--version=<version>] [--dry-run] [--insecure] [--auto-update-indicated]
861+
wp plugin update [<plugin>...] [--all] [--exclude=<name>] [--minor] [--patch] [--format=<format>] [--version=<version>] [--dry-run] [--insecure] [--auto-update-indicated] [--include-vcs]
862862
~~~
863863

864864
**Alias:** `upgrade`
@@ -903,6 +903,9 @@ wp plugin update [<plugin>...] [--all] [--exclude=<name>] [--minor] [--patch] [-
903903
[--auto-update-indicated]
904904
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`.
905905

906+
[--include-vcs]
907+
Include plugins that are version-controlled with a VCS (e.g. git, svn, hg). Skipped by default.
908+
906909
**EXAMPLES**
907910

908911
$ wp plugin update bbpress --version=dev
@@ -1813,7 +1816,7 @@ Lists the available theme updates. Similar to `wp core check-update`.
18131816
Updates one or more themes.
18141817

18151818
~~~
1816-
wp theme update [<theme>...] [--all] [--exclude=<theme-names>] [--minor] [--patch] [--format=<format>] [--version=<version>] [--dry-run] [--insecure] [--auto-update-indicated]
1819+
wp theme update [<theme>...] [--all] [--exclude=<theme-names>] [--minor] [--patch] [--format=<format>] [--version=<version>] [--dry-run] [--insecure] [--auto-update-indicated] [--include-vcs]
18171820
~~~
18181821

18191822
**Alias:** `upgrade`
@@ -1858,6 +1861,9 @@ wp theme update [<theme>...] [--all] [--exclude=<theme-names>] [--minor] [--patc
18581861
[--auto-update-indicated]
18591862
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`.
18601863

1864+
[--include-vcs]
1865+
Include themes that are version-controlled with a VCS (e.g. git, svn, hg). Skipped by default.
1866+
18611867
**EXAMPLES**
18621868

18631869
# Update multiple themes

features/plugin-update.feature

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,36 @@ Feature: Update WordPress plugins
377377
"""
378378
Success: Updated 2 of 2 plugins.
379379
"""
380+
381+
@require-wp-5.2
382+
Scenario: Skip plugin update when plugin directory is a VCS checkout
383+
Given a WP install
384+
And I run `wp plugin install wordpress-importer --version=0.5 --force`
385+
And I run `wp plugin path wordpress-importer --dir`
386+
And save STDOUT as {PLUGIN_DIR}
387+
388+
When I run `mkdir {PLUGIN_DIR}/.git`
389+
And I try `wp plugin update wordpress-importer`
390+
Then STDERR should contain:
391+
"""
392+
Warning: wordpress-importer: Skipped update because a VCS checkout was detected. Use --include-vcs to override.
393+
"""
394+
And STDERR should contain:
395+
"""
396+
Error: No plugins updated.
397+
"""
398+
And the return code should be 1
399+
400+
@require-wp-5.2
401+
Scenario: Update plugin in VCS checkout when --include-vcs is set
402+
Given a WP install
403+
And I run `wp plugin install wordpress-importer --version=0.5 --force`
404+
And I run `wp plugin path wordpress-importer --dir`
405+
And save STDOUT as {PLUGIN_DIR}
406+
407+
When I run `mkdir {PLUGIN_DIR}/.git`
408+
And I run `wp plugin update wordpress-importer --include-vcs`
409+
Then STDOUT should contain:
410+
"""
411+
Success: Updated 1 of 1 plugins.
412+
"""

features/theme-update.feature

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,34 @@ Feature: Update WordPress themes
257257
"""
258258
Success: Updated 2 of 2 themes.
259259
"""
260+
261+
Scenario: Skip theme update when theme directory is a VCS checkout
262+
Given a WP install
263+
And I run `wp theme install twentytwelve --version=3.0 --force`
264+
And I run `wp theme path twentytwelve --dir`
265+
And save STDOUT as {THEME_DIR}
266+
267+
When I run `mkdir {THEME_DIR}/.git`
268+
And I try `wp theme update twentytwelve`
269+
Then STDERR should contain:
270+
"""
271+
Warning: twentytwelve: Skipped update because a VCS checkout was detected. Use --include-vcs to override.
272+
"""
273+
And STDERR should contain:
274+
"""
275+
Error: No themes updated.
276+
"""
277+
And the return code should be 1
278+
279+
Scenario: Update theme in VCS checkout when --include-vcs is set
280+
Given a WP install
281+
And I run `wp theme install twentytwelve --version=3.0 --force`
282+
And I run `wp theme path twentytwelve --dir`
283+
And save STDOUT as {THEME_DIR}
284+
285+
When I run `mkdir {THEME_DIR}/.git`
286+
And I run `wp theme update twentytwelve --include-vcs`
287+
Then STDOUT should contain:
288+
"""
289+
Success: Updated 1 of 1 themes.
290+
"""

src/Plugin_AutoUpdates_Command.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ public function disable( $args, $assoc_args ) {
169169
$auto_updates = [];
170170
}
171171

172+
/** @var array<string> $auto_updates */
173+
172174
$count = 0;
173175
$successes = 0;
174176

src/Plugin_Command.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,9 @@ protected function install_from_repo( $slug, $assoc_args ) {
840840
* [--auto-update-indicated]
841841
* : 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`.
842842
*
843+
* [--include-vcs]
844+
* : Include plugins that are version-controlled with a VCS (e.g. git, svn, hg). Skipped by default.
845+
*
843846
* ## EXAMPLES
844847
*
845848
* $ wp plugin update bbpress --version=dev

src/Theme_AutoUpdates_Command.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ public function disable( $args, $assoc_args ) {
169169
$auto_updates = [];
170170
}
171171

172+
/** @var array<string> $auto_updates */
173+
172174
$count = 0;
173175
$successes = 0;
174176

src/Theme_Command.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,9 @@ public function get( $args, $assoc_args ) {
792792
* [--auto-update-indicated]
793793
* : 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`.
794794
*
795+
* [--include-vcs]
796+
* : Include themes that are version-controlled with a VCS (e.g. git, svn, hg). Skipped by default.
797+
*
795798
* ## EXAMPLES
796799
*
797800
* # Update multiple themes

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,30 @@ function ( $item ) {
744744
}
745745
}
746746

747+
// Skip VCS-controlled items unless --include-vcs is set.
748+
if ( ! Utils\get_flag_value( $assoc_args, 'include-vcs', false ) && in_array( $this->item_type, [ 'plugin', 'theme' ], true ) ) {
749+
if ( ! class_exists( 'WP_Automatic_Updater' ) ) {
750+
if ( file_exists( ABSPATH . 'wp-admin/includes/class-wp-automatic-updater.php' ) ) {
751+
require_once ABSPATH . 'wp-admin/includes/class-wp-automatic-updater.php';
752+
} else {
753+
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
754+
}
755+
}
756+
$automatic_updater = new \WP_Automatic_Updater();
757+
foreach ( $items_to_update as $item_key => $item_info ) {
758+
if ( 'plugin' === $this->item_type ) {
759+
$item_dir = WP_PLUGIN_DIR . '/' . dirname( $item_key );
760+
} else {
761+
$item_dir = get_theme_root( $item_key ) . '/' . $item_key;
762+
}
763+
if ( $automatic_updater->is_vcs_checkout( $item_dir ) ) {
764+
WP_CLI::warning( "{$item_info['name']}: Skipped update because a VCS checkout was detected. Use --include-vcs to override." );
765+
++$skipped;
766+
unset( $items_to_update[ $item_key ] );
767+
}
768+
}
769+
}
770+
747771
if ( Utils\get_flag_value( $assoc_args, 'dry-run' ) ) {
748772
if ( empty( $items_to_update ) ) {
749773
WP_CLI::log( "No {$this->item_type} updates available." );

0 commit comments

Comments
 (0)