Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/cargo/ops/cargo_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,14 @@ fn install_one(
};

let (mut ws, rustc, target) = make_ws_rustc_target(config, opts, &source_id, pkg.clone())?;
// If we're installing in --locked mode and there's no `Cargo.lock` published
// ie. the bin was published before https://github.com/rust-lang/cargo/pull/7026
if config.locked() && !ws.root().join("Cargo.lock").exists() {
config.shell().warn(format!(
"no Cargo.lock file published in {}",
pkg.to_string()
))?;
}
let pkg = if source_id.is_git() {
// Don't use ws.current() in order to keep the package source as a git source so that
// install tracking uses the correct source.
Expand Down
4 changes: 4 additions & 0 deletions src/cargo/util/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,10 @@ impl Config {
self.frozen
}

pub fn locked(&self) -> bool {
self.locked
}

pub fn lock_update_allowed(&self) -> bool {
!self.frozen && !self.locked
}
Expand Down
12 changes: 12 additions & 0 deletions tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ fn git_repo() {
.with_stderr(
"\
[UPDATING] git repository `[..]`
[WARNING] no Cargo.lock file published in foo v0.1.0 ([..])
[INSTALLING] foo v0.1.0 ([..])
[COMPILING] foo v0.1.0 ([..])
[FINISHED] release [optimized] target(s) in [..]
Expand Down Expand Up @@ -1665,3 +1666,14 @@ workspace: [..]/foo/Cargo.toml
.run();
assert_has_installed_exe(cargo_home(), "foo");
}

#[cargo_test]
fn locked_install_without_published_lockfile() {
Package::new("foo", "0.1.0")
.file("src/main.rs", "//! Some docs\nfn main() {}")
.publish();

cargo_process("install foo --locked")
.with_stderr_contains("[WARNING] no Cargo.lock file published in foo v0.1.0")
.run();
}