From 6200ff81602edd80075980e6b1c7a7ebc874f341 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Mar 2026 21:30:09 +0000 Subject: [PATCH 1/9] Initial plan From b2b5569cfe62eede0cbcfdc83669c782eb2ca0b7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Mar 2026 21:36:14 +0000 Subject: [PATCH 2/9] Append .git suffix automatically for GitHub/GitLab URLs without it Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/package-install.feature | 48 ++++++++++++++++++++++++++++++++ src/Package_Command.php | 21 ++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/features/package-install.feature b/features/package-install.feature index 495d77af..12a39e6c 100644 --- a/features/package-install.feature +++ b/features/package-install.feature @@ -298,6 +298,54 @@ Feature: Install WP-CLI packages Success: Uninstalled package. """ + @github-api + Scenario: Install a package from a Git URL without .git suffix + Given an empty directory + + When I run `wp package install https://github.com/wp-cli/google-sitemap-generator-cli` + Then STDOUT should contain: + """ + Installing package wp-cli/google-sitemap-generator-cli + """ + And STDOUT should contain: + """ + Registering https://github.com/wp-cli/google-sitemap-generator-cli.git as a VCS repository... + """ + And STDOUT should contain: + """ + Success: Package installed. + """ + + When I run `wp package uninstall wp-cli/google-sitemap-generator-cli` + Then STDOUT should contain: + """ + Success: Uninstalled package. + """ + + @github-api + Scenario: Install a package from a Git URL without .git suffix but with a version suffix + Given an empty directory + + When I run `wp package install https://github.com/wp-cli/google-sitemap-generator-cli:dev-main` + Then STDOUT should contain: + """ + Installing package wp-cli/google-sitemap-generator-cli (dev-main) + """ + And STDOUT should contain: + """ + Registering https://github.com/wp-cli/google-sitemap-generator-cli.git as a VCS repository... + """ + And STDOUT should contain: + """ + Success: Package installed. + """ + + When I run `wp package uninstall wp-cli/google-sitemap-generator-cli` + Then STDOUT should contain: + """ + Success: Uninstalled package. + """ + @github-api Scenario: Install a package from a Git URL with mixed-case git name but lowercase composer.json name Given an empty directory diff --git a/src/Package_Command.php b/src/Package_Command.php index 12e784a9..7cddb8d1 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -222,6 +222,8 @@ public function install( $args, $assoc_args ) { $git_package = false; $dir_package = false; $version = ''; + // Append .git suffix for GitHub/GitLab URLs that are missing it. + $package_name = $this->maybe_add_git_suffix( $package_name ); // Parse version suffix from a git URL (e.g. https://github.com/vendor/package.git:dev-main). if ( preg_match( '#^(.+\.git):([^:]+)$#', $package_name, $url_version_matches ) ) { $package_name = $url_version_matches[1]; @@ -1296,6 +1298,25 @@ private function is_git_repository( $package ) { return '.git' === strtolower( substr( $package, -4, 4 ) ); } + /** + * Appends the .git suffix to GitHub or GitLab URLs that are missing it. + * + * @param string $package_name Package name or URL to normalize. + * @return string Normalized package name or URL. + */ + private function maybe_add_git_suffix( $package_name ) { + // Already has .git suffix (possibly followed by :version). + if ( preg_match( '#\.git(?::[^:]+)?$#i', $package_name ) ) { + return $package_name; + } + // Append .git for GitHub/GitLab HTTPS or SSH URLs, preserving any :version suffix. + // Pattern: (https?://github.com// or git@github.com:/)(:version)? + if ( preg_match( '#^((?:https?://(?:github|gitlab)\.com/|git@(?:github|gitlab)\.com:)[^/]+/[^/:]+)(:.*)?$#i', $package_name, $matches ) ) { + return $matches[1] . '.git' . ( $matches[2] ?? '' ); + } + return $package_name; + } + /** * Checks that `$package_name` matches the name in composer.json at Github.com, and return corrected value if not. * From 14d7ac3175f9bae4187e22d322d7730556ac86d2 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 3 Mar 2026 10:36:06 +0100 Subject: [PATCH 3/9] Update features/package-install.feature Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- features/package-install.feature | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/features/package-install.feature b/features/package-install.feature index 12a39e6c..8f97141e 100644 --- a/features/package-install.feature +++ b/features/package-install.feature @@ -346,6 +346,51 @@ Feature: Install WP-CLI packages Success: Uninstalled package. """ + Scenario: Install a package from a GitHub SSH URL without .git suffix + Given an empty directory + + When I run `wp package install git@github.com:wp-cli/google-sitemap-generator-cli` + Then STDOUT should contain: + """ + Installing package wp-cli/google-sitemap-generator-cli + """ + And STDOUT should contain: + """ + Registering https://github.com/wp-cli/google-sitemap-generator-cli.git as a VCS repository... + """ + And STDOUT should contain: + """ + Success: Package installed. + """ + + When I run `wp package uninstall wp-cli/google-sitemap-generator-cli` + Then STDOUT should contain: + """ + Success: Uninstalled package. + """ + + Scenario: Install a package from a GitLab URL without .git suffix and nested groups + Given an empty directory + + When I run `wp package install https://gitlab.com/example-group/sub-group/example-wp-cli-package` + Then STDOUT should contain: + """ + Installing package example-wp-cli-package + """ + And STDOUT should contain: + """ + Registering https://gitlab.com/example-group/sub-group/example-wp-cli-package.git as a VCS repository... + """ + And STDOUT should contain: + """ + Success: Package installed. + """ + + When I run `wp package uninstall example-wp-cli-package` + Then STDOUT should contain: + """ + Success: Uninstalled package. + """ @github-api Scenario: Install a package from a Git URL with mixed-case git name but lowercase composer.json name Given an empty directory From 3313b08e8054f288e0bc0b9d74066b86ca883214 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 3 Mar 2026 10:37:12 +0100 Subject: [PATCH 4/9] Update src/Package_Command.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Package_Command.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Package_Command.php b/src/Package_Command.php index 7cddb8d1..06e3a575 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -1310,8 +1310,8 @@ private function maybe_add_git_suffix( $package_name ) { return $package_name; } // Append .git for GitHub/GitLab HTTPS or SSH URLs, preserving any :version suffix. - // Pattern: (https?://github.com// or git@github.com:/)(:version)? - if ( preg_match( '#^((?:https?://(?:github|gitlab)\.com/|git@(?:github|gitlab)\.com:)[^/]+/[^/:]+)(:.*)?$#i', $package_name, $matches ) ) { + // Pattern: (https?://github.com//[...subgroups...] or git@github.com:/[...subgroups...])(:version)? + if ( preg_match( '#^((?:https?://(?:github|gitlab)\.com/|git@(?:github|gitlab)\.com:)[^/:]+(?:/[^/:]+)*)(:.*)?$#i', $package_name, $matches ) ) { return $matches[1] . '.git' . ( $matches[2] ?? '' ); } return $package_name; From cf544fc0c9de38a462d56ceb3f1a89aa5df1358b Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 3 Mar 2026 10:51:11 +0100 Subject: [PATCH 5/9] Apply suggestions from code review --- features/package-install.feature | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/features/package-install.feature b/features/package-install.feature index 8f97141e..494ec15f 100644 --- a/features/package-install.feature +++ b/features/package-install.feature @@ -372,21 +372,21 @@ Feature: Install WP-CLI packages Scenario: Install a package from a GitLab URL without .git suffix and nested groups Given an empty directory - When I run `wp package install https://gitlab.com/example-group/sub-group/example-wp-cli-package` + When I run `wp package install https://gitlab.com/wp-cli/wp-cli-test/test-command` Then STDOUT should contain: """ - Installing package example-wp-cli-package + Installing package test-command """ And STDOUT should contain: """ - Registering https://gitlab.com/example-group/sub-group/example-wp-cli-package.git as a VCS repository... + Registering https://gitlab.com/wp-cli/wp-cli-test/test-command.git as a VCS repository... """ And STDOUT should contain: """ Success: Package installed. """ - When I run `wp package uninstall example-wp-cli-package` + When I run `wp package uninstall test-command` Then STDOUT should contain: """ Success: Uninstalled package. From 5652abe7ac3e0f8ceb6363b2c8fd1d32b0261a9a Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 3 Mar 2026 11:09:51 +0100 Subject: [PATCH 6/9] Update features/package-install.feature --- features/package-install.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/package-install.feature b/features/package-install.feature index 494ec15f..512632f5 100644 --- a/features/package-install.feature +++ b/features/package-install.feature @@ -356,7 +356,7 @@ Feature: Install WP-CLI packages """ And STDOUT should contain: """ - Registering https://github.com/wp-cli/google-sitemap-generator-cli.git as a VCS repository... + Registering git@github.com:wp-cli/google-sitemap-generator-cli.git as a VCS repository... """ And STDOUT should contain: """ From adc0c9064dd987f4fa9578720acb21bb71b7416f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Mar 2026 10:14:07 +0000 Subject: [PATCH 7/9] Fix get_github_default_branch only called for GitHub URLs; fix SSH test expectation Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/package-install.feature | 3 +++ src/Package_Command.php | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/features/package-install.feature b/features/package-install.feature index 512632f5..3d8b6fa1 100644 --- a/features/package-install.feature +++ b/features/package-install.feature @@ -346,6 +346,7 @@ Feature: Install WP-CLI packages Success: Uninstalled package. """ + @github-api Scenario: Install a package from a GitHub SSH URL without .git suffix Given an empty directory @@ -369,6 +370,7 @@ Feature: Install WP-CLI packages Success: Uninstalled package. """ + @gitlab-api Scenario: Install a package from a GitLab URL without .git suffix and nested groups Given an empty directory @@ -391,6 +393,7 @@ Feature: Install WP-CLI packages """ Success: Uninstalled package. """ + @github-api Scenario: Install a package from a Git URL with mixed-case git name but lowercase composer.json name Given an empty directory diff --git a/src/Package_Command.php b/src/Package_Command.php index 06e3a575..8e8c04b9 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -231,7 +231,11 @@ public function install( $args, $assoc_args ) { } if ( $this->is_git_repository( $package_name ) ) { if ( '' === $version ) { - $version = "dev-{$this->get_github_default_branch( $package_name, $insecure )}"; + if ( preg_match( '#^(?:https?://github\.com/|git@github\.com:)#i', $package_name ) ) { + $version = "dev-{$this->get_github_default_branch( $package_name, $insecure )}"; + } else { + $version = 'dev-master'; + } } $git_package = $package_name; $matches = []; From 59d30d0cc889c2674d1ec2e7ff9817ec5472ab6c Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 3 Mar 2026 13:17:07 +0100 Subject: [PATCH 8/9] Apply suggestion from @swissspidy --- features/package-install.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/package-install.feature b/features/package-install.feature index 3d8b6fa1..62465c50 100644 --- a/features/package-install.feature +++ b/features/package-install.feature @@ -377,7 +377,7 @@ Feature: Install WP-CLI packages When I run `wp package install https://gitlab.com/wp-cli/wp-cli-test/test-command` Then STDOUT should contain: """ - Installing package test-command + Installing package wp-cli-test/test-command """ And STDOUT should contain: """ From 55d3e8dfad52ef9abaf1f1e49b5f2408393b354e Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 3 Mar 2026 13:26:40 +0100 Subject: [PATCH 9/9] Apply suggestion from @swissspidy --- features/package-install.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/package-install.feature b/features/package-install.feature index 62465c50..fd91d45c 100644 --- a/features/package-install.feature +++ b/features/package-install.feature @@ -388,7 +388,7 @@ Feature: Install WP-CLI packages Success: Package installed. """ - When I run `wp package uninstall test-command` + When I run `wp package uninstall wp-cli-test/test-command` Then STDOUT should contain: """ Success: Uninstalled package.