Skip to content

Commit 26cb07b

Browse files
committed
Auto merge of #2771 - alexcrichton:update-replace, r=brson
Don't lock overrides if we're updating them There was already a function for this, `keep`, it was just forgotten to be called. Closes #2766
2 parents 4fbd47c + feccad0 commit 26cb07b

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

src/cargo/ops/cargo_generate_lockfile.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ pub fn update_lockfile(manifest_path: &Path,
3737
let package = try!(Package::for_path(manifest_path, opts.config));
3838

3939
let previous_resolve = match try!(ops::load_pkg_lockfile(&package, opts.config)) {
40-
Some(resolve) => resolve,
41-
None => {
42-
return generate_lockfile(manifest_path, opts.config);
43-
}
40+
Some(resolve) => resolve,
41+
None => return generate_lockfile(manifest_path, opts.config),
4442
};
4543
let mut registry = PackageRegistry::new(opts.config);
4644
let mut to_avoid = HashSet::new();

src/cargo/ops/resolve.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ pub fn resolve_with_previous<'a>(registry: &mut PackageRegistry,
105105
let replace = package.manifest().replace();
106106
let replace = replace.iter().map(|&(ref spec, ref dep)| {
107107
for (key, val) in r.replacements().iter() {
108-
if spec.matches(key) && dep.matches_id(val) {
108+
if spec.matches(key) &&
109+
dep.matches_id(val) &&
110+
keep(&val, to_avoid, &to_avoid_sources) {
109111
return (spec.clone(), dep.clone().lock_to(val))
110112
}
111113
}

tests/overrides.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,3 +578,42 @@ Please re-run this command with [..]
578578
[..]#foo:0.1.0
579579
"));
580580
}
581+
582+
#[test]
583+
fn update() {
584+
Package::new("foo", "0.1.0").publish();
585+
586+
let foo = git::repo(&paths::root().join("override"))
587+
.file("Cargo.toml", r#"
588+
[package]
589+
name = "foo"
590+
version = "0.1.0"
591+
authors = []
592+
"#)
593+
.file("src/lib.rs", "pub fn foo() {}");
594+
foo.build();
595+
596+
let p = project("local")
597+
.file("Cargo.toml", &format!(r#"
598+
[package]
599+
name = "local"
600+
version = "0.0.1"
601+
authors = []
602+
603+
[dependencies]
604+
foo = "0.1.0"
605+
606+
[replace]
607+
"foo:0.1.0" = {{ git = '{0}' }}
608+
"#, foo.url()))
609+
.file("src/lib.rs", "");
610+
611+
assert_that(p.cargo_process("generate-lockfile"),
612+
execs().with_status(0));
613+
assert_that(p.cargo("update"),
614+
execs().with_status(0)
615+
.with_stderr("\
616+
[UPDATING] registry `[..]`
617+
[UPDATING] git repository `[..]`
618+
"));
619+
}

0 commit comments

Comments
 (0)