Trying to install an R Package from a git repo hosted on TFS 2015 using the following R Code
install.packages("devtools")
creds <- git2r::cred_user_pass("AD_USER_ID", "password")
url <- "http://tfs_server/tfs/Collection/Project/_git/RepoName"
devtools::install_git(url, build_vignettes = TRUE, credentials = creds)
Executing the above results in
Downloading git repo http://tfs_server/tfs/Collection/Project/_git/RepoName
Installation failed: Error in 'git2r_clone': unexpected HTTP status code: 401
I have verified I can clone the repo from command line using the credentials.
Also tried
url <- "http://AD_USER_ID:password@tfs_server/tfs/Collection/Project/_git/RepoName"
Based on @Dason's suggestion tried
git2r::clone(url, local_path="./Test", credentials = creds)
and got
cloning into './Test'...
Error in git2r::clone(url, local_path = "./Test", credentials = cred) :
Error in 'git2r_clone': unexpected HTTP status code: 401
Looks like git2r is unable to pass the creds to the server
How do I pass the credentials?
One way you could pull a repo hosted on TFS using R and devtools::install_git() on Windows is through SSH. This assumes you have installed Git for Windows .
Everything works as expected from Git Bash using Git, however the shell in a typical R environment is set differently than the one in Git Bash.
In order for devtools::install_git() to work with TFS, some environment variables must be set first.
# Let SSH know about our SSH config
# if needed, change paths accordingly
Sys.setenv("GIT_SSH_COMMAND" = sprintf("C:/Users/%s/AppData/Local/Programs/Git/usr/bin/ssh.exe -F C:/Users/%s/.ssh/config",
Sys.getenv("USERNAME"),
Sys.getenv("USERNAME")))
# Add R postback to PATH so that any prompts are redirected back at the user
Sys.setenv("PATH" = paste0(Sys.getenv("PATH"),
";C:\\Program Files\\RStudio\\bin\\postback"))
ssh_url <- "ssh://tfs_server:22/tfs/Collection/Project/_git/RepoName"
# This works after setting environment variables GIT_SSH_COMMAND and PATH
devtools::install_git(ssh_url, git = "external")
Then I added the following lines to my ssh config file (located in C:\\Users\\%username%\\.ssh) in order to inform SSH about my username and private key file:
Host tfs_server
# you can optionally specify the key exchange algorithm
# see more at: https://www.ssh.com/academy/ssh/sshd_config#cryptographic-policy
# KexAlgorithms SPECIFY_KEX_ALGORITHM
User YOUR_TFS_USER_NAME
Hostname tfs_server
# it is a good idea to apply stricter permissions
# to your private key: chmod 400 ~/.ssh/id_rsa
IdentityFile C:/Users/YOUR_USER_NAME/.ssh/id_rsa
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.