Skip to content
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: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
- When restoring GitHub-hosted packages, packrat will now look for both
`Github*` and `Remote*` fields to determine where to install from. (#740)

- When restoring packages from CRAN-like repositories, names are no
longer used to detect if these are actually git-like. This prevents
issues if you name a CRAN-like repository something like "GitHub". (#747)

# packrat 0.9.3

- Update vendored `renv` with support for additional Linux distributions when
Expand Down
9 changes: 7 additions & 2 deletions R/restore.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ isFromCranlikeRepo <- function(pkgRecord, repos) {
return(TRUE)
}

# for records that do declare a source, ensure it's not 'source', 'github', 'bitbucket', or 'gitlab'.
# check if there's a remote host and repo for github, bitbucket, or gitlab
if (!is.null(pkgRecord$remote_host) && !is.null(pkgRecord$remote_repo)) {
return(FALSE)
}

# for records that do declare a source, ensure it's not 'source'.
# in previous releases of packrat, we attempted to match the repository name
# with one of the existing repositories; however, this caused issues in
# certain environments (the names declared repositories in the lockfile, and
# the the names of the active repositories in the R session, may not match)
!tolower(source) %in% c("source", "github", "bitbucket", "gitlab")
!tolower(source) %in% c("source")
}

# Given a package record and a database of packages, check to see if
Expand Down
89 changes: 89 additions & 0 deletions tests/testthat/test-restore.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,92 @@ test_that("appendRemoteInfoToDescription uses RemoteSubdir", {
desc <- readLines(file.path(dest_dir, "toast", "DESCRIPTION"))
expect_true("RemoteSubdir: toast" %in% desc)
})

test_that("isFromCranlikeRepo returns TRUE for CRAN source", {
pkgRecord <- list(
name = "ggplot2",
source = "CRAN",
version = "3.4.0"
)

repos <- c(CRAN = "https://cran.r-project.org")

expect_true(isFromCranlikeRepo(pkgRecord, repos))
})

test_that("isFromCranlikeRepo returns TRUE for CustomCRANLikeRepository class", {
pkgRecord <- structure(
list(
name = "ggplot2",
source = "CRAN",
version = "3.4.0"
),
class = c("packageRecord", "CustomCRANLikeRepository")
)

repos <- c(CRAN = "https://cran.r-project.org")

expect_true(isFromCranlikeRepo(pkgRecord, repos))
})

test_that("isFromCranlikeRepo returns FALSE for source package", {
pkgRecord <- list(
name = "mypackage",
source = "source",
version = "1.0.0"
)

repos <- c(CRAN = "https://cran.r-project.org")

expect_false(isFromCranlikeRepo(pkgRecord, repos))
})

test_that("isFromCranlikeRepo returns FALSE if remote_repo/remote_host are present", {
pkgRecord <- list(
name = "mypackage",
source = "GitHub",
version = "1.0.0",
remote_host = "github.com",
remote_repo = "mypackage"
)

repos <- c(GitHub = "https://github.com/me/mypackage")

expect_false(isFromCranlikeRepo(pkgRecord, repos))
})

test_that("isFromCranlikeRepo returns TRUE for BioConductor source", {
pkgRecord <- list(
name = "GenomicRanges",
source = "Bioconductor",
version = "1.50.0"
)

repos <- c(BioCsoft = "https://bioconductor.org/packages/3.16/bioc")

expect_true(isFromCranlikeRepo(pkgRecord, repos))
})

test_that("isFromCranlikeRepo returns TRUE for custom repository source", {
pkgRecord <- list(
name = "mypackage",
source = "MyRepo",
version = "1.0.0"
)

repos <- c(MyRepo = "https://example.com/repo")

expect_true(isFromCranlikeRepo(pkgRecord, repos))
})

test_that("isFromCranlikeRepo returns TRUE for a CRAN-like source named Github", {
pkgRecord <- list(
name = "mypackage",
source = "GitHub",
version = "1.0.0"
)

repos <- c(GitHub = "https://example.com/repo")

expect_true(isFromCranlikeRepo(pkgRecord, repos))
})