Skip to content

Commit d254aa4

Browse files
committed
Preserve original reference in parse_remote_ref and enhance ref handling in build_pak_remote_ref
1 parent ce0dabf commit d254aa4

3 files changed

Lines changed: 77 additions & 26 deletions

File tree

R/util_resolve_remote.R

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ resolve_remote_pkg <- function(pkg_ref, cache_path = NULL) {
174174
#' @return List with components: type, user, repo, ref, subdir
175175
#' @keywords internal
176176
parse_remote_ref <- function(ref) {
177+
original_ref <- ref
178+
177179
# Handle web URLs
178180
if (grepl("^https?://", ref)) {
179181
return(parse_remote_url(ref))
@@ -200,7 +202,7 @@ parse_remote_ref <- function(ref) {
200202
repo = NA_character_,
201203
ref = NULL,
202204
subdir = NULL,
203-
original = ref
205+
original = original_ref
204206
))
205207
}
206208

@@ -226,7 +228,7 @@ parse_remote_ref <- function(ref) {
226228
repo = ref,
227229
ref = commit_ref,
228230
subdir = NULL,
229-
original = ref
231+
original = original_ref
230232
))
231233
}
232234

@@ -262,7 +264,7 @@ parse_remote_ref <- function(ref) {
262264
repo = ref,
263265
ref = commit_ref,
264266
subdir = NULL,
265-
original = ref
267+
original = original_ref
266268
))
267269
}
268270

@@ -281,7 +283,7 @@ parse_remote_ref <- function(ref) {
281283
repo = repo,
282284
ref = commit_ref,
283285
subdir = subdir,
284-
original = ref
286+
original = original_ref
285287
)
286288
}
287289

@@ -299,33 +301,65 @@ build_pak_remote_ref <- function(parsed) {
299301
if (!is.null(parsed$subdir)) {
300302
ref <- paste0(ref, "/", parsed$subdir)
301303
}
304+
if (!is.null(parsed$ref)) {
305+
ref <- paste0(ref, "@", parsed$ref)
306+
}
302307
ref
303308
},
304309
gitlab = {
305310
ref <- sprintf("gitlab::%s/%s", parsed$user, parsed$repo)
306311
if (!is.null(parsed$subdir)) {
307312
ref <- paste0(ref, "/-/", parsed$subdir)
308313
}
314+
if (!is.null(parsed$ref)) {
315+
ref <- paste0(ref, "@", parsed$ref)
316+
}
317+
ref
318+
},
319+
bioc = {
320+
# bioc:: refs are built from repo and ref to ensure correctness
321+
# even if original was missing the prefix.
322+
ref <- sprintf("bioc::%s", parsed$repo)
323+
if (!is.null(parsed$ref)) {
324+
ref <- paste0(ref, "@", parsed$ref)
325+
}
309326
ref
310327
},
311-
bioc = sprintf("bioc::%s", parsed$repo),
312-
git = sprintf("git::%s", parsed$original),
328+
git = {
329+
# For git:: we just use the original untouched string if it has the prefix
330+
if (grepl("^git::", parsed$original)) {
331+
parsed$original
332+
} else {
333+
ref <- sprintf("git::%s", parsed$original)
334+
if (!is.null(parsed$ref)) {
335+
ref <- paste0(ref, "@", parsed$ref)
336+
}
337+
ref
338+
}
339+
},
313340
bitbucket = {
314341
# Backward compatibility: translate bitbucket:: to git:: URL
315342
ref <- sprintf("git::https://bitbucket.org/%s/%s.git", parsed$user, parsed$repo)
316343
if (!is.null(parsed$subdir)) {
317344
warning("Subdirectories are not supported for Bitbucket legacy references. Using repository root.")
318345
}
346+
if (!is.null(parsed$ref)) {
347+
ref <- paste0(ref, "@", parsed$ref)
348+
}
319349
ref
320350
},
321351
# Transparent pass-through for other pak types
322-
sprintf("%s::%s", parsed$type, parsed$original)
352+
if (grepl(paste0("^", parsed$type, "::"), parsed$original)) {
353+
parsed$original
354+
} else {
355+
ref <- sprintf("%s::%s", parsed$type, parsed$original)
356+
if (!is.null(parsed$ref)) {
357+
ref <- paste0(ref, "@", parsed$ref)
358+
}
359+
ref
360+
}
323361
)
324362

325-
if (!is.null(parsed$ref)) {
326-
pak_ref <- paste0(pak_ref, "@", parsed$ref)
327-
}
328-
329363
pak_ref
330364
}
331365

@@ -413,7 +447,7 @@ parse_remote_url <- function(url) {
413447
"ci", "build", "perf", "style", "revert",
414448
"renovate", "dependabot"
415449
)
416-
is_version_tag <- grepl("^v?\\d+(\\Dots+)*([._-][A-Za-z0-9.+-]+)?$", ref_parts[1])
450+
is_version_tag <- grepl("^v?\\d+(\\.\\d+)*([._-][A-Za-z0-9.+-]+)?$", ref_parts[1])
417451

418452
if (ref_parts[1] %in% common_branches || is_version_tag) {
419453
ref <- ref_parts[1]

tests/testthat/test-remote.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ test_that("parse_remote_url parses GitHub URLs correctly", {
280280
p <- parse_remote_url("https://github.com/user/repo/tree/v1.2.3/pkg")
281281
expect_equal(p$ref, "v1.2.3")
282282
expect_equal(p$subdir, "pkg")
283+
284+
p <- parse_remote_url("https://github.com/user/repo/tree/v1.2.3.4/pkg")
285+
expect_equal(p$ref, "v1.2.3.4")
283286
})
284287

285288
test_that("parse_remote_url parses GitLab URLs correctly", {
@@ -444,6 +447,18 @@ test_that("parse_remote_url handles generic URLs as git::", {
444447
expect_equal(p$original, "https://example.com/repo.git")
445448
})
446449

450+
test_that("parse_remote_ref preserves original reference with prefix and ref", {
451+
p <- parse_remote_ref("bioc::Biobase@RELEASE_3_18")
452+
expect_equal(p$original, "bioc::Biobase@RELEASE_3_18")
453+
expect_equal(remote_display_name(p), "bioc::Biobase@RELEASE_3_18")
454+
455+
p2 <- parse_remote_ref("github::user/repo@main")
456+
expect_equal(p2$original, "github::user/repo@main")
457+
458+
p3 <- parse_remote_ref("user/repo/subdir@v1.0.0")
459+
expect_equal(p3$original, "user/repo/subdir@v1.0.0")
460+
})
461+
447462
test_that("remote_display_name handles NA users and original refs", {
448463
p <- list(type = "git", original = "https://example.com/repo", user = NA_character_)
449464
expect_equal(remote_display_name(p), "https://example.com/repo")

tests/testthat/test-to_txt.R

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,14 @@ test_that(
361361

362362
fake_rdd_extract_code_spy <- function(
363363
pkg,
364-
file,
365-
include_tests,
366-
include_roxygen,
367-
force_fetch,
368-
version,
369-
cache_path,
370-
keep_files
364+
file = NULL,
365+
include_tests = FALSE,
366+
include_roxygen = FALSE,
367+
force_fetch = FALSE,
368+
version = NULL,
369+
cache_path = getOption("rdocdump.cache_path"),
370+
keep_files = "none",
371+
...
371372
) {
372373
calls$rdd_force_fetch <- force_fetch
373374
"CODE"
@@ -428,13 +429,14 @@ test_that(
428429

429430
fake_rdd_extract_code_spy <- function(
430431
pkg,
431-
file,
432-
include_tests,
433-
include_roxygen,
434-
force_fetch,
435-
cache_path,
436-
version,
437-
keep_files
432+
file = NULL,
433+
include_tests = FALSE,
434+
include_roxygen = FALSE,
435+
force_fetch = FALSE,
436+
version = NULL,
437+
cache_path = getOption("rdocdump.cache_path"),
438+
keep_files = "none",
439+
...
438440
) {
439441
calls$rdd_force_fetch <- force_fetch
440442
"CODE"

0 commit comments

Comments
 (0)