Skip to content

Commit 4c8b8ac

Browse files
committed
Auto merge of #5564 - mati865:metadata_fix, r=alexcrichton
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...
2 parents 22c0f22 + 059107e commit 4c8b8ac

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

src/cargo/ops/cargo_install.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,11 @@ fn install_one(
356356
set.remove(bin);
357357
}
358358
}
359+
// Failsafe to force replacing metadata for git packages
360+
// https://github.com/rust-lang/cargo/issues/4582
361+
if let Some(set) = list.v1.remove(&pkg.package_id().clone()) {
362+
list.v1.insert(pkg.package_id().clone(), set);
363+
}
359364
list.v1
360365
.entry(pkg.package_id().clone())
361366
.or_insert_with(BTreeSet::new)

tests/testsuite/install.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ use std::fs::{self, File, OpenOptions};
33
use std::io::prelude::*;
44

55
use cargo::util::ProcessBuilder;
6-
use cargotest::ChannelChanger;
76
use cargotest::install::{cargo_home, has_installed_exe};
87
use cargotest::support::git;
98
use cargotest::support::paths;
109
use cargotest::support::registry::Package;
1110
use cargotest::support::{execs, project};
11+
use cargotest::ChannelChanger;
12+
use git2;
1213
use hamcrest::{assert_that, existing_dir, is_not};
1314

1415
fn cargo_process(s: &str) -> ProcessBuilder {
@@ -1533,3 +1534,50 @@ fn install_empty_argument() {
15331534
),
15341535
);
15351536
}
1537+
1538+
#[test]
1539+
fn git_repo_replace() {
1540+
let p = git::repo(&paths::root().join("foo"))
1541+
.file(
1542+
"Cargo.toml",
1543+
r#"
1544+
[package]
1545+
name = "foo"
1546+
version = "0.1.0"
1547+
authors = []
1548+
"#,
1549+
)
1550+
.file("src/main.rs", "fn main() {}")
1551+
.build();
1552+
let repo = git2::Repository::open(&p.root()).unwrap();
1553+
let old_rev = repo.revparse_single("HEAD").unwrap().id();
1554+
assert_that(
1555+
cargo_process("install")
1556+
.arg("--git")
1557+
.arg(p.url().to_string()),
1558+
execs().with_status(0),
1559+
);
1560+
git::commit(&repo);
1561+
let new_rev = repo.revparse_single("HEAD").unwrap().id();
1562+
let mut path = paths::home();
1563+
path.push(".cargo/.crates.toml");
1564+
1565+
assert_ne!(old_rev, new_rev);
1566+
assert!(
1567+
fs::read_to_string(path.clone())
1568+
.unwrap()
1569+
.contains(&format!("{}", old_rev))
1570+
);
1571+
assert_that(
1572+
cargo_process("install")
1573+
.arg("--force")
1574+
.arg("--git")
1575+
.arg(p.url().to_string()),
1576+
execs().with_status(0),
1577+
);
1578+
assert!(
1579+
fs::read_to_string(path)
1580+
.unwrap()
1581+
.contains(&format!("{}", new_rev))
1582+
);
1583+
}

0 commit comments

Comments
 (0)