Generate the lock file when there is no lock file

This commit is contained in:
srinivasreddy 2016-03-21 01:42:52 +05:30 committed by Srinivas Reddy Thatiparthy
parent 1a6a32e76a
commit 01cc9e10c2
2 changed files with 34 additions and 9 deletions

View file

@ -29,18 +29,20 @@ pub fn generate_lockfile(manifest_path: &Path, config: &Config)
pub fn update_lockfile(manifest_path: &Path,
opts: &UpdateOptions) -> CargoResult<()> {
let package = try!(Package::for_path(manifest_path, opts.config));
let previous_resolve = match try!(ops::load_pkg_lockfile(&package,
opts.config)) {
Some(resolve) => resolve,
None => bail!("a Cargo.lock must exist before it is updated")
};
if opts.aggressive && opts.precise.is_some() {
bail!("cannot specify both aggressive and precise simultaneously")
}
let package = try!(Package::for_path(manifest_path, opts.config));
let previous_resolve = match try!(ops::load_pkg_lockfile(&package, opts.config)) {
Some(resolve) => resolve,
None => {
let _ = generate_lockfile(manifest_path, opts.config);
return Ok(());
}
};
let mut registry = PackageRegistry::new(opts.config);
let mut to_avoid = HashSet::new();

View file

@ -1,8 +1,8 @@
use std::fs::File;
use std::fs::{self, File};
use std::io::prelude::*;
use support::{project, execs};
use hamcrest::{assert_that, existing_file};
use hamcrest::{assert_that, existing_file, is_not};
fn setup() {}
@ -171,3 +171,26 @@ test!(preserve_line_endings_issue_2076 {
assert!(lock2.starts_with("[root]\r\n"));
assert_eq!(lock1, lock2);
});
test!(cargo_update_generate_lockfile {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
authors = []
version = "0.0.1"
"#)
.file("src/main.rs", "fn main() {}");
let lockfile = p.root().join("Cargo.lock");
assert_that(&lockfile, is_not(existing_file()));
assert_that(p.cargo_process("update"), execs().with_status(0).with_stdout(""));
assert_that(&lockfile, existing_file());
fs::remove_file(p.root().join("Cargo.lock")).unwrap();
assert_that(&lockfile, is_not(existing_file()));
assert_that(p.cargo("update"), execs().with_status(0).with_stdout(""));
assert_that(&lockfile, existing_file());
});