From 17ec41515e4908aae0d4848423e0605aafe21196 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Sun, 27 Mar 2022 11:13:10 +0800 Subject: [PATCH 1/2] Use the correct the flag in --locked --offline error message Signed-off-by: hi-rustin --- src/cargo/ops/lockfile.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/ops/lockfile.rs b/src/cargo/ops/lockfile.rs index 8743520ad0c..2a1b1db39dd 100644 --- a/src/cargo/ops/lockfile.rs +++ b/src/cargo/ops/lockfile.rs @@ -47,7 +47,7 @@ pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoRes } if !ws.config().lock_update_allowed() { - let flag = if ws.config().network_allowed() { + let flag = if ws.config().locked() { "--locked" } else { "--frozen" From 7363f43d02bb4144ed78a7361e0c97b02f228da8 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Sun, 27 Mar 2022 11:13:24 +0800 Subject: [PATCH 2/2] Add offline_and_locked_and_no_frozen test Signed-off-by: hi-rustin --- tests/testsuite/offline.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/testsuite/offline.rs b/tests/testsuite/offline.rs index 722f59767a5..28f2b543ded 100644 --- a/tests/testsuite/offline.rs +++ b/tests/testsuite/offline.rs @@ -700,3 +700,16 @@ remove the --frozen flag and use --offline instead. ") .run(); } + +#[cargo_test] +fn offline_and_locked_and_no_frozen() { + let p = project().file("src/lib.rs", "").build(); + p.cargo("build --locked --offline") + .with_status(101) + .with_stderr("\ +error: the lock file [ROOT]/foo/Cargo.lock needs to be updated but --locked was passed to prevent this +If you want to try to generate the lock file without accessing the network, \ +remove the --locked flag and use --offline instead. +") + .run(); +}