Skip to content

Commit 3c8c94b

Browse files
committed
Auto merge of #8137 - twe4ked:install-current-directory-error, r=alexcrichton
Improve error message when running `cargo install .` Existing error: ``` $ cargo install . Updating crates.io index error: could not find `.` in registry `https://github.com/rust-lang/crates.io-index` ``` New error: ``` $ cargo install . error: To install the binaries for the package in current working directory use `cargo install --path .`. Use `cargo build` if you want to simply build the package. ``` Existing related errors: ``` $ cargo install error: Using `cargo install` to install the binaries for the package in current working directory is no longer supported, use `cargo install --path .` instead. Use `cargo build` if you want to simply build the package. $ cargo uninstall . error: invalid package ID specification: `.` Caused by: Invalid character `.` in pkgid: `.` ```
2 parents 6a41339 + 0c14dc2 commit 3c8c94b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/cargo/ops/cargo_install.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ fn install_one(
146146
no_track: bool,
147147
is_first_install: bool,
148148
) -> CargoResult<()> {
149+
if let Some(name) = krate {
150+
if name == "." {
151+
bail!(
152+
"To install the binaries for the package in current working \
153+
directory use `cargo install --path .`. \
154+
Use `cargo build` if you want to simply build the package."
155+
)
156+
}
157+
}
149158
let pkg = if source_id.is_git() {
150159
select_pkg(
151160
GitSource::new(source_id, config)?,

tests/testsuite/install.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,20 @@ fn missing() {
151151
.run();
152152
}
153153

154+
#[cargo_test]
155+
fn missing_current_working_directory() {
156+
cargo_process("install .")
157+
.with_status(101)
158+
.with_stderr(
159+
"\
160+
error: To install the binaries for the package in current working \
161+
directory use `cargo install --path .`. Use `cargo build` if you \
162+
want to simply build the package.
163+
",
164+
)
165+
.run();
166+
}
167+
154168
#[cargo_test]
155169
fn bad_version() {
156170
pkg("foo", "0.0.1");

0 commit comments

Comments
 (0)