Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support vendoring with different revs from same git repo #10690

Merged
merged 2 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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