Skip to content

Commit 61ba775

Browse files
committed
fix(add): Update the lock file
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
1 parent 323c7bc commit 61ba775

File tree

14 files changed

+38
-1
lines changed

14 files changed

+38
-1
lines changed

src/bin/cargo/commands/add.rs

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use cargo::ops::cargo_add::add;
77
use cargo::ops::cargo_add::AddOptions;
88
use cargo::ops::cargo_add::DepOp;
99
use cargo::ops::cargo_add::DepTable;
10+
use cargo::ops::generate_lockfile;
1011
use cargo::util::command_prelude::*;
1112
use cargo::util::interning::InternedString;
1213
use cargo::CargoResult;
@@ -193,6 +194,12 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
193194
};
194195
add(&ws, &options)?;
195196

197+
if !dry_run {
198+
// Reload the workspace since we've changed dependencies
199+
let ws = args.workspace(config)?;
200+
generate_lockfile(&ws)?;
201+
}
202+
196203
Ok(())
197204
}
198205

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Updating git repository `[ROOTURL]/git-package`
22
Adding git-package (git) to dependencies.
3+
Updating git repository `[ROOTURL]/git-package`
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Updating git repository `[ROOTURL]/git-package`
22
Adding git-package (git) to dependencies.
3+
Updating git repository `[ROOTURL]/git-package`
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Updating git repository `[ROOTURL]/git-package`
22
Adding git-package (git) to dev-dependencies.
3+
Updating git repository `[ROOTURL]/git-package`
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Updating git repository `[ROOTURL]/git-package`
22
Updating git repository `[ROOTURL]/git-package`
33
Adding git-package (git) to dependencies.
4+
Updating git repository `[ROOTURL]/git-package`
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Updating git repository `[ROOTURL]/git-package`
22
Adding my-package1 (git) to dependencies.
33
Adding my-package2 (git) to dependencies.
4+
Updating git repository `[ROOTURL]/git-package`

tests/testsuite/cargo_add/git_registry/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn git_registry() {
3232
])
3333
.current_dir(cwd)
3434
.assert()
35-
.success()
35+
.failure()
3636
.stdout_matches_path(curr_dir!().join("stdout.log"))
3737
.stderr_matches_path(curr_dir!().join("stderr.log"));
3838

Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
Updating git repository `[ROOTURL]/versioned-package`
22
Adding versioned-package (git) to dependencies.
3+
error: failed to parse manifest at `[ROOT]/case/Cargo.toml`
4+
5+
Caused by:
6+
dependency (versioned-package) specification is ambiguous. Only one of `git` or `registry` is allowed.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Updating git repository `[ROOTURL]/git-package`
22
Adding git-package (git) to dependencies.
3+
Updating git repository `[ROOTURL]/git-package`
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Updating git repository `[ROOTURL]/git-package`
22
Adding git-package (git) to dependencies.
3+
Updating git repository `[ROOTURL]/git-package`

tests/testsuite/cargo_add/list_features_path/stderr.log

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
+ nose
55
- eyes
66
- optional-dependency
7+
Updating `dummy-registry` index

tests/testsuite/cargo_add/list_features_path_no_default/stderr.log

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
- mouth
55
- nose
66
- optional-dependency
7+
Updating `dummy-registry` index

tests/testsuite/cargo_add/locked_unchanged/in/Cargo.lock

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Updating git repository `[ROOTURL]/versioned-package`
22
Adding versioned-package (git) to optional dependencies.
3+
Updating git repository `[ROOTURL]/versioned-package`

0 commit comments

Comments
 (0)