]> git.proxmox.com Git - cargo.git/commitdiff
Always replace metadata when replacing package
authorMateusz Mikuła <matti@marinelayer.io>
Thu, 24 May 2018 09:39:56 +0000 (11:39 +0200)
committerMateusz Mikuła <mati865@gmail.com>
Fri, 25 May 2018 12:37:40 +0000 (14:37 +0200)
Fixes https://github.com/rust-lang/cargo/issues/4582

src/cargo/ops/cargo_install.rs
tests/testsuite/install.rs

index d5f09ff9b6dff7144436b4ceb241e62ffb741bc9..9516aac0917627029f880d21f4fa484a3fff4f7f 100644 (file)
@@ -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)
index 5e6f6f6d3331d640f41fee303b6e855cfc2ad694..6c24e17f0c2a197dec7676a74ef64636710d4644 100644 (file)
@@ -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))
+    );
+}