Skip to content

Commit

Permalink
Auto merge of #5564 - mati865:metadata_fix, r=alexcrichton
Browse files Browse the repository at this point in the history
Always replace metadata when replacing package

Fixes #4582

I'm having problem writing test for it.
The test should install binary, make commit and reinstall binary, this part is done.
To know if it was done properly we need to compare git revision of HEAD and installed binary and that's where the problems begin...
  • Loading branch information
bors committed May 25, 2018
2 parents 22c0f22 + 059107e commit 4c8b8ac
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 4c8b8ac

Please sign in to comment.