]> git.proxmox.com Git - cargo.git/commitdiff
fix(add): Update the lock file
authorEd Page <eopage@gmail.com>
Mon, 25 Jul 2022 15:11:50 +0000 (10:11 -0500)
committerEd Page <eopage@gmail.com>
Tue, 26 Jul 2022 19:59:07 +0000 (14:59 -0500)
This is done in the command, rather than in the op,
- To consistently construct the `Workspace`
- It is more composable as an API

A downside is we update the git dependencies a second time.

We are not rolling back on error.
- For some errors, the user might want to debug what went wrong
- Rollback adds its own complications and risks, including since its
  non-atomic

Fixes #10901

23 files changed:
src/bin/cargo/commands/add.rs
tests/testsuite/cargo_add/git/stderr.log
tests/testsuite/cargo_add/git_branch/stderr.log
tests/testsuite/cargo_add/git_dev/stderr.log
tests/testsuite/cargo_add/git_inferred_name/stderr.log
tests/testsuite/cargo_add/git_multiple_names/stderr.log
tests/testsuite/cargo_add/git_registry/mod.rs
tests/testsuite/cargo_add/git_registry/stderr.log
tests/testsuite/cargo_add/git_rev/stderr.log
tests/testsuite/cargo_add/git_tag/stderr.log
tests/testsuite/cargo_add/list_features_path/stderr.log
tests/testsuite/cargo_add/list_features_path_no_default/stderr.log
tests/testsuite/cargo_add/locked_unchanged/in/Cargo.lock [new file with mode: 0644]
tests/testsuite/cargo_add/lockfile_updated/in/Cargo.lock [new file with mode: 0644]
tests/testsuite/cargo_add/lockfile_updated/in/Cargo.toml [new file with mode: 0644]
tests/testsuite/cargo_add/lockfile_updated/in/src/lib.rs [new file with mode: 0644]
tests/testsuite/cargo_add/lockfile_updated/mod.rs [new file with mode: 0644]
tests/testsuite/cargo_add/lockfile_updated/out/Cargo.lock [new file with mode: 0644]
tests/testsuite/cargo_add/lockfile_updated/out/Cargo.toml [new file with mode: 0644]
tests/testsuite/cargo_add/lockfile_updated/stderr.log [new file with mode: 0644]
tests/testsuite/cargo_add/lockfile_updated/stdout.log [new file with mode: 0644]
tests/testsuite/cargo_add/mod.rs
tests/testsuite/cargo_add/overwrite_version_with_git/stderr.log

index 32c7699e775e3f7ede28a49133b67a1653940162..1ff2aad1944d76e6682124e3a00f2cd1eb0668b6 100644 (file)
@@ -7,6 +7,7 @@ use cargo::ops::cargo_add::add;
 use cargo::ops::cargo_add::AddOptions;
 use cargo::ops::cargo_add::DepOp;
 use cargo::ops::cargo_add::DepTable;
+use cargo::ops::resolve_ws;
 use cargo::util::command_prelude::*;
 use cargo::util::interning::InternedString;
 use cargo::CargoResult;
@@ -193,6 +194,12 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
     };
     add(&ws, &options)?;
 
+    if !dry_run {
+        // Reload the workspace since we've changed dependencies
+        let ws = args.workspace(config)?;
+        resolve_ws(&ws)?;
+    }
+
     Ok(())
 }
 
index fdfb1a952a162df660bb3b83744d6fbf95c7165e..839d8bb327271c34e7feeee318ee4d9937c8f3be 100644 (file)
@@ -1,2 +1,3 @@
     Updating git repository `[ROOTURL]/git-package`
       Adding git-package (git) to dependencies.
+    Updating git repository `[ROOTURL]/git-package`
index fdfb1a952a162df660bb3b83744d6fbf95c7165e..839d8bb327271c34e7feeee318ee4d9937c8f3be 100644 (file)
@@ -1,2 +1,3 @@
     Updating git repository `[ROOTURL]/git-package`
       Adding git-package (git) to dependencies.
+    Updating git repository `[ROOTURL]/git-package`
index 4ba31625b58e8ebb7d3c986697297a4197e23260..8e53bb4beeae71083b760fcad01f61b8b2e26fce 100644 (file)
@@ -1,2 +1,3 @@
     Updating git repository `[ROOTURL]/git-package`
       Adding git-package (git) to dev-dependencies.
+    Updating git repository `[ROOTURL]/git-package`
index 48f251ea11d788bffdaf5772ec3479ef3d4a3758..b5e8b1c9ba39e0fc1d34cca6343c71b9447eb805 100644 (file)
@@ -1,3 +1,4 @@
     Updating git repository `[ROOTURL]/git-package`
     Updating git repository `[ROOTURL]/git-package`
       Adding git-package (git) to dependencies.
+    Updating git repository `[ROOTURL]/git-package`
index e67710147dacc598e13b3aba9919b44bdf7bd974..454f0c797ee7f2689edf4893df5ce6e468b9d8f5 100644 (file)
@@ -1,3 +1,4 @@
     Updating git repository `[ROOTURL]/git-package`
       Adding my-package1 (git) to dependencies.
       Adding my-package2 (git) to dependencies.
+    Updating git repository `[ROOTURL]/git-package`
index 20ebb39a848922f31cb8af273932a91b04dda07a..b546f63abef90d3a028380c86c327d9d0dc16969 100644 (file)
@@ -32,7 +32,7 @@ fn git_registry() {
         ])
         .current_dir(cwd)
         .assert()
-        .success()
+        .failure()
         .stdout_matches_path(curr_dir!().join("stdout.log"))
         .stderr_matches_path(curr_dir!().join("stderr.log"));
 
index 548debfadf6a9ae804e7686394816e6367f29295..c554c7ec08273fde81a7d61a0311b79358e96143 100644 (file)
@@ -1,2 +1,6 @@
     Updating git repository `[ROOTURL]/versioned-package`
       Adding versioned-package (git) to dependencies.
+error: failed to parse manifest at `[ROOT]/case/Cargo.toml`
+
+Caused by:
+  dependency (versioned-package) specification is ambiguous. Only one of `git` or `registry` is allowed.
index fdfb1a952a162df660bb3b83744d6fbf95c7165e..839d8bb327271c34e7feeee318ee4d9937c8f3be 100644 (file)
@@ -1,2 +1,3 @@
     Updating git repository `[ROOTURL]/git-package`
       Adding git-package (git) to dependencies.
+    Updating git repository `[ROOTURL]/git-package`
index fdfb1a952a162df660bb3b83744d6fbf95c7165e..839d8bb327271c34e7feeee318ee4d9937c8f3be 100644 (file)
@@ -1,2 +1,3 @@
     Updating git repository `[ROOTURL]/git-package`
       Adding git-package (git) to dependencies.
+    Updating git repository `[ROOTURL]/git-package`
index 27378049be0067736ef87d4920c0bed392e8d875..af6747fe8360007c79317606c96d4ebec2ef4ba0 100644 (file)
@@ -4,3 +4,4 @@
              + nose
              - eyes
              - optional-dependency
+    Updating `dummy-registry` index
index cc6c834627910a063c30c98f73d9fed4048acda8..7f47a220ec09fbd65678a0223f721caea5f7caf3 100644 (file)
@@ -4,3 +4,4 @@
              - mouth
              - nose
              - optional-dependency
+    Updating `dummy-registry` index
diff --git a/tests/testsuite/cargo_add/locked_unchanged/in/Cargo.lock b/tests/testsuite/cargo_add/locked_unchanged/in/Cargo.lock
new file mode 100644 (file)
index 0000000..011b335
--- /dev/null
@@ -0,0 +1,16 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+dependencies = [
+ "my-package",
+]
+
+[[package]]
+name = "my-package"
+version = "99999.0.0+my-package"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "62c45acf9e11d2f97f5b318143219c0b4102eafef1c22a4b545b47104691d915"
diff --git a/tests/testsuite/cargo_add/lockfile_updated/in/Cargo.lock b/tests/testsuite/cargo_add/lockfile_updated/in/Cargo.lock
new file mode 100644 (file)
index 0000000..d9bcc98
--- /dev/null
@@ -0,0 +1,17 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+dependencies = [
+ "my-package",
+ "unrelateed-crate",
+]
+
+[[package]]
+name = "unrelateed-crate"
+version = "0.2.0+my-package"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "266de4849a570b5dfda5e8e082a2aff885e9d2d4965dae8f8b6c8535e1ec731f"
diff --git a/tests/testsuite/cargo_add/lockfile_updated/in/Cargo.toml b/tests/testsuite/cargo_add/lockfile_updated/in/Cargo.toml
new file mode 100644 (file)
index 0000000..95276d7
--- /dev/null
@@ -0,0 +1,8 @@
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+
+[dependencies]
+unrelateed-crate = "0.2.0"
diff --git a/tests/testsuite/cargo_add/lockfile_updated/in/src/lib.rs b/tests/testsuite/cargo_add/lockfile_updated/in/src/lib.rs
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/testsuite/cargo_add/lockfile_updated/mod.rs b/tests/testsuite/cargo_add/lockfile_updated/mod.rs
new file mode 100644 (file)
index 0000000..41d39ef
--- /dev/null
@@ -0,0 +1,25 @@
+use cargo_test_support::compare::assert_ui;
+use cargo_test_support::prelude::*;
+use cargo_test_support::Project;
+
+use crate::cargo_add::init_registry;
+use cargo_test_support::curr_dir;
+
+#[cargo_test]
+fn lockfile_updated() {
+    init_registry();
+    let project = Project::from_template(curr_dir!().join("in"));
+    let project_root = project.root();
+    let cwd = &project_root;
+
+    snapbox::cmd::Command::cargo_ui()
+        .arg("add")
+        .arg_line("my-package")
+        .current_dir(cwd)
+        .assert()
+        .success()
+        .stdout_matches_path(curr_dir!().join("stdout.log"))
+        .stderr_matches_path(curr_dir!().join("stderr.log"));
+
+    assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
+}
diff --git a/tests/testsuite/cargo_add/lockfile_updated/out/Cargo.lock b/tests/testsuite/cargo_add/lockfile_updated/out/Cargo.lock
new file mode 100644 (file)
index 0000000..4b5fb46
--- /dev/null
@@ -0,0 +1,23 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+dependencies = [
+ "my-package",
+ "unrelateed-crate",
+]
+
+[[package]]
+name = "my-package"
+version = "99999.0.0+my-package"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "62c45acf9e11d2f97f5b318143219c0b4102eafef1c22a4b545b47104691d915"
+
+[[package]]
+name = "unrelateed-crate"
+version = "0.2.0+my-package"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "266de4849a570b5dfda5e8e082a2aff885e9d2d4965dae8f8b6c8535e1ec731f"
diff --git a/tests/testsuite/cargo_add/lockfile_updated/out/Cargo.toml b/tests/testsuite/cargo_add/lockfile_updated/out/Cargo.toml
new file mode 100644 (file)
index 0000000..3176a98
--- /dev/null
@@ -0,0 +1,9 @@
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+
+[dependencies]
+my-package = "99999.0.0"
+unrelateed-crate = "0.2.0"
diff --git a/tests/testsuite/cargo_add/lockfile_updated/stderr.log b/tests/testsuite/cargo_add/lockfile_updated/stderr.log
new file mode 100644 (file)
index 0000000..fd6b711
--- /dev/null
@@ -0,0 +1,2 @@
+    Updating `dummy-registry` index
+      Adding my-package v99999.0.0 to dependencies.
diff --git a/tests/testsuite/cargo_add/lockfile_updated/stdout.log b/tests/testsuite/cargo_add/lockfile_updated/stdout.log
new file mode 100644 (file)
index 0000000..e69de29
index 914e1c3ae50656c7d19d142056cd85d35df500d3..ae32bdd2de3cd339275c0953d63565b4d1dd5f24 100644 (file)
@@ -50,6 +50,7 @@ mod list_features_path;
 mod list_features_path_no_default;
 mod locked_changed;
 mod locked_unchanged;
+mod lockfile_updated;
 mod manifest_path_package;
 mod merge_activated_features;
 mod multiple_conflicts_with_features;
@@ -133,6 +134,9 @@ fn add_registry_packages(alt: bool) {
         cargo_test_support::registry::Package::new(name, "0.1.1+my-package")
             .alternative(alt)
             .publish();
+        cargo_test_support::registry::Package::new(name, "0.2.0+my-package")
+            .alternative(alt)
+            .publish();
         cargo_test_support::registry::Package::new(name, "0.2.3+my-package")
             .alternative(alt)
             .publish();
index c5013969264d6b252a5fe6c86223fad1b6a5188a..1b77cbe0e3581a1e058b23bfff1d0e45c63fb675 100644 (file)
@@ -1,2 +1,3 @@
     Updating git repository `[ROOTURL]/versioned-package`
       Adding versioned-package (git) to optional dependencies.
+    Updating git repository `[ROOTURL]/versioned-package`