繁体   English   中英

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

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

尝试使用以下 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)

执行上面的结果

Downloading git repo http://tfs_server/tfs/Collection/Project/_git/RepoName
Installation failed: Error in 'git2r_clone': unexpected HTTP status code: 401

我已经验证我可以使用凭据从命令行克隆 repo。

也试过

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

根据@Dason 的建议尝试

git2r::clone(url, local_path="./Test", credentials = creds)

并得到

cloning into './Test'...
Error in git2r::clone(url, local_path = "./Test", credentials = cred) : 
  Error in 'git2r_clone': unexpected HTTP status code: 401

看起来 git2r 无法将凭据传递给服务器

我如何通过凭据?

在 Windows 上使用 R 和devtools::install_git()拉取托管在 TFS 上的存储库的一种方法是通过 SSH。 这假设您已经安装了适用于 Windows 的 Git

使用 Git 在 Git Bash 中一切都按预期工作,但是典型 R 环境中的 shell 设置与 Git Bash 中的不同。

为了让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")

然后我将以下几行添加到我的 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