Skip to content

Commit 5d25c3b

Browse files
committed
Use credentials in install_git when using git2r
Fixes #106
1 parent c1d9e0f commit 5d25c3b

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
# Development
77

8+
* `install_git()` now supports passing credentials, when it is used with `git =
9+
"git2r"` (#106)
10+
11+
* `install_()` functions now pass arguments, including authentication
12+
information and upgrade down to dependencies (#53, #86, #87).
13+
814
* `install_()` functions now return the name of the package(s) which were
915
installed (#55).
1016

R/install-git.R

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#' @param branch Name of branch, tag or SHA reference to use, if not HEAD.
1111
#' @param subdir A sub-directory within a git repository that may
1212
#' contain the package we are interested in installing.
13+
#' @param credentials A git2r credentials object passed through to clone.
14+
#' Supplying this argument implies using \code{git2r} with \code{git}.
1315
#' @param git Whether to use the \code{git2r} package, or an external
1416
#' git client via system. Default is \code{git2r} if it is installed,
1517
#' otherwise an external git installation.
@@ -20,34 +22,43 @@
2022
#' install_git("git://github.com/hadley/stringr.git")
2123
#' install_git("git://github.com/hadley/stringr.git", branch = "stringr-0.2")
2224
#'}
23-
install_git <- function(url, subdir = NULL, branch = NULL,
25+
install_git <- function(url, subdir = NULL, branch = NULL, credentials = NULL,
2426
git = c("auto", "git2r", "external"), ...) {
2527

26-
remotes <- lapply(url, git_remote, subdir = subdir, branch = branch, git = match.arg(git))
27-
install_remotes(remotes, ...)
28+
remotes <- lapply(url, git_remote, subdir = subdir, branch = branch,
29+
credentials = credentials, git = match.arg(git))
30+
31+
install_remotes(remotes, credentials = credentials, ...)
2832
}
2933

3034

31-
git_remote <- function(url, subdir = NULL, branch = NULL, git = c("auto", "git2r", "external")) {
35+
git_remote <- function(url, subdir = NULL, branch = NULL, credentials = NULL,
36+
git = c("auto", "git2r", "external")) {
37+
3238
git <- match.arg(git)
3339
if (git == "auto") {
3440
git <- if (pkg_installed("git2r")) "git2r" else "external"
3541
}
3642

37-
list(git2r = git_remote_git2r, external = git_remote_xgit)[[git]](url, subdir, branch)
43+
if (!is.null(credentials) && git != "git2r") {
44+
stop("`credentials` can only be used with `git = \"git2r\"`", call. = FALSE)
45+
}
46+
47+
list(git2r = git_remote_git2r, external = git_remote_xgit)[[git]](url, subdir, branch, credentials)
3848
}
3949

4050

41-
git_remote_git2r <- function(url, subdir = NULL, branch = NULL) {
51+
git_remote_git2r <- function(url, subdir = NULL, branch = NULL, credentials = NULL) {
4252
remote("git2r",
4353
url = url,
4454
subdir = subdir,
45-
branch = branch
55+
branch = branch,
56+
credentials = credentials
4657
)
4758
}
4859

4960

50-
git_remote_xgit <- function(url, subdir = NULL, branch = NULL) {
61+
git_remote_xgit <- function(url, subdir = NULL, branch = NULL, credentials = NULL) {
5162
remote("xgit",
5263
url = url,
5364
subdir = subdir,
@@ -62,7 +73,7 @@ remote_download.git2r_remote <- function(x, quiet = FALSE) {
6273
}
6374

6475
bundle <- tempfile()
65-
git2r::clone(x$url, bundle, progress = FALSE)
76+
git2r::clone(x$url, bundle, credentials = x$credentials, progress = FALSE)
6677

6778
if (!is.null(x$branch)) {
6879
r <- git2r::repository(bundle)

man/install_deps.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/install_git.Rd

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/package_deps.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)