简体   繁体   English

您如何将 R devtools::install_git 与 TFS 托管的 Git Repo 一起使用?

[英]How do you use R devtools::install_git with TFS hosted Git Repo?

Trying to install an R Package from a git repo hosted on TFS 2015 using the following R Code尝试使用以下 R 代码从托管在 TFS 2015 上的 git 存储库安装 R 包

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.我已经验证我可以使用凭据从命令行克隆 repo。

Also tried也试过

url <- "http://AD_USER_ID:password@tfs_server/tfs/Collection/Project/_git/RepoName" 

Based on @Dason's suggestion tried根据@Dason 的建议尝试

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看起来 git2r 无法将凭据传递给服务器

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.在 Windows 上使用 R 和devtools::install_git()拉取托管在 TFS 上的存储库的一种方法是通过 SSH。 This assumes you have installed Git for Windows .这假设您已经安装了适用于 Windows 的 Git

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.使用 Git 在 Git Bash 中一切都按预期工作,但是典型 R 环境中的 shell 设置与 Git Bash 中的不同。

In order for devtools::install_git() to work with TFS, some environment variables must be set first.为了让devtools::install_git()与 TFS 一起工作,必须首先设置一些环境变量。

# 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:然后我将以下几行添加到我的 ssh 配置文件(位于 C:\\Users\\%username%\\.ssh)中,以便将我的用户名和私钥文件通知 SSH:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM