Skip to content

Commit

Permalink
fix(add): Update the lock file
Browse files Browse the repository at this point in the history
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
  • Loading branch information
epage committed Jul 26, 2022
1 parent 323c7bc commit 1766dc0
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/bin/cargo/commands/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(())
}

Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/cargo_add/git/stderr.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Updating git repository `[ROOTURL]/git-package`
Adding git-package (git) to dependencies.
Updating git repository `[ROOTURL]/git-package`
1 change: 1 addition & 0 deletions tests/testsuite/cargo_add/git_branch/stderr.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Updating git repository `[ROOTURL]/git-package`
Adding git-package (git) to dependencies.
Updating git repository `[ROOTURL]/git-package`
1 change: 1 addition & 0 deletions tests/testsuite/cargo_add/git_dev/stderr.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Updating git repository `[ROOTURL]/git-package`
Adding git-package (git) to dev-dependencies.
Updating git repository `[ROOTURL]/git-package`
1 change: 1 addition & 0 deletions tests/testsuite/cargo_add/git_inferred_name/stderr.log
Original file line number Diff line number Diff line change
@@ -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`
1 change: 1 addition & 0 deletions tests/testsuite/cargo_add/git_multiple_names/stderr.log
Original file line number Diff line number Diff line change
@@ -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`
2 changes: 1 addition & 1 deletion tests/testsuite/cargo_add/git_registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down
4 changes: 4 additions & 0 deletions tests/testsuite/cargo_add/git_registry/stderr.log
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions tests/testsuite/cargo_add/git_rev/stderr.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Updating git repository `[ROOTURL]/git-package`
Adding git-package (git) to dependencies.
Updating git repository `[ROOTURL]/git-package`
1 change: 1 addition & 0 deletions tests/testsuite/cargo_add/git_tag/stderr.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Updating git repository `[ROOTURL]/git-package`
Adding git-package (git) to dependencies.
Updating git repository `[ROOTURL]/git-package`
1 change: 1 addition & 0 deletions tests/testsuite/cargo_add/list_features_path/stderr.log
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
+ nose
- eyes
- optional-dependency
Updating `dummy-registry` index
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
- mouth
- nose
- optional-dependency
Updating `dummy-registry` index
16 changes: 16 additions & 0 deletions tests/testsuite/cargo_add/locked_unchanged/in/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Updating git repository `[ROOTURL]/versioned-package`
Adding versioned-package (git) to optional dependencies.
Updating git repository `[ROOTURL]/versioned-package`

0 comments on commit 1766dc0

Please sign in to comment.