Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo install: suggest --git when package name is url #12575

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
cardoso marked this conversation as resolved.
Show resolved Hide resolved
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