From 5ec675c20b6f0000056c0b907eae931f254754f6 Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Tue, 17 Mar 2026 17:22:25 +0100 Subject: [PATCH] pull: fix edge cases - Ubuntu does not have 'Launchpad/Code' repo edge case - Vcs-Git field has a git command, not only an URL edge case --- src/package_info.rs | 10 +++++++++- src/pull.rs | 29 ++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/package_info.rs b/src/package_info.rs index e31bfa9..2c4438a 100644 --- a/src/package_info.rs +++ b/src/package_info.rs @@ -153,6 +153,14 @@ impl Iterator for DebianSources { } } + // Parse Vcs-Git field: it may contain just a URL, or URL followed by -b + // e.g., "https://salsa.debian.org/science-team/paraview.git -b debian/latest" + let vcs_git = fields.get("Vcs-Git").map(|vcs| { + // Split on whitespace and take the first part (the URL) + // The URL should not contain spaces, so this is safe + vcs.split_whitespace().next().unwrap_or(vcs).to_string() + }); + Some(PackageStanza { package: fields.get("Package").unwrap().to_string(), version: fields.get("Version").unwrap().to_string(), @@ -161,7 +169,7 @@ impl Iterator for DebianSources { .get("Format") .cloned() .unwrap_or_else(|| "1.0".to_string()), - vcs_git: fields.get("Vcs-Git").cloned(), + vcs_git, vcs_browser: fields.get("Vcs-Browser").cloned(), files, }) diff --git a/src/pull.rs b/src/pull.rs index 9c8aa71..19df76e 100644 --- a/src/pull.rs +++ b/src/pull.rs @@ -504,14 +504,17 @@ pub async fn pull( // Depending on target series, we pick target branch; if latest series is specified, // we target the development branch, i.e. the default branch + // Only use Ubuntu-specific branch naming if the VCS is from Launchpad + let is_launchpad_vcs = url.contains("launchpad.net"); let branch_name = if crate::distro_info::get_ordered_series_name(package_info.dist.as_str()) .await?[0] != *series { - if package_info.dist == "ubuntu" { + if package_info.dist == "ubuntu" && is_launchpad_vcs { Some(format!("{}/{}", package_info.dist, series)) } else { // Debian does not have reliable branch naming... + // Also, Ubuntu packages with salsa VCS don't have Ubuntu-specific branches // For now, we skip that part and clone default // TODO: Inspect remote branches and tags for matches None @@ -615,18 +618,27 @@ mod tests { let head = repo.head().unwrap(); let name = head.name().unwrap(); + // Check if the VCS is from Launchpad - only Launchpad has Ubuntu-specific branches + let is_launchpad_vcs = info + .preferred_vcs + .as_ref() + .map(|url| url.contains("launchpad.net")) + .unwrap_or(false); + if let Some(s) = series { // The local branch should be named dist/series // We skip debian for now as it does not have a reliable naming scheme - if info.dist == "ubuntu" { + // Also skip Ubuntu packages with non-Launchpad VCS (e.g., salsa.debian.org) + if info.dist == "ubuntu" && is_launchpad_vcs { assert_eq!(name, format!("refs/heads/{0}/{s}", info.dist)); } } else { // The local branch should be named ubuntu/devel for Ubuntu // Debian unfortunately does not have a reliable naming scheme + // Also skip Ubuntu packages with non-Launchpad VCS // Given that there was no series specified, and this is a test, // we require to have a distribution specified - if dist.unwrap() == "ubuntu" { + if dist.unwrap() == "ubuntu" && is_launchpad_vcs { assert_eq!(name, "refs/heads/ubuntu/devel"); } } @@ -690,4 +702,15 @@ mod tests { async fn test_pull_hello_ubuntu_latest_end_to_end() { test_pull_package_end_to_end("hello", None, Some("ubuntu"), None).await; } + + /// Test for paraview - a package that has no Ubuntu Launchpad code, + /// only a debian salsa repo, even in Ubuntu. + /// Furthermore, paraview has a Vcs-Git value of: + /// Vcs-Git: https://salsa.debian.org/science-team/paraview.git -b debian/latest + /// Given that it is not only an url but also specifies a branch, it needs + /// special care, that this test ensures. + #[tokio::test] + async fn test_pull_paraview_ubuntu_end_to_end() { + test_pull_package_end_to_end("paraview", Some("noble"), None, None).await; + } }