Skip to content

Commit 5a574d3

Browse files
committed
Auto merge of #10690 - AtkinsChang:vendor, r=hi-rustin
Support vendoring with different revs from same git repo ### What does this PR try to resolve? Fixes #10667 ### How should we test and review this PR? test case is included
2 parents 2381cbd + f114298 commit 5a574d3

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

src/cargo/ops/vendor.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@ fn sync(
255255
let name = if source_id.is_crates_io() {
256256
CRATES_IO_REGISTRY.to_string()
257257
} else {
258-
source_id.url().to_string()
258+
// Remove `precise` since that makes the source name very long,
259+
// and isn't needed to disambiguate multiple sources.
260+
source_id.with_precise(None).as_url().to_string()
259261
};
260262

261263
let source = if source_id.is_crates_io() {

tests/testsuite/vendor.rs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::fs;
88

99
use cargo_test_support::git;
1010
use cargo_test_support::registry::{self, Package, RegistryBuilder};
11-
use cargo_test_support::{basic_lib_manifest, paths, project, Project};
11+
use cargo_test_support::{basic_lib_manifest, basic_manifest, paths, project, Project};
1212

1313
#[cargo_test]
1414
fn vendor_simple() {
@@ -675,6 +675,60 @@ fn git_simple() {
675675
assert!(csum.contains("\"package\":null"));
676676
}
677677

678+
#[cargo_test]
679+
fn git_diff_rev() {
680+
let (git_project, git_repo) = git::new_repo("git", |p| {
681+
p.file("Cargo.toml", &basic_manifest("a", "0.1.0"))
682+
.file("src/lib.rs", "")
683+
});
684+
let url = git_project.url();
685+
let ref_1 = "v0.1.0";
686+
let ref_2 = "v0.2.0";
687+
688+
git::tag(&git_repo, ref_1);
689+
690+
git_project.change_file("Cargo.toml", &basic_manifest("a", "0.2.0"));
691+
git::add(&git_repo);
692+
git::commit(&git_repo);
693+
git::tag(&git_repo, ref_2);
694+
695+
let p = project()
696+
.file(
697+
"Cargo.toml",
698+
&format!(
699+
r#"
700+
[package]
701+
name = "foo"
702+
version = "0.1.0"
703+
704+
[dependencies]
705+
a_1 = {{ package = "a", git = '{url}', rev = '{ref_1}' }}
706+
a_2 = {{ package = "a", git = '{url}', rev = '{ref_2}' }}
707+
"#
708+
),
709+
)
710+
.file("src/lib.rs", "")
711+
.build();
712+
713+
p.cargo("vendor --respect-source-config")
714+
.with_stdout(
715+
r#"[source."git+file://[..]/git?rev=v0.1.0"]
716+
git = [..]
717+
rev = "v0.1.0"
718+
replace-with = "vendored-sources"
719+
720+
[source."git+file://[..]/git?rev=v0.2.0"]
721+
git = [..]
722+
rev = "v0.2.0"
723+
replace-with = "vendored-sources"
724+
725+
[source.vendored-sources]
726+
directory = "vendor"
727+
"#,
728+
)
729+
.run();
730+
}
731+
678732
#[cargo_test]
679733
fn git_duplicate() {
680734
let git = git::new("a", |p| {

0 commit comments

Comments
 (0)