Skip to content

Commit ecf05e4

Browse files
committed
cargo install: suggest --git when package name is url
1 parent b8df7aa commit ecf05e4

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/bin/cargo/commands/install.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
121121
)
122122
.into());
123123
}
124+
125+
if let Ok(url) = crate_name.into_url() {
126+
return Err(anyhow!(
127+
"invalid package name: `{url}`
128+
Use `cargo install --git {url}` if you meant to install from a git repository."
129+
)
130+
.into());
131+
}
124132
}
125133

126134
let mut from_cwd = false;

tests/testsuite/install.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ fn toolchain() {
7171
.run();
7272
}
7373

74+
#[cargo_test]
75+
fn url() {
76+
pkg("foo", "0.0.1");
77+
cargo_process("install https://github.com/bar/foo")
78+
.with_status(101)
79+
.with_stderr(
80+
"\
81+
[ERROR] invalid package name: `https://github.com/bar/foo`
82+
Use `cargo install --git https://github.com/bar/foo` if you meant to install from a git repository.")
83+
.run();
84+
}
85+
7486
#[cargo_test]
7587
fn simple_with_message_format() {
7688
pkg("foo", "0.0.1");

0 commit comments

Comments
 (0)