diff --git a/Cargo.toml b/Cargo.toml index af1946dd8ad..8e1d666d1f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -101,6 +101,8 @@ features = [ [dev-dependencies] cargo-test-macro = { path = "crates/cargo-test-macro" } cargo-test-support = { path = "crates/cargo-test-support" } +pathdiff = "0.2.0" +regex = "1" [build-dependencies] flate2 = { version = "1.0.3", default-features = false, features = ["zlib"] } diff --git a/crates/cargo-test-support/src/git.rs b/crates/cargo-test-support/src/git.rs index 18c4646b37d..0cdf5c24829 100644 --- a/crates/cargo-test-support/src/git.rs +++ b/crates/cargo-test-support/src/git.rs @@ -211,7 +211,10 @@ pub fn add_submodule<'a>( default_repo_cfg(&subrepo); t!(subrepo.remote_add_fetch("origin", "refs/heads/*:refs/heads/*")); let mut origin = t!(subrepo.find_remote("origin")); - t!(origin.fetch(&Vec::::new(), None, None)); + dbg!(path); + let fetch = origin.fetch(&Vec::::new(), None, None); + dbg!(&fetch); + t!(fetch); t!(subrepo.checkout_head(None)); t!(s.add_finalize()); s diff --git a/tests/testsuite/git.rs b/tests/testsuite/git.rs index d7974a3ef87..c53abf81276 100644 --- a/tests/testsuite/git.rs +++ b/tests/testsuite/git.rs @@ -13,6 +13,9 @@ use std::thread; use cargo_test_support::paths::{self, CargoPathExt}; use cargo_test_support::{basic_lib_manifest, basic_manifest, git, main_file, path2url, project}; use cargo_test_support::{sleep_ms, t, Project}; +use pathdiff::diff_paths; +use std::fs::File; +use regex::Regex; fn disable_git_cli() -> bool { // mingw git on Windows does not support Windows-style file URIs. @@ -943,6 +946,60 @@ fn dep_with_submodule() { .run(); } +#[cargo_test] +fn dep_with_relative_submodule() { + + + let foo = project(); + let base = git::new("base/base", |project| { + project.file("Cargo.toml", &basic_lib_manifest("base")) + .file("src/lib.rs", "pub fn dep() {}") + }); + let deployment = git::new("deployment", |project| project.file("src/lib.rs", "pub fn dep() {}")); + + let base_repo = git2::Repository::open(&base.root()).unwrap(); + let temp = base.root().join("../../deployment").canonicalize().unwrap(); + let deployment_url = temp.to_str().unwrap(); + git::add_submodule(&base_repo, "../../deployment", Path::new("deployment")); + git::commit(&base_repo); + + let project = foo + .file( + "Cargo.toml", + &format!( + r#" + [project] + + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + + [dependencies.base] + + git = '{}' + "#, + base.url() + ), + ) + .file( + "src/lib.rs", + "pub fn foo() { }", + ) + .build(); + + project + .cargo("build") + .with_stderr( + "\ +[UPDATING] git repository [..] +[UPDATING] git submodule `file://[..]/dep2` +[COMPILING] dep1 [..] +[COMPILING] foo [..] +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n", + ) + .run(); +} + #[cargo_test] fn dep_with_bad_submodule() { let project = project();