Skip to content

Commit

Permalink
Auto merge of #10690 - AtkinsChang:vendor, r=hi-rustin
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Dec 26, 2022
2 parents 2381cbd + f114298 commit 5a574d3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/cargo/ops/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
56 changes: 55 additions & 1 deletion tests/testsuite/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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| {
Expand Down

0 comments on commit 5a574d3

Please sign in to comment.