From 059107e1a0ad270f3c4fe193464f2b82d9d5999f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mateusz=20Miku=C5=82a?= Date: Thu, 24 May 2018 11:39:56 +0200 Subject: [PATCH] Always replace metadata when replacing package Fixes https://github.com/rust-lang/cargo/issues/4582 --- src/cargo/ops/cargo_install.rs | 5 ++++ tests/testsuite/install.rs | 50 +++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_install.rs b/src/cargo/ops/cargo_install.rs index d5f09ff9b..9516aac09 100644 --- a/src/cargo/ops/cargo_install.rs +++ b/src/cargo/ops/cargo_install.rs @@ -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) diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index 5e6f6f6d3..6c24e17f0 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -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 { @@ -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)) + ); +} -- 2.30.2