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.
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 )
0 commit comments