Skip to content

Commit 8be367f

Browse files
jonkeanegithub-actions[bot]karawoo
authored
Use URLs to detect git-like repos rather than name (#748)
* a failing unit test * Use repo URL, not repo name to detect git-like repos. * Update R/restore.R Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update R/restore.R Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update tests/testthat/test-restore.R Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Slightly nicer URL sniffers * Use the presence of remote host and repo for determining that a repo is git-like * Update tests/testthat/test-restore.R Co-authored-by: Kara Woo <karawoo@users.noreply.github.com> * add news --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Kara Woo <karawoo@users.noreply.github.com>
1 parent 52a809d commit 8be367f

File tree

3 files changed

+100
-2
lines changed

3 files changed

+100
-2
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
- When restoring GitHub-hosted packages, packrat will now look for both
44
`Github*` and `Remote*` fields to determine where to install from. (#740)
55

6+
- When restoring packages from CRAN-like repositories, names are no
7+
longer used to detect if these are actually git-like. This prevents
8+
issues if you name a CRAN-like repository something like "GitHub". (#747)
9+
610
# packrat 0.9.3
711

812
- Update vendored `renv` with support for additional Linux distributions when

R/restore.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@ isFromCranlikeRepo <- function(pkgRecord, repos) {
2525
return(TRUE)
2626
}
2727

28-
# for records that do declare a source, ensure it's not 'source', 'github', 'bitbucket', or 'gitlab'.
28+
# check if there's a remote host and repo for github, bitbucket, or gitlab
29+
if (!is.null(pkgRecord$remote_host) && !is.null(pkgRecord$remote_repo)) {
30+
return(FALSE)
31+
}
32+
33+
# for records that do declare a source, ensure it's not 'source'.
2934
# in previous releases of packrat, we attempted to match the repository name
3035
# with one of the existing repositories; however, this caused issues in
3136
# certain environments (the names declared repositories in the lockfile, and
3237
# the the names of the active repositories in the R session, may not match)
33-
!tolower(source) %in% c("source", "github", "bitbucket", "gitlab")
38+
!tolower(source) %in% c("source")
3439
}
3540

3641
# Given a package record and a database of packages, check to see if

tests/testthat/test-restore.R

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,92 @@ test_that("appendRemoteInfoToDescription uses RemoteSubdir", {
150150
desc <- readLines(file.path(dest_dir, "toast", "DESCRIPTION"))
151151
expect_true("RemoteSubdir: toast" %in% desc)
152152
})
153+
154+
test_that("isFromCranlikeRepo returns TRUE for CRAN source", {
155+
pkgRecord <- list(
156+
name = "ggplot2",
157+
source = "CRAN",
158+
version = "3.4.0"
159+
)
160+
161+
repos <- c(CRAN = "https://cran.r-project.org")
162+
163+
expect_true(isFromCranlikeRepo(pkgRecord, repos))
164+
})
165+
166+
test_that("isFromCranlikeRepo returns TRUE for CustomCRANLikeRepository class", {
167+
pkgRecord <- structure(
168+
list(
169+
name = "ggplot2",
170+
source = "CRAN",
171+
version = "3.4.0"
172+
),
173+
class = c("packageRecord", "CustomCRANLikeRepository")
174+
)
175+
176+
repos <- c(CRAN = "https://cran.r-project.org")
177+
178+
expect_true(isFromCranlikeRepo(pkgRecord, repos))
179+
})
180+
181+
test_that("isFromCranlikeRepo returns FALSE for source package", {
182+
pkgRecord <- list(
183+
name = "mypackage",
184+
source = "source",
185+
version = "1.0.0"
186+
)
187+
188+
repos <- c(CRAN = "https://cran.r-project.org")
189+
190+
expect_false(isFromCranlikeRepo(pkgRecord, repos))
191+
})
192+
193+
test_that("isFromCranlikeRepo returns FALSE if remote_repo/remote_host are present", {
194+
pkgRecord <- list(
195+
name = "mypackage",
196+
source = "GitHub",
197+
version = "1.0.0",
198+
remote_host = "github.com",
199+
remote_repo = "mypackage"
200+
)
201+
202+
repos <- c(GitHub = "https://github.com/me/mypackage")
203+
204+
expect_false(isFromCranlikeRepo(pkgRecord, repos))
205+
})
206+
207+
test_that("isFromCranlikeRepo returns TRUE for BioConductor source", {
208+
pkgRecord <- list(
209+
name = "GenomicRanges",
210+
source = "Bioconductor",
211+
version = "1.50.0"
212+
)
213+
214+
repos <- c(BioCsoft = "https://bioconductor.org/packages/3.16/bioc")
215+
216+
expect_true(isFromCranlikeRepo(pkgRecord, repos))
217+
})
218+
219+
test_that("isFromCranlikeRepo returns TRUE for custom repository source", {
220+
pkgRecord <- list(
221+
name = "mypackage",
222+
source = "MyRepo",
223+
version = "1.0.0"
224+
)
225+
226+
repos <- c(MyRepo = "https://example.com/repo")
227+
228+
expect_true(isFromCranlikeRepo(pkgRecord, repos))
229+
})
230+
231+
test_that("isFromCranlikeRepo returns TRUE for a CRAN-like source named Github", {
232+
pkgRecord <- list(
233+
name = "mypackage",
234+
source = "GitHub",
235+
version = "1.0.0"
236+
)
237+
238+
repos <- c(GitHub = "https://example.com/repo")
239+
240+
expect_true(isFromCranlikeRepo(pkgRecord, repos))
241+
})

0 commit comments

Comments
 (0)