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

Fix regex that broke git@xxx in install-git #630

Merged
merged 2 commits into from
Jun 23, 2021
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# remotes (development version)

* Fix regex that breaks git protocol in `git_remote` (@niheaven #630).

# remotes 2.4.0

* Re-license as MIT. (#551)
Expand Down
2 changes: 1 addition & 1 deletion R/install-git.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ git_remote <- function(url, subdir = NULL, ref = NULL, credentials = git_credent
stop("`credentials` can only be used with `git = \"git2r\"`", call. = FALSE)
}

meta <- re_match(url, "(?:(?<url>[^@]*))(?:@(?<ref>.*))?")
meta <- re_match(url, "(?<url>(?:git@)?[^@]*)(?:@(?<ref>.*))?")
ref <- ref %||% (if (meta$ref == "") NULL else meta$ref)

list(git2r = git_remote_git2r, external = git_remote_xgit)[[git]](meta$url, subdir, ref, credentials)
Expand Down
2 changes: 1 addition & 1 deletion inst/install-github.R

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

2 changes: 1 addition & 1 deletion install-github.R

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

30 changes: 30 additions & 0 deletions tests/testthat/test-install-git.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,35 @@ test_that("install_git with command line git and full SHA ref", {
expect_true(!is.na(remote$sha) && nzchar(remote$sha))
})

test_that("git_remote returns the url", {

skip_on_cran()

# works without ref
url <- "https://github.com/cran/falsy.git"
remote <- git_remote(url)
expect_equal(remote$url, "https://github.com/cran/falsy.git")

# works with ref
url <- "https://github.com/cran/falsy.git@master"
remote <- git_remote(url)
expect_equal(remote$url, "https://github.com/cran/falsy.git")
expect_equal(remote$ref, "master")

# works without ref (git protocol)
url <- "git@github.com:cran/falsy.git"
remote <- git_remote(url)
expect_equal(remote$url, "git@github.com:cran/falsy.git")

# works with ref (git protocal)
url <- "git@github.com:cran/falsy.git@master"
remote <- git_remote(url)
expect_equal(remote$url, "git@github.com:cran/falsy.git")
expect_equal(remote$ref, "master")
})

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

skip_on_cran()
skip_if_offline()
skip_if_not_installed("git2r")
Expand All @@ -168,6 +196,7 @@ test_that("remote_package_name.git2r_remote returns the package name if it exist
})

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

skip_on_cran()
skip_if_offline()
if (is.null(git_path())) skip("git is not installed")
Expand All @@ -189,6 +218,7 @@ test_that("remote_package_name.xgit_remote returns the package name if it exists
})

test_that("remote_sha.xgit remote returns the SHA if it exists", {

skip_on_cran()
skip_if_offline()
if (is.null(git_path())) skip("git is not installed")
Expand Down