diff --git a/crates/uv-distribution/src/metadata/lowering.rs b/crates/uv-distribution/src/metadata/lowering.rs index 41f4df47e948..bedcc1e31692 100644 --- a/crates/uv-distribution/src/metadata/lowering.rs +++ b/crates/uv-distribution/src/metadata/lowering.rs @@ -315,11 +315,12 @@ impl LoweredRequirement { })?; let source = if let Some(git_member) = &git_member { - // If the workspace comes from a git dependency, all workspace - // members need to be git deps, too. - let subdirectory = - uv_fs::relative_to(member.root(), git_member.fetch_root) - .expect("Workspace member must be relative"); + // If the workspace comes from a Git dependency, all workspace + // members need to be Git dependencies, too. + let subdirectory = uv_fs::normalize_path( + &uv_fs::relative_to(member.root(), git_member.fetch_root) + .expect("Workspace member must be relative"), + ); RequirementSource::Git { repository: git_member.git_source.git.repository().clone(), reference: git_member.git_source.git.reference().clone(), diff --git a/crates/uv-resolver/src/resolver/urls.rs b/crates/uv-resolver/src/resolver/urls.rs index eeae4817b62a..2f33ad21c587 100644 --- a/crates/uv-resolver/src/resolver/urls.rs +++ b/crates/uv-resolver/src/resolver/urls.rs @@ -191,11 +191,14 @@ impl Urls { fn same_resource(a: &ParsedUrl, b: &ParsedUrl, git: &GitResolver) -> bool { match (a, b) { (ParsedUrl::Archive(a), ParsedUrl::Archive(b)) => { - a.subdirectory == b.subdirectory + a.subdirectory.as_deref().map(uv_fs::normalize_path) + == b.subdirectory.as_deref().map(uv_fs::normalize_path) && CanonicalUrl::new(&a.url) == CanonicalUrl::new(&b.url) } (ParsedUrl::Git(a), ParsedUrl::Git(b)) => { - a.subdirectory == b.subdirectory && git.same_ref(&a.url, &b.url) + a.subdirectory.as_deref().map(uv_fs::normalize_path) + == b.subdirectory.as_deref().map(uv_fs::normalize_path) + && git.same_ref(&a.url, &b.url) } (ParsedUrl::Path(a), ParsedUrl::Path(b)) => { a.install_path == b.install_path diff --git a/crates/uv/tests/it/sync.rs b/crates/uv/tests/it/sync.rs index 4b528ff15f21..7f419b83e2f5 100644 --- a/crates/uv/tests/it/sync.rs +++ b/crates/uv/tests/it/sync.rs @@ -5319,6 +5319,97 @@ fn sync_git_repeated_member_dynamic_metadata() -> Result<()> { Ok(()) } +/// See: +#[test] +fn sync_git_repeated_member_backwards_path() -> Result<()> { + let context = TestContext::new("3.13"); + + let pyproject_toml = context.temp_dir.child("pyproject.toml"); + pyproject_toml.write_str( + r#" + [project] + name = "foo" + version = "0.1.0" + requires-python = ">=3.13" + dependencies = ["package", "dependency"] + [tool.uv.sources] + package = { git = "https://github.com/astral-sh/uv-backwards-path-test", subdirectory = "root" } + dependency = { git = "https://github.com/astral-sh/uv-backwards-path-test", subdirectory = "dependency" } + "#, + )?; + + uv_snapshot!(context.filters(), context.lock(), @r###" + success: true + exit_code: 0 + ----- stdout ----- + + ----- stderr ----- + Resolved 3 packages in [TIME] + "###); + + let lock = context.read("uv.lock"); + + insta::with_settings!( + { + filters => context.filters(), + }, + { + assert_snapshot!( + lock, @r###" + version = 1 + requires-python = ">=3.13" + + [options] + exclude-newer = "2024-03-25T00:00:00Z" + + [[package]] + name = "dependency" + version = "0.1.0" + source = { git = "https://github.com/astral-sh/uv-backwards-path-test?subdirectory=dependency#4bcc7fcd2e548c2ab7ba6b97b1c4e3ababccc7a9" } + + [[package]] + name = "foo" + version = "0.1.0" + source = { virtual = "." } + dependencies = [ + { name = "dependency" }, + { name = "package" }, + ] + + [package.metadata] + requires-dist = [ + { name = "dependency", git = "https://github.com/astral-sh/uv-backwards-path-test?subdirectory=dependency" }, + { name = "package", git = "https://github.com/astral-sh/uv-backwards-path-test?subdirectory=root" }, + ] + + [[package]] + name = "package" + version = "0.1.0" + source = { git = "https://github.com/astral-sh/uv-backwards-path-test?subdirectory=root#4bcc7fcd2e548c2ab7ba6b97b1c4e3ababccc7a9" } + dependencies = [ + { name = "dependency" }, + ] + "### + ); + } + ); + + uv_snapshot!(context.filters(), context.sync(), @r###" + success: true + exit_code: 0 + ----- stdout ----- + + ----- stderr ----- + Resolved 3 packages in [TIME] + Prepared 2 packages in [TIME] + Installed 2 packages in [TIME] + + dependency==0.1.0 (from git+https://github.com/astral-sh/uv-backwards-path-test@4bcc7fcd2e548c2ab7ba6b97b1c4e3ababccc7a9#subdirectory=dependency) + + package==0.1.0 (from git+https://github.com/astral-sh/uv-backwards-path-test@4bcc7fcd2e548c2ab7ba6b97b1c4e3ababccc7a9#subdirectory=root) + "###); + + Ok(()) +} + /// The project itself is marked as an editable dependency, but under the wrong name. The project /// is a package. #[test]