Skip to content

Commit

Permalink
Always replace metadata when replacing package
Browse files Browse the repository at this point in the history
  • Loading branch information
mati865 committed May 25, 2018
1 parent 69d61e4 commit 059107e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/cargo/ops/cargo_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ fn install_one(
set.remove(bin);
}
}
// Failsafe to force replacing metadata for git packages
// https://github.com/rust-lang/cargo/issues/4582
if let Some(set) = list.v1.remove(&pkg.package_id().clone()) {
list.v1.insert(pkg.package_id().clone(), set);
}
list.v1
.entry(pkg.package_id().clone())
.or_insert_with(BTreeSet::new)
Expand Down
50 changes: 49 additions & 1 deletion tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ use std::fs::{self, File, OpenOptions};
use std::io::prelude::*;

use cargo::util::ProcessBuilder;
use cargotest::ChannelChanger;
use cargotest::install::{cargo_home, has_installed_exe};
use cargotest::support::git;
use cargotest::support::paths;
use cargotest::support::registry::Package;
use cargotest::support::{execs, project};
use cargotest::ChannelChanger;
use git2;
use hamcrest::{assert_that, existing_dir, is_not};

fn cargo_process(s: &str) -> ProcessBuilder {
Expand Down Expand Up @@ -1533,3 +1534,50 @@ fn install_empty_argument() {
),
);
}

#[test]
fn git_repo_replace() {
let p = git::repo(&paths::root().join("foo"))
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
authors = []
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
let repo = git2::Repository::open(&p.root()).unwrap();
let old_rev = repo.revparse_single("HEAD").unwrap().id();
assert_that(
cargo_process("install")
.arg("--git")
.arg(p.url().to_string()),
execs().with_status(0),
);
git::commit(&repo);
let new_rev = repo.revparse_single("HEAD").unwrap().id();
let mut path = paths::home();
path.push(".cargo/.crates.toml");

assert_ne!(old_rev, new_rev);
assert!(
fs::read_to_string(path.clone())
.unwrap()
.contains(&format!("{}", old_rev))
);
assert_that(
cargo_process("install")
.arg("--force")
.arg("--git")
.arg(p.url().to_string()),
execs().with_status(0),
);
assert!(
fs::read_to_string(path)
.unwrap()
.contains(&format!("{}", new_rev))
);
}

0 comments on commit 059107e

Please sign in to comment.