Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding error handling to git_remote http requests (Resolves #625) #628

Merged
merged 6 commits into from
Jul 9, 2021
Merged
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: remotes
Title: R Package Installation from Remote Repositories, Including 'GitHub'
Version: 2.4.0.9000
Version: 2.4.0.9001
Authors@R: c(
person("Jim", "Hester", , "jim.hester@rstudio.com", role = c("aut", "cre")),
person("Gábor", "Csárdi", , "csardi.gabor@gmail.com", role = c("aut")),
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# remotes (development version)

* Using `remote_package_name.git2r_remote` and `remote_package_name.xgit_remote`, http responses returning an invalid `DESCRIPTION` or that redirect to another page will now fallback to return `NA` instead of throwing an error when trying to parse the unexpected content (#628, @dgkf).
* Fix regex that breaks git protocol in `git_remote` (@niheaven #630).

# remotes 2.4.0
9 changes: 7 additions & 2 deletions R/install-git.R
Original file line number Diff line number Diff line change
@@ -146,9 +146,14 @@ remote_package_name.git2r_remote <- function(remote, ...) {
description_path <- paste0(collapse = "/", c(remote$subdir, "DESCRIPTION"))

if (grepl("^https?://", remote$url)) {
# assumes GitHub-style "<repo>/raw/<ref>/<path>" url
url <- build_url(sub("\\.git$", "", remote$url), "raw", remote_sha(remote, ...), description_path)
download(tmp, url)
read_dcf(tmp)$Package
tryCatch({
download(tmp, url)
read_dcf(tmp)$Package
}, error = function(e) {
NA_character_
})
} else {
# Try using git archive --remote to retrieve the DESCRIPTION, if the protocol
# or server doesn't support that return NA
9 changes: 7 additions & 2 deletions inst/install-github.R

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions install-github.R

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tests/testthat/test-install-git.R
Original file line number Diff line number Diff line change
@@ -193,6 +193,22 @@ test_that("remote_package_name.git2r_remote returns the package name if it exist
url <- "https://github.com/igraph/rigraph.git@master"
remote <- git_remote(url, git = "git2r")
expect_equal(remote_package_name(remote), "igraph")

# works for gitlab urls
url <- "https://gitlab.com/r-lib-grp/test-pkg.git"
remote <- git_remote(url, git = "git2r")
expect_equal(remote_package_name(remote), "test123")

# safely returns NA when DESCRIPTION url is not accessible
# (condition emitted due to inaccessible git remote for remote_sha during testing)
url <- "https://gitlab.com/r-lib-grp/fake-private-repo.git"
remote <- git_remote(url, git = "git2r")
err <- tryCatch(remote_sha(remote), error = function(e) e)
expect_error( # expect same error as calling remote_sha directly
expect_equal(remote_package_name(remote), NA_character_),
class = class(err),
label = conditionMessage(err)
)
})

test_that("remote_package_name.xgit_remote returns the package name if it exists", {