Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Don't try to generate Gargo.lock on empty workspaces. #3092

Merged
merged 1 commit into from
Sep 14, 2016
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: 7 additions & 1 deletion src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<'cfg> Workspace<'cfg> {
Ok(ws)
}

/// Creates a "tempoarary workspace" from one package which only contains
/// Creates a "temporary workspace" from one package which only contains
/// that package.
///
/// This constructor will not touch the filesystem and only creates an
Expand Down Expand Up @@ -464,6 +464,12 @@ impl<'cfg> Packages<'cfg> {
}
}

impl<'a, 'cfg> Members<'a, 'cfg> {
pub fn is_empty(self) -> bool {
self.count() == 0
}
}

impl<'a, 'cfg> Iterator for Members<'a, 'cfg> {
type Item = &'a Package;

Expand Down
4 changes: 4 additions & 0 deletions src/cargo/ops/cargo_generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ pub fn update_lockfile(ws: &Workspace, opts: &UpdateOptions)
bail!("cannot specify both aggressive and precise simultaneously")
}

if ws.members().is_empty() {
bail!("you can't generate a lockfile for an empty workspace.")
}

let previous_resolve = match try!(ops::load_pkg_lockfile(ws)) {
Some(resolve) => resolve,
None => return generate_lockfile(ws),
Expand Down
22 changes: 22 additions & 0 deletions tests/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,3 +940,25 @@ fn lockfile_can_specify_nonexistant_members() {

assert_that(p.cargo("build").cwd(p.root().join("a")), execs().with_status(0));
}

#[test]
fn you_cannot_generate_lockfile_for_empty_workspaces() {
let p = project("foo")
.file("Cargo.toml", r#"
[workspace]
"#)
.file("bar/Cargo.toml", r#"
[project]
name = "foo"
version = "0.1.0"
authors = []
"#)
.file("bar/src/main.rs", "fn main() {}");
p.build();

assert_that(p.cargo("update"),
execs().with_status(101)
.with_stderr("\
error: you can't generate a lockfile for an empty workspace.
"));
}