From 0200d3b3caf78461e5f61f34deb833c538257bc8 Mon Sep 17 00:00:00 2001 From: Atkins Chang Date: Fri, 13 May 2022 16:59:57 +0800 Subject: [PATCH 1/2] Add test for vendor with different revs from same git repo Signed-off-by: Atkins Chang --- tests/testsuite/vendor.rs | 56 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/tests/testsuite/vendor.rs b/tests/testsuite/vendor.rs index 306c07830a1..57f5084db79 100644 --- a/tests/testsuite/vendor.rs +++ b/tests/testsuite/vendor.rs @@ -8,7 +8,7 @@ use std::fs; use cargo_test_support::git; use cargo_test_support::registry::{self, Package, RegistryBuilder}; -use cargo_test_support::{basic_lib_manifest, paths, project, Project}; +use cargo_test_support::{basic_lib_manifest, basic_manifest, paths, project, Project}; #[cargo_test] fn vendor_simple() { @@ -675,6 +675,60 @@ fn git_simple() { assert!(csum.contains("\"package\":null")); } +#[cargo_test] +fn git_diff_rev() { + let (git_project, git_repo) = git::new_repo("git", |p| { + p.file("Cargo.toml", &basic_manifest("a", "0.1.0")) + .file("src/lib.rs", "") + }); + let url = git_project.url(); + let ref_1 = "v0.1.0"; + let ref_2 = "v0.2.0"; + + git::tag(&git_repo, ref_1); + + git_project.change_file("Cargo.toml", &basic_manifest("a", "0.2.0")); + git::add(&git_repo); + git::commit(&git_repo); + git::tag(&git_repo, ref_2); + + let p = project() + .file( + "Cargo.toml", + &format!( + r#" + [package] + name = "foo" + version = "0.1.0" + + [dependencies] + a_1 = {{ package = "a", git = '{url}', rev = '{ref_1}' }} + a_2 = {{ package = "a", git = '{url}', rev = '{ref_2}' }} + "# + ), + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("vendor --respect-source-config") + .with_stdout( + r#"[source."git+file://[..]/git?rev=v0.1.0"] +git = [..] +rev = "v0.1.0" +replace-with = "vendored-sources" + +[source."git+file://[..]/git?rev=v0.2.0"] +git = [..] +rev = "v0.2.0" +replace-with = "vendored-sources" + +[source.vendored-sources] +directory = "vendor" +"#, + ) + .run(); +} + #[cargo_test] fn git_duplicate() { let git = git::new("a", |p| { From f114298149326c435150fecf02b8b58f1cac67e3 Mon Sep 17 00:00:00 2001 From: Atkins Chang Date: Fri, 13 May 2022 17:01:21 +0800 Subject: [PATCH 2/2] Support vendoring with different revs from same git repo Signed-off-by: Atkins Chang --- src/cargo/ops/vendor.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/vendor.rs b/src/cargo/ops/vendor.rs index c09a936d03f..1239289d684 100644 --- a/src/cargo/ops/vendor.rs +++ b/src/cargo/ops/vendor.rs @@ -255,7 +255,9 @@ fn sync( let name = if source_id.is_crates_io() { CRATES_IO_REGISTRY.to_string() } else { - source_id.url().to_string() + // Remove `precise` since that makes the source name very long, + // and isn't needed to disambiguate multiple sources. + source_id.with_precise(None).as_url().to_string() }; let source = if source_id.is_crates_io() {