Skip to content

Support version suffix on git URL package installs#223

Merged
swissspidy merged 2 commits intomainfrom
copilot/fix-installation-error
Mar 2, 2026
Merged

Support version suffix on git URL package installs#223
swissspidy merged 2 commits intomainfrom
copilot/fix-installation-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 2, 2026

Installing a package via a full git URL with a version suffix (e.g. https://github.com/vendor/package.git:dev-main) fails with a misleading error because is_git_repository() checks for a .git suffix and the appended version breaks that check, causing the input to fall through to the shortened-identifier path:

$ wp package install https://github.com/wp-cli/search-replace-command.git:dev-main
Error: Invalid package: shortened identifier 'https' not found.

$ wp package install github:wp-cli/search-replace-command.git:dev-main
Error: Invalid package: shortened identifier 'github' not found.

Changes

  • src/Package_Command.php — Before the is_git_repository() check, detect and split the <url>.git:<version> pattern. The extracted version bypasses the subsequent get_github_default_branch() API call since the version is already known.
// 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];
    $version      = $url_version_matches[2];
}
  • features/package-install.feature — New @github-api scenario covering HTTPS git URL with a version suffix.
Original prompt

This section details on the original issue you should resolve

<issue_title>Errors installing command into development environment</issue_title>
<issue_description>## Bug Report

Describe the current, buggy behavior

I read the contributing guidlines for installing a command, but got an error that looked like a regression of the problem described in wp-cli/wp-cli#5602.

When trying to work around it with the :dev-main suffix, wp-cli baulked at the https: scheme and the ssh alias github: (which shortens the usual git@github.com and selects the right key).

Maybe I'm just doing it wrong but it seems like odd behaviour when supplying legitimate URLs that work with Git.

Describe how other contributors can replicate this bug

Install command using wp package install ... with an HTTP or ssh alias URL. It may do the same with the explicit git@... URL.

See shell output below.

Describe what you expect as the correct outcome

Command to install as per docs, or docs are updated to new expected command.

It worked when I used wp package install wp-cli/search-replace-command:dev-main.

Let us know what environment you are running this on

OS:     Linux 6.5.0-10-generic wp-cli/wp-cli#10-Ubuntu SMP PREEMPT_DYNAMIC Fri Oct 13 13:49:38 UTC 2023 x86_64
Shell:  /bin/bash
PHP binary:     /usr/bin/php
PHP version:    8.2.10-2ubuntu1
php.ini used:   /etc/php/8.2/cli/php.ini
MySQL binary:   /usr/bin/mysql
MySQL version:  mysql  Ver 15.1 Distrib 10.11.4-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper
SQL modes:
WP-CLI root dir:        /home/roy/GitHub/wp-cli
WP-CLI vendor dir:      /home/roy/GitHub/wp-cli/vendor
WP_CLI phar path:
WP-CLI packages dir:    /home/roy/.wp-cli/packages/
WP-CLI cache dir:       /home/roy/.wp-cli/cache
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.10.0-alpha

Provide additional context/screenshots

Shell output:

roy@RoyBook ~/GitHub/wp-cli
$ bin/wp package install https://github.com/wp-cli/search-replace-command.git
Installing package wp-cli/search-replace-command (dev-main)
Updating /home/roy/.wp-cli/packages/composer.json to require the package...
Registering https://github.com/wp-cli/search-replace-command.git as a VCS repository...
Using Composer to install the package...
---
Loading composer repositories with package information
Warning: Could not authenticate against github.com
---
Error: Package installation failed.
Reverted composer.json.


roy@RoyBook ~/GitHub/wp-cli
$ bin/wp package install github:wp-cli/search-replace-command.git
Warning: Couldn't fetch default branch for package 'github:wp-cli/search-replace-command.git' (HTTP code 403). Presuming default branch is 'master'.
Installing package wp-cli/search-replace-command (dev-master)
Updating /home/roy/.wp-cli/packages/composer.json to require the package...
Registering github:wp-cli/search-replace-command.git as a VCS repository...
Using Composer to install the package...
---
Loading composer repositories with package information
Updating dependencies
Generating rules
Resolving dependencies through SAT
Looking at all rules.

Dependency resolution completed in 0.000 seconds
Your requirements could not be resolved to an installable set of packages.
Problem 1
    - Root composer.json requires wp-cli/search-replace-command dev-master, found wp-cli/search-replace-command[dev-main, dev-bump-travis-server-to-xenial, v1.0.0, v1.0.1, v1.0.2, v1.0.3, v1.0.4, v1.1.0, v1.1.1, v1.1.2, v1.1.3, v1.1.4, v1.2.0, v1.3.0, v1.3.1, v2.0.0, v2.0.1, v2.0.2, v2.0.3, v2.0.4, v2.0.5, v2.0.6, v2.0.7, v2.0.8, v2.0.9, v2.0.10, v2.0.11, v2.0.12, v2.0.13, v2.0.14, v2.0.15, v2.0.16, v2.0.17, v2.0.18, v2.0.19, v2.0.20, v2.1.0, v2.1.1, v2.1.2, v2.1.3, 2.x-dev (alias of dev-main)] but it does not match the constraint. Perhaps dev-master was renamed to dev-main?
Running update with --no-dev does not mean require-dev is ignored, it just means the packages will not be installed. If dev requirements are blocking the update you have to resolve those problems.
---
Error: Package installation failed (Composer return code 2).
Reverted composer.json.


roy@RoyBook ~/GitHub/wp-cli
$ bin/wp package install github:wp-cli/search-replace-command.git
Warning: Couldn't fetch default branch for package 'github:wp-cli/search-replace-command.git' (HTTP code 403). Presuming default branch is 'master'.
Installing package wp-cli/search-replace-command (dev-master)
Updating /home/roy/.wp-cli/packages/composer.json to require the package...
Registering github:wp-cli/search-replace-co...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes wp-cli/package-command#184

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

…endor/package.git:dev-main)

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix errors installing command in development environment Support version suffix on git URL package installs Mar 2, 2026
@swissspidy swissspidy added the command:package-install Related to 'package install' command label Mar 2, 2026
@swissspidy swissspidy added this to the 2.6.2 milestone Mar 2, 2026
@swissspidy swissspidy marked this pull request as ready for review March 2, 2026 10:40
@swissspidy swissspidy requested a review from a team as a code owner March 2, 2026 10:40
Copilot AI review requested due to automatic review settings March 2, 2026 10:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes wp package install when installing from a full git URL that includes a version suffix (e.g. ...repo.git:dev-main), ensuring the URL is still recognized as a git repository and the version is applied correctly.

Changes:

  • Parse and split the <git-url>.git:<version> pattern before is_git_repository() so .git detection works and the version is preserved.
  • Skip the GitHub default-branch API lookup when the version suffix is explicitly provided.
  • Add a Behat scenario to cover installing from an HTTPS git URL with a version suffix.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Package_Command.php Extracts :version from git URLs ending in .git before git-repo detection; avoids default-branch lookup when version is present.
features/package-install.feature Adds an acceptance scenario validating install/uninstall via https://...repo.git:dev-main.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@swissspidy swissspidy linked an issue Mar 2, 2026 that may be closed by this pull request
2 tasks
@swissspidy swissspidy merged commit 945b977 into main Mar 2, 2026
72 checks passed
@swissspidy swissspidy deleted the copilot/fix-installation-error branch March 2, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:package-install Related to 'package install' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Errors installing command into development environment

3 participants