Skip to content

Commit ed092d1

Browse files
Copilotswissspidy
andcommitted
Support version suffix in git URL installs (e.g. https://github.com/vendor/package.git:dev-main)
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 6d731ff commit ed092d1

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

features/package-install.feature

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,30 @@ Feature: Install WP-CLI packages
274274
wp-cli/google-sitemap-generator-cli
275275
"""
276276

277+
@github-api
278+
Scenario: Install a package from a Git URL with a version suffix
279+
Given an empty directory
280+
281+
When I run `wp package install https://github.com/wp-cli/google-sitemap-generator-cli.git:dev-main`
282+
Then STDOUT should contain:
283+
"""
284+
Installing package wp-cli/google-sitemap-generator-cli (dev-main)
285+
"""
286+
And STDOUT should contain:
287+
"""
288+
Registering https://github.com/wp-cli/google-sitemap-generator-cli.git as a VCS repository...
289+
"""
290+
And STDOUT should contain:
291+
"""
292+
Success: Package installed.
293+
"""
294+
295+
When I run `wp package uninstall wp-cli/google-sitemap-generator-cli`
296+
Then STDOUT should contain:
297+
"""
298+
Success: Uninstalled package.
299+
"""
300+
277301
@github-api
278302
Scenario: Install a package from a Git URL with mixed-case git name but lowercase composer.json name
279303
Given an empty directory

src/Package_Command.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,15 @@ public function install( $args, $assoc_args ) {
222222
$git_package = false;
223223
$dir_package = false;
224224
$version = '';
225+
// Parse version suffix from a git URL (e.g. https://github.com/vendor/package.git:dev-main).
226+
if ( preg_match( '#^(.+\.git):([^:]+)$#', $package_name, $url_version_matches ) ) {
227+
$package_name = $url_version_matches[1];
228+
$version = $url_version_matches[2];
229+
}
225230
if ( $this->is_git_repository( $package_name ) ) {
226-
$version = "dev-{$this->get_github_default_branch( $package_name, $insecure )}";
231+
if ( '' === $version ) {
232+
$version = "dev-{$this->get_github_default_branch( $package_name, $insecure )}";
233+
}
227234
$git_package = $package_name;
228235
$matches = [];
229236
if ( preg_match( '#([^:\/]+\/[^\/]+)\.git#', $package_name, $matches ) ) {

0 commit comments

Comments
 (0)