From e86545014cc585b722db2b127037bf1582b0fc96 Mon Sep 17 00:00:00 2001
From: Daniel Paoliello
Date: Tue, 27 Aug 2024 15:11:19 -0700
Subject: [PATCH 1/2] Fix lookup_path_base to take workspace_root as &Path
instead of &PathBuf
---
src/cargo/util/toml/mod.rs | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs
index 44b3b6812c8..a086319d181 100644
--- a/src/cargo/util/toml/mod.rs
+++ b/src/cargo/util/toml/mod.rs
@@ -312,7 +312,7 @@ fn normalize_toml(
inherit_cell
.try_borrow_with(|| load_inheritable_fields(gctx, manifest_file, &workspace_config))
};
- let workspace_root = || inherit().map(|fields| fields.ws_root());
+ let workspace_root = || inherit().map(|fields| fields.ws_root().as_path());
if let Some(original_package) = original_toml.package() {
let package_name = &original_package.name;
@@ -538,7 +538,7 @@ fn normalize_toml(
fn normalize_patch<'a>(
gctx: &GlobalContext,
original_patch: Option<&BTreeMap>>,
- workspace_root: &dyn Fn() -> CargoResult<&'a PathBuf>,
+ workspace_root: &dyn Fn() -> CargoResult<&'a Path>,
features: &Features,
) -> CargoResult
+Unstable (nightly-only)
+
+
--registry
registry
Name of the registry to use. Registry names are defined in Cargo config
files. If not specified, the default registry is used,
diff --git a/src/etc/man/cargo-add.1 b/src/etc/man/cargo-add.1
index b89508b3f09..a7b2d1a110d 100644
--- a/src/etc/man/cargo-add.1
+++ b/src/etc/man/cargo-add.1
@@ -74,6 +74,13 @@ Specific commit to use when adding from git.
\fIFilesystem path\fR to local crate to add.
.RE
.sp
+\fB\-\-base\fR \fIbase\fR
+.RS 4
+The \fIpath base\fR to use when adding a local crate.
+.sp
+\fIUnstable (nightly\-only)\fR
+.RE
+.sp
\fB\-\-registry\fR \fIregistry\fR
.RS 4
Name of the registry to use. Registry names are defined in \fICargo config
diff --git a/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/in/.cargo/config.toml b/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/in/.cargo/config.toml
new file mode 100644
index 00000000000..fa0f7bb4d2b
--- /dev/null
+++ b/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/in/.cargo/config.toml
@@ -0,0 +1,2 @@
+[path-bases]
+my_base = "deps"
diff --git a/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/in/Cargo.toml b/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/in/Cargo.toml
new file mode 100644
index 00000000000..32f9a4ec1cd
--- /dev/null
+++ b/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/in/Cargo.toml
@@ -0,0 +1,7 @@
+cargo-features = ["path-bases"]
+
+[workspace]
+members = ["primary", "deps/dependency"]
+
+[workspace.dependencies]
+foo = { version = "0.0.0", base = "my_base", path = "./dependency"}
\ No newline at end of file
diff --git a/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/in/deps/dependency/Cargo.toml b/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/in/deps/dependency/Cargo.toml
new file mode 100644
index 00000000000..0de6f9b15a8
--- /dev/null
+++ b/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/in/deps/dependency/Cargo.toml
@@ -0,0 +1,4 @@
+[package]
+name = "foo"
+version = "0.0.0"
+edition = "2015"
diff --git a/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/in/deps/dependency/src/lib.rs b/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/in/deps/dependency/src/lib.rs
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/in/primary/Cargo.toml b/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/in/primary/Cargo.toml
new file mode 100644
index 00000000000..737232cece6
--- /dev/null
+++ b/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/in/primary/Cargo.toml
@@ -0,0 +1,6 @@
+cargo-features = ["path-bases"]
+
+[package]
+name = "bar"
+version = "0.0.0"
+edition = "2015"
diff --git a/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/in/primary/src/lib.rs b/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/in/primary/src/lib.rs
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/mod.rs b/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/mod.rs
new file mode 100644
index 00000000000..95ecd0d6500
--- /dev/null
+++ b/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/mod.rs
@@ -0,0 +1,27 @@
+use cargo_test_support::compare::assert_ui;
+use cargo_test_support::current_dir;
+use cargo_test_support::file;
+use cargo_test_support::prelude::*;
+use cargo_test_support::str;
+use cargo_test_support::Project;
+
+#[cargo_test]
+fn case() {
+ cargo_test_support::registry::init();
+
+ let project = Project::from_template(current_dir!().join("in"));
+ let project_root = project.root();
+ let cwd = &project_root;
+
+ snapbox::cmd::Command::cargo_ui()
+ .arg("add")
+ .args(["foo", "-p", "bar"])
+ .current_dir(cwd)
+ .masquerade_as_nightly_cargo(&["path-base"])
+ .assert()
+ .success()
+ .stdout_eq(str![""])
+ .stderr_eq(file!["stderr.term.svg"]);
+
+ assert_ui().subset_matches(current_dir!().join("out"), &project_root);
+}
diff --git a/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/out/Cargo.toml b/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/out/Cargo.toml
new file mode 100644
index 00000000000..32f9a4ec1cd
--- /dev/null
+++ b/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/out/Cargo.toml
@@ -0,0 +1,7 @@
+cargo-features = ["path-bases"]
+
+[workspace]
+members = ["primary", "deps/dependency"]
+
+[workspace.dependencies]
+foo = { version = "0.0.0", base = "my_base", path = "./dependency"}
\ No newline at end of file
diff --git a/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/out/deps/dependency/Cargo.toml b/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/out/deps/dependency/Cargo.toml
new file mode 100644
index 00000000000..0de6f9b15a8
--- /dev/null
+++ b/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/out/deps/dependency/Cargo.toml
@@ -0,0 +1,4 @@
+[package]
+name = "foo"
+version = "0.0.0"
+edition = "2015"
diff --git a/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/out/primary/Cargo.toml b/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/out/primary/Cargo.toml
new file mode 100644
index 00000000000..67ed3895785
--- /dev/null
+++ b/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/out/primary/Cargo.toml
@@ -0,0 +1,9 @@
+cargo-features = ["path-bases"]
+
+[package]
+name = "bar"
+version = "0.0.0"
+edition = "2015"
+
+[dependencies]
+foo.workspace = true
diff --git a/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/stderr.term.svg b/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/stderr.term.svg
new file mode 100644
index 00000000000..890a67bc986
--- /dev/null
+++ b/tests/testsuite/cargo_add/detect_workspace_inherit_path_base/stderr.term.svg
@@ -0,0 +1,27 @@
+
diff --git a/tests/testsuite/cargo_add/dev_existing_path_base/in/.cargo/config.toml b/tests/testsuite/cargo_add/dev_existing_path_base/in/.cargo/config.toml
new file mode 100644
index 00000000000..4539a438423
--- /dev/null
+++ b/tests/testsuite/cargo_add/dev_existing_path_base/in/.cargo/config.toml
@@ -0,0 +1,2 @@
+[path-bases]
+my_base = "."
diff --git a/tests/testsuite/cargo_add/dev_existing_path_base/in/dependency/Cargo.toml b/tests/testsuite/cargo_add/dev_existing_path_base/in/dependency/Cargo.toml
new file mode 100644
index 00000000000..c645a3371c0
--- /dev/null
+++ b/tests/testsuite/cargo_add/dev_existing_path_base/in/dependency/Cargo.toml
@@ -0,0 +1,6 @@
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture-dependency"
+version = "0.0.0"
+edition = "2015"
diff --git a/tests/testsuite/cargo_add/dev_existing_path_base/in/dependency/src/lib.rs b/tests/testsuite/cargo_add/dev_existing_path_base/in/dependency/src/lib.rs
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/tests/testsuite/cargo_add/dev_existing_path_base/in/primary/Cargo.toml b/tests/testsuite/cargo_add/dev_existing_path_base/in/primary/Cargo.toml
new file mode 100644
index 00000000000..ecba72b5df6
--- /dev/null
+++ b/tests/testsuite/cargo_add/dev_existing_path_base/in/primary/Cargo.toml
@@ -0,0 +1,11 @@
+cargo-features = ["path-bases"]
+
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+edition = "2015"
+
+[dependencies]
+cargo-list-test-fixture-dependency = { version = "0.0.0", base = "my_base", path = "dependency" }
diff --git a/tests/testsuite/cargo_add/dev_existing_path_base/in/primary/src/lib.rs b/tests/testsuite/cargo_add/dev_existing_path_base/in/primary/src/lib.rs
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/tests/testsuite/cargo_add/dev_existing_path_base/mod.rs b/tests/testsuite/cargo_add/dev_existing_path_base/mod.rs
new file mode 100644
index 00000000000..be1a8550392
--- /dev/null
+++ b/tests/testsuite/cargo_add/dev_existing_path_base/mod.rs
@@ -0,0 +1,25 @@
+use cargo_test_support::compare::assert_ui;
+use cargo_test_support::current_dir;
+use cargo_test_support::file;
+use cargo_test_support::prelude::*;
+use cargo_test_support::str;
+use cargo_test_support::Project;
+
+#[cargo_test]
+fn case() {
+ let project = Project::from_template(current_dir!().join("in"));
+ let project_root = project.root();
+ let cwd = project_root.join("primary");
+
+ snapbox::cmd::Command::cargo_ui()
+ .arg("add")
+ .arg_line("cargo-list-test-fixture-dependency --dev")
+ .current_dir(&cwd)
+ .masquerade_as_nightly_cargo(&["path-base"])
+ .assert()
+ .success()
+ .stdout_eq(str![""])
+ .stderr_eq(file!["stderr.term.svg"]);
+
+ assert_ui().subset_matches(current_dir!().join("out"), &project_root);
+}
diff --git a/tests/testsuite/cargo_add/dev_existing_path_base/out/dependency/Cargo.toml b/tests/testsuite/cargo_add/dev_existing_path_base/out/dependency/Cargo.toml
new file mode 100644
index 00000000000..c645a3371c0
--- /dev/null
+++ b/tests/testsuite/cargo_add/dev_existing_path_base/out/dependency/Cargo.toml
@@ -0,0 +1,6 @@
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture-dependency"
+version = "0.0.0"
+edition = "2015"
diff --git a/tests/testsuite/cargo_add/dev_existing_path_base/out/primary/Cargo.toml b/tests/testsuite/cargo_add/dev_existing_path_base/out/primary/Cargo.toml
new file mode 100644
index 00000000000..6f036f2f6b9
--- /dev/null
+++ b/tests/testsuite/cargo_add/dev_existing_path_base/out/primary/Cargo.toml
@@ -0,0 +1,14 @@
+cargo-features = ["path-bases"]
+
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+edition = "2015"
+
+[dependencies]
+cargo-list-test-fixture-dependency = { version = "0.0.0", base = "my_base", path = "dependency" }
+
+[dev-dependencies]
+cargo-list-test-fixture-dependency = { base = "my_base", path = "dependency" }
diff --git a/tests/testsuite/cargo_add/dev_existing_path_base/stderr.term.svg b/tests/testsuite/cargo_add/dev_existing_path_base/stderr.term.svg
new file mode 100644
index 00000000000..c4a8bc01449
--- /dev/null
+++ b/tests/testsuite/cargo_add/dev_existing_path_base/stderr.term.svg
@@ -0,0 +1,29 @@
+
diff --git a/tests/testsuite/cargo_add/help/stdout.term.svg b/tests/testsuite/cargo_add/help/stdout.term.svg
index 9335d606113..cee4d65c49f 100644
--- a/tests/testsuite/cargo_add/help/stdout.term.svg
+++ b/tests/testsuite/cargo_add/help/stdout.term.svg
@@ -219,83 +219,89 @@
- --git <URI>
+ --base <BASE>
- Git repository location
+ The path base to use when adding from a local crate (unstable).
-
+
- Without any other information, cargo will use latest commit on the main branch.
+ --git <URI>
-
+ Git repository location
- --branch <BRANCH>
+
- Git branch to download the crate from
+ Without any other information, cargo will use latest commit on the main branch.
- --tag <TAG>
+ --branch <BRANCH>
- Git tag to download the crate from
+ Git branch to download the crate from
- --rev <REV>
+ --tag <TAG>
- Git reference to download the crate from
+ Git tag to download the crate from
-
+
- This is the catch all, handling hashes to named references in remote repositories.
+ --rev <REV>
-
+ Git reference to download the crate from
- --registry <NAME>
+
- Package registry for this dependency
+ This is the catch all, handling hashes to named references in remote repositories.
- Section:
+ --registry <NAME>
- --dev
+ Package registry for this dependency
- Add as development dependency
+
-
+ Section:
- Dev-dependencies are not used when compiling a package for building, but are used for
+ --dev
- compiling tests, examples, and benchmarks.
+ Add as development dependency
- These dependencies are not propagated to other packages which depend on this package.
+ Dev-dependencies are not used when compiling a package for building, but are used for
-
+ compiling tests, examples, and benchmarks.
- --build
+
- Add as build dependency
+ These dependencies are not propagated to other packages which depend on this package.
-
+
- Build-dependencies are the only dependencies available for use by build scripts
+ --build
- (`build.rs` files).
+ Add as build dependency
-
+
- --target <TARGET>
+ Build-dependencies are the only dependencies available for use by build scripts
- Add as dependency to the given target platform
+ (`build.rs` files).
- Run `cargo help add` for more detailed information.
+ --target <TARGET>
-
+ Add as dependency to the given target platform
+
+
+
+ Run `cargo help add` for more detailed information.
+
+
diff --git a/tests/testsuite/cargo_add/mod.rs b/tests/testsuite/cargo_add/mod.rs
index 8207d5fd387..ff910628ee8 100644
--- a/tests/testsuite/cargo_add/mod.rs
+++ b/tests/testsuite/cargo_add/mod.rs
@@ -16,9 +16,11 @@ mod detect_workspace_inherit;
mod detect_workspace_inherit_features;
mod detect_workspace_inherit_fuzzy;
mod detect_workspace_inherit_optional;
+mod detect_workspace_inherit_path_base;
mod detect_workspace_inherit_public;
mod dev;
mod dev_build_conflict;
+mod dev_existing_path_base;
mod dev_prefer_existing_version;
mod dry_run;
mod empty_dep_name;
@@ -94,6 +96,7 @@ mod overwrite_no_public_with_public;
mod overwrite_optional;
mod overwrite_optional_with_no_optional;
mod overwrite_optional_with_optional;
+mod overwrite_path_base_with_version;
mod overwrite_path_noop;
mod overwrite_path_with_version;
mod overwrite_preserves_inline_table;
@@ -108,6 +111,10 @@ mod overwrite_with_rename;
mod overwrite_workspace_dep;
mod overwrite_workspace_dep_features;
mod path;
+mod path_base;
+mod path_base_inferred_name;
+mod path_base_missing_base_path;
+mod path_base_unstable;
mod path_dev;
mod path_inferred_name;
mod path_inferred_name_conflicts_full_feature;
diff --git a/tests/testsuite/cargo_add/overwrite_path_base_with_version/in/.cargo/config.toml b/tests/testsuite/cargo_add/overwrite_path_base_with_version/in/.cargo/config.toml
new file mode 100644
index 00000000000..4539a438423
--- /dev/null
+++ b/tests/testsuite/cargo_add/overwrite_path_base_with_version/in/.cargo/config.toml
@@ -0,0 +1,2 @@
+[path-bases]
+my_base = "."
diff --git a/tests/testsuite/cargo_add/overwrite_path_base_with_version/in/dependency/Cargo.toml b/tests/testsuite/cargo_add/overwrite_path_base_with_version/in/dependency/Cargo.toml
new file mode 100644
index 00000000000..c645a3371c0
--- /dev/null
+++ b/tests/testsuite/cargo_add/overwrite_path_base_with_version/in/dependency/Cargo.toml
@@ -0,0 +1,6 @@
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture-dependency"
+version = "0.0.0"
+edition = "2015"
diff --git a/tests/testsuite/cargo_add/overwrite_path_base_with_version/in/dependency/src/lib.rs b/tests/testsuite/cargo_add/overwrite_path_base_with_version/in/dependency/src/lib.rs
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/tests/testsuite/cargo_add/overwrite_path_base_with_version/in/primary/Cargo.toml b/tests/testsuite/cargo_add/overwrite_path_base_with_version/in/primary/Cargo.toml
new file mode 100644
index 00000000000..9d01c094369
--- /dev/null
+++ b/tests/testsuite/cargo_add/overwrite_path_base_with_version/in/primary/Cargo.toml
@@ -0,0 +1,11 @@
+cargo-features = ["path-bases"]
+
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+edition = "2015"
+
+[dependencies]
+cargo-list-test-fixture-dependency = { optional = true, path = "dependency", base = "my_base" }
diff --git a/tests/testsuite/cargo_add/overwrite_path_base_with_version/in/primary/src/lib.rs b/tests/testsuite/cargo_add/overwrite_path_base_with_version/in/primary/src/lib.rs
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/tests/testsuite/cargo_add/overwrite_path_base_with_version/mod.rs b/tests/testsuite/cargo_add/overwrite_path_base_with_version/mod.rs
new file mode 100644
index 00000000000..ade44c07b48
--- /dev/null
+++ b/tests/testsuite/cargo_add/overwrite_path_base_with_version/mod.rs
@@ -0,0 +1,29 @@
+use cargo_test_support::compare::assert_ui;
+use cargo_test_support::current_dir;
+use cargo_test_support::file;
+use cargo_test_support::prelude::*;
+use cargo_test_support::str;
+use cargo_test_support::Project;
+
+#[cargo_test]
+fn case() {
+ cargo_test_support::registry::init();
+ cargo_test_support::registry::Package::new("cargo-list-test-fixture-dependency", "20.0.0")
+ .publish();
+
+ let project = Project::from_template(current_dir!().join("in"));
+ let project_root = project.root();
+ let cwd = project_root.join("primary");
+
+ snapbox::cmd::Command::cargo_ui()
+ .arg("add")
+ .arg_line("cargo-list-test-fixture-dependency@20.0")
+ .current_dir(&cwd)
+ .masquerade_as_nightly_cargo(&["path-base"])
+ .assert()
+ .success()
+ .stdout_eq(str![""])
+ .stderr_eq(file!["stderr.term.svg"]);
+
+ assert_ui().subset_matches(current_dir!().join("out"), &project_root);
+}
diff --git a/tests/testsuite/cargo_add/overwrite_path_base_with_version/out/dependency/Cargo.toml b/tests/testsuite/cargo_add/overwrite_path_base_with_version/out/dependency/Cargo.toml
new file mode 100644
index 00000000000..c645a3371c0
--- /dev/null
+++ b/tests/testsuite/cargo_add/overwrite_path_base_with_version/out/dependency/Cargo.toml
@@ -0,0 +1,6 @@
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture-dependency"
+version = "0.0.0"
+edition = "2015"
diff --git a/tests/testsuite/cargo_add/overwrite_path_base_with_version/out/primary/Cargo.toml b/tests/testsuite/cargo_add/overwrite_path_base_with_version/out/primary/Cargo.toml
new file mode 100644
index 00000000000..ead3ec39232
--- /dev/null
+++ b/tests/testsuite/cargo_add/overwrite_path_base_with_version/out/primary/Cargo.toml
@@ -0,0 +1,14 @@
+cargo-features = ["path-bases"]
+
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+edition = "2015"
+
+[dependencies]
+cargo-list-test-fixture-dependency = { optional = true, version = "20.0" }
+
+[features]
+cargo-list-test-fixture-dependency = ["dep:cargo-list-test-fixture-dependency"]
diff --git a/tests/testsuite/cargo_add/overwrite_path_base_with_version/stderr.term.svg b/tests/testsuite/cargo_add/overwrite_path_base_with_version/stderr.term.svg
new file mode 100644
index 00000000000..ea8afda68de
--- /dev/null
+++ b/tests/testsuite/cargo_add/overwrite_path_base_with_version/stderr.term.svg
@@ -0,0 +1,35 @@
+
diff --git a/tests/testsuite/cargo_add/path_base/in/.cargo/config.toml b/tests/testsuite/cargo_add/path_base/in/.cargo/config.toml
new file mode 100644
index 00000000000..4539a438423
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base/in/.cargo/config.toml
@@ -0,0 +1,2 @@
+[path-bases]
+my_base = "."
diff --git a/tests/testsuite/cargo_add/path_base/in/dependency/Cargo.toml b/tests/testsuite/cargo_add/path_base/in/dependency/Cargo.toml
new file mode 100644
index 00000000000..c645a3371c0
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base/in/dependency/Cargo.toml
@@ -0,0 +1,6 @@
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture-dependency"
+version = "0.0.0"
+edition = "2015"
diff --git a/tests/testsuite/cargo_add/path_base/in/dependency/src/lib.rs b/tests/testsuite/cargo_add/path_base/in/dependency/src/lib.rs
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/tests/testsuite/cargo_add/path_base/in/primary/Cargo.toml b/tests/testsuite/cargo_add/path_base/in/primary/Cargo.toml
new file mode 100644
index 00000000000..420ef1eb8f7
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base/in/primary/Cargo.toml
@@ -0,0 +1,8 @@
+cargo-features = ["path-bases"]
+
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+edition = "2015"
diff --git a/tests/testsuite/cargo_add/path_base/in/primary/src/lib.rs b/tests/testsuite/cargo_add/path_base/in/primary/src/lib.rs
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/tests/testsuite/cargo_add/path_base/mod.rs b/tests/testsuite/cargo_add/path_base/mod.rs
new file mode 100644
index 00000000000..326a76283bc
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base/mod.rs
@@ -0,0 +1,25 @@
+use cargo_test_support::compare::assert_ui;
+use cargo_test_support::current_dir;
+use cargo_test_support::file;
+use cargo_test_support::prelude::*;
+use cargo_test_support::str;
+use cargo_test_support::Project;
+
+#[cargo_test]
+fn case() {
+ let project = Project::from_template(current_dir!().join("in"));
+ let project_root = project.root();
+ let cwd = project_root.join("primary");
+
+ snapbox::cmd::Command::cargo_ui()
+ .arg("add")
+ .arg_line("cargo-list-test-fixture-dependency --path ../dependency --base my_base")
+ .current_dir(&cwd)
+ .masquerade_as_nightly_cargo(&["path-base"])
+ .assert()
+ .success()
+ .stdout_eq(str![""])
+ .stderr_eq(file!["stderr.term.svg"]);
+
+ assert_ui().subset_matches(current_dir!().join("out"), &project_root);
+}
diff --git a/tests/testsuite/cargo_add/path_base/out/dependency/Cargo.toml b/tests/testsuite/cargo_add/path_base/out/dependency/Cargo.toml
new file mode 100644
index 00000000000..c645a3371c0
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base/out/dependency/Cargo.toml
@@ -0,0 +1,6 @@
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture-dependency"
+version = "0.0.0"
+edition = "2015"
diff --git a/tests/testsuite/cargo_add/path_base/out/primary/Cargo.toml b/tests/testsuite/cargo_add/path_base/out/primary/Cargo.toml
new file mode 100644
index 00000000000..ecba72b5df6
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base/out/primary/Cargo.toml
@@ -0,0 +1,11 @@
+cargo-features = ["path-bases"]
+
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+edition = "2015"
+
+[dependencies]
+cargo-list-test-fixture-dependency = { version = "0.0.0", base = "my_base", path = "dependency" }
diff --git a/tests/testsuite/cargo_add/path_base/stderr.term.svg b/tests/testsuite/cargo_add/path_base/stderr.term.svg
new file mode 100644
index 00000000000..6781757da4a
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base/stderr.term.svg
@@ -0,0 +1,29 @@
+
diff --git a/tests/testsuite/cargo_add/path_base_inferred_name/in/.cargo/config.toml b/tests/testsuite/cargo_add/path_base_inferred_name/in/.cargo/config.toml
new file mode 100644
index 00000000000..4539a438423
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base_inferred_name/in/.cargo/config.toml
@@ -0,0 +1,2 @@
+[path-bases]
+my_base = "."
diff --git a/tests/testsuite/cargo_add/path_base_inferred_name/in/dependency/Cargo.toml b/tests/testsuite/cargo_add/path_base_inferred_name/in/dependency/Cargo.toml
new file mode 100644
index 00000000000..c645a3371c0
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base_inferred_name/in/dependency/Cargo.toml
@@ -0,0 +1,6 @@
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture-dependency"
+version = "0.0.0"
+edition = "2015"
diff --git a/tests/testsuite/cargo_add/path_base_inferred_name/in/dependency/src/lib.rs b/tests/testsuite/cargo_add/path_base_inferred_name/in/dependency/src/lib.rs
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/tests/testsuite/cargo_add/path_base_inferred_name/in/primary/Cargo.toml b/tests/testsuite/cargo_add/path_base_inferred_name/in/primary/Cargo.toml
new file mode 100644
index 00000000000..420ef1eb8f7
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base_inferred_name/in/primary/Cargo.toml
@@ -0,0 +1,8 @@
+cargo-features = ["path-bases"]
+
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+edition = "2015"
diff --git a/tests/testsuite/cargo_add/path_base_inferred_name/in/primary/src/lib.rs b/tests/testsuite/cargo_add/path_base_inferred_name/in/primary/src/lib.rs
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/tests/testsuite/cargo_add/path_base_inferred_name/mod.rs b/tests/testsuite/cargo_add/path_base_inferred_name/mod.rs
new file mode 100644
index 00000000000..005a9d75330
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base_inferred_name/mod.rs
@@ -0,0 +1,25 @@
+use cargo_test_support::compare::assert_ui;
+use cargo_test_support::current_dir;
+use cargo_test_support::file;
+use cargo_test_support::prelude::*;
+use cargo_test_support::str;
+use cargo_test_support::Project;
+
+#[cargo_test]
+fn case() {
+ let project = Project::from_template(current_dir!().join("in"));
+ let project_root = project.root();
+ let cwd = project_root.join("primary");
+
+ snapbox::cmd::Command::cargo_ui()
+ .arg("add")
+ .arg_line("--path ../dependency --base my_base")
+ .current_dir(&cwd)
+ .masquerade_as_nightly_cargo(&["path-base"])
+ .assert()
+ .success()
+ .stdout_eq(str![""])
+ .stderr_eq(file!["stderr.term.svg"]);
+
+ assert_ui().subset_matches(current_dir!().join("out"), &project_root);
+}
diff --git a/tests/testsuite/cargo_add/path_base_inferred_name/out/dependency/Cargo.toml b/tests/testsuite/cargo_add/path_base_inferred_name/out/dependency/Cargo.toml
new file mode 100644
index 00000000000..c645a3371c0
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base_inferred_name/out/dependency/Cargo.toml
@@ -0,0 +1,6 @@
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture-dependency"
+version = "0.0.0"
+edition = "2015"
diff --git a/tests/testsuite/cargo_add/path_base_inferred_name/out/primary/Cargo.toml b/tests/testsuite/cargo_add/path_base_inferred_name/out/primary/Cargo.toml
new file mode 100644
index 00000000000..ecba72b5df6
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base_inferred_name/out/primary/Cargo.toml
@@ -0,0 +1,11 @@
+cargo-features = ["path-bases"]
+
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+edition = "2015"
+
+[dependencies]
+cargo-list-test-fixture-dependency = { version = "0.0.0", base = "my_base", path = "dependency" }
diff --git a/tests/testsuite/cargo_add/path_base_inferred_name/stderr.term.svg b/tests/testsuite/cargo_add/path_base_inferred_name/stderr.term.svg
new file mode 100644
index 00000000000..6781757da4a
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base_inferred_name/stderr.term.svg
@@ -0,0 +1,29 @@
+
diff --git a/tests/testsuite/cargo_add/path_base_missing_base_path/in/primary/Cargo.toml b/tests/testsuite/cargo_add/path_base_missing_base_path/in/primary/Cargo.toml
new file mode 100644
index 00000000000..1622ce604fd
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base_missing_base_path/in/primary/Cargo.toml
@@ -0,0 +1,6 @@
+cargo-features = ["path-bases"]
+
+[package]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+edition = "2015"
diff --git a/tests/testsuite/cargo_add/path_base_missing_base_path/in/primary/src/lib.rs b/tests/testsuite/cargo_add/path_base_missing_base_path/in/primary/src/lib.rs
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/tests/testsuite/cargo_add/path_base_missing_base_path/mod.rs b/tests/testsuite/cargo_add/path_base_missing_base_path/mod.rs
new file mode 100644
index 00000000000..dbae05ad0a4
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base_missing_base_path/mod.rs
@@ -0,0 +1,25 @@
+use cargo_test_support::compare::assert_ui;
+use cargo_test_support::current_dir;
+use cargo_test_support::file;
+use cargo_test_support::prelude::*;
+use cargo_test_support::str;
+use cargo_test_support::Project;
+
+#[cargo_test]
+fn case() {
+ let project = Project::from_template(current_dir!().join("in"));
+ let project_root = project.root();
+ let cwd = project_root.join("primary");
+
+ snapbox::cmd::Command::cargo_ui()
+ .arg("add")
+ .arg_line("--path dependency --base bad_base")
+ .current_dir(&cwd)
+ .masquerade_as_nightly_cargo(&["path-base"])
+ .assert()
+ .code(101)
+ .stdout_eq(str![""])
+ .stderr_eq(file!["stderr.term.svg"]);
+
+ assert_ui().subset_matches(current_dir!().join("out"), &project_root);
+}
diff --git a/tests/testsuite/cargo_add/path_base_missing_base_path/out/primary/Cargo.toml b/tests/testsuite/cargo_add/path_base_missing_base_path/out/primary/Cargo.toml
new file mode 100644
index 00000000000..1622ce604fd
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base_missing_base_path/out/primary/Cargo.toml
@@ -0,0 +1,6 @@
+cargo-features = ["path-bases"]
+
+[package]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+edition = "2015"
diff --git a/tests/testsuite/cargo_add/path_base_missing_base_path/stderr.term.svg b/tests/testsuite/cargo_add/path_base_missing_base_path/stderr.term.svg
new file mode 100644
index 00000000000..ebe52195f6c
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base_missing_base_path/stderr.term.svg
@@ -0,0 +1,27 @@
+
diff --git a/tests/testsuite/cargo_add/path_base_unstable/in/primary/Cargo.toml b/tests/testsuite/cargo_add/path_base_unstable/in/primary/Cargo.toml
new file mode 100644
index 00000000000..8194d1deb0e
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base_unstable/in/primary/Cargo.toml
@@ -0,0 +1,4 @@
+[package]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+edition = "2015"
diff --git a/tests/testsuite/cargo_add/path_base_unstable/in/primary/src/lib.rs b/tests/testsuite/cargo_add/path_base_unstable/in/primary/src/lib.rs
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/tests/testsuite/cargo_add/path_base_unstable/mod.rs b/tests/testsuite/cargo_add/path_base_unstable/mod.rs
new file mode 100644
index 00000000000..c55fa83a123
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base_unstable/mod.rs
@@ -0,0 +1,24 @@
+use cargo_test_support::compare::assert_ui;
+use cargo_test_support::current_dir;
+use cargo_test_support::file;
+use cargo_test_support::prelude::*;
+use cargo_test_support::str;
+use cargo_test_support::Project;
+
+#[cargo_test]
+fn case() {
+ let project = Project::from_template(current_dir!().join("in"));
+ let project_root = project.root();
+ let cwd = project_root.join("primary");
+
+ snapbox::cmd::Command::cargo_ui()
+ .arg("add")
+ .arg_line("--path dependency --base mybase")
+ .current_dir(&cwd)
+ .assert()
+ .code(101)
+ .stdout_eq(str![""])
+ .stderr_eq(file!["stderr.term.svg"]);
+
+ assert_ui().subset_matches(current_dir!().join("out"), &project_root);
+}
diff --git a/tests/testsuite/cargo_add/path_base_unstable/out/primary/Cargo.toml b/tests/testsuite/cargo_add/path_base_unstable/out/primary/Cargo.toml
new file mode 100644
index 00000000000..8194d1deb0e
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base_unstable/out/primary/Cargo.toml
@@ -0,0 +1,4 @@
+[package]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+edition = "2015"
diff --git a/tests/testsuite/cargo_add/path_base_unstable/stderr.term.svg b/tests/testsuite/cargo_add/path_base_unstable/stderr.term.svg
new file mode 100644
index 00000000000..ca60ce2b30e
--- /dev/null
+++ b/tests/testsuite/cargo_add/path_base_unstable/stderr.term.svg
@@ -0,0 +1,37 @@
+