Skip to content

Commit d9daaf7

Browse files
committed
Detect incorrectly named cargo.toml for install --git
1 parent 1fc6406 commit d9daaf7

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

src/cargo/ops/cargo_read_manifest.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,19 @@ pub fn read_packages(
8888
if all_packages.is_empty() {
8989
match errors.pop() {
9090
Some(err) => Err(err),
91-
None => Err(anyhow::format_err!(
92-
"Could not find Cargo.toml in `{}`",
91+
None => {
92+
if find_project_manifest_exact(path, "cargo.toml").is_ok() {
93+
Err(anyhow::format_err!(
94+
"Could not find Cargo.toml in `{}`, but found cargo.toml please try to rename it to Cargo.toml",
9395
path.display()
94-
)),
96+
))
97+
} else {
98+
Err(anyhow::format_err!(
99+
"Could not find Cargo.toml in `{}`",
100+
path.display()
101+
))
102+
}
103+
}
95104
}
96105
} else {
97106
Ok(all_packages.into_iter().map(|(_, v)| v).collect())

tests/testsuite/install.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,53 @@ fn missing() {
244244
.run();
245245
}
246246

247+
#[cargo_test]
248+
fn pkg_missing_cargo_toml() {
249+
let p = project()
250+
.file(
251+
"Cargo1.toml",
252+
r#"
253+
[package]
254+
name = "foo"
255+
version = "0.1.0"
256+
authors = []
257+
"#,
258+
)
259+
.file("src/main.rs", "fn main() {}")
260+
.build();
261+
262+
cargo_process("install")
263+
.arg(p.root())
264+
.with_status(101)
265+
.with_stderr(
266+
"\
267+
[UPDATING] [..] index
268+
[ERROR] could not find `[..]` in registry `[..]` with version `*`
269+
",
270+
)
271+
.run();
272+
}
273+
274+
#[cargo_test]
275+
#[cfg(not(target_os = "macos"))]
276+
fn git_repository_missing_cargo_toml() {
277+
let p = git::repo(&paths::root().join("foo"))
278+
.file("cargo.toml", &basic_manifest("foo", "0.1.0"))
279+
.file("src/main.rs", "fn main() {}")
280+
.build();
281+
282+
cargo_process("install --git")
283+
.arg(p.url().to_string())
284+
.with_status(101)
285+
.with_stderr(
286+
"\
287+
[UPDATING] git repository [..]
288+
[ERROR] Could not find Cargo.toml in `[..]`, but found cargo.toml please try to rename it to Cargo.toml
289+
",
290+
)
291+
.run();
292+
}
293+
247294
#[cargo_test]
248295
fn missing_current_working_directory() {
249296
cargo_process("install .")

0 commit comments

Comments
 (0)