Skip to content

Commit

Permalink
cargo install: suggest --git when package name is url
Browse files Browse the repository at this point in the history
  • Loading branch information
cardoso committed Aug 28, 2023
1 parent b8df7aa commit ecf05e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/bin/cargo/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
)
.into());
}

if let Ok(url) = crate_name.into_url() {
return Err(anyhow!(
"invalid package name: `{url}`
Use `cargo install --git {url}` if you meant to install from a git repository."
)
.into());
}
}

let mut from_cwd = false;
Expand Down
12 changes: 12 additions & 0 deletions tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ fn toolchain() {
.run();
}

#[cargo_test]
fn url() {
pkg("foo", "0.0.1");
cargo_process("install https://github.com/bar/foo")
.with_status(101)
.with_stderr(
"\
[ERROR] invalid package name: `https://github.com/bar/foo`
Use `cargo install --git https://github.com/bar/foo` if you meant to install from a git repository.")
.run();
}

#[cargo_test]
fn simple_with_message_format() {
pkg("foo", "0.0.1");
Expand Down

0 comments on commit ecf05e4

Please sign in to comment.