From 378458aea4f217308358bf4ccd59b4f0af1cea99 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 6 Sep 2024 09:45:19 -0500 Subject: [PATCH] fix(new): Add to workspace relative to manifest, not current-dir We were correctly doing this for cases like `cargo new foo` or `cargo new deeper/than/this/directory/foo` but not `cargo new ../foo`. This came up when discussing #14501 --- src/cargo/ops/cargo_new.rs | 2 +- .../out/workspace/Cargo.toml | 1 - .../ignore_current_dir_workspace/stderr.term.svg | 15 +++------------ 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index df4d814fb11a..a3d08bb4db04 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -802,7 +802,7 @@ fn mk(gctx: &GlobalContext, opts: &MkOptions<'_>) -> CargoResult<()> { } } - let manifest_path = path.join("Cargo.toml"); + let manifest_path = paths::normalize_path(&path.join("Cargo.toml")); if let Ok(root_manifest_path) = find_root_manifest_for_wd(&manifest_path) { let root_manifest = paths::read(&root_manifest_path)?; // Sometimes the root manifest is not a valid manifest, so we only try to parse it if it is. diff --git a/tests/testsuite/cargo_new/ignore_current_dir_workspace/out/workspace/Cargo.toml b/tests/testsuite/cargo_new/ignore_current_dir_workspace/out/workspace/Cargo.toml index ce2c1898ce13..cd7525f40507 100644 --- a/tests/testsuite/cargo_new/ignore_current_dir_workspace/out/workspace/Cargo.toml +++ b/tests/testsuite/cargo_new/ignore_current_dir_workspace/out/workspace/Cargo.toml @@ -1,5 +1,4 @@ [workspace] -members = ["../out-of-workspace"] [package] name = "foo" diff --git a/tests/testsuite/cargo_new/ignore_current_dir_workspace/stderr.term.svg b/tests/testsuite/cargo_new/ignore_current_dir_workspace/stderr.term.svg index a7b5660b5f07..7858e42a578b 100644 --- a/tests/testsuite/cargo_new/ignore_current_dir_workspace/stderr.term.svg +++ b/tests/testsuite/cargo_new/ignore_current_dir_workspace/stderr.term.svg @@ -1,10 +1,9 @@ - +