【问题标题】:How do you use R devtools::install_git with TFS hosted Git Repo?您如何将 R devtools::install_git 与 TFS 托管的 Git Repo 一起使用?
【发布时间】:2019-06-02 07:36:14
【问题描述】:

尝试使用以下 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 无法将凭据传递给服务器

如何传递凭据?

【问题讨论】:

  • 你说你可以在命令行克隆 - 你可以使用 git2r::clone 克隆并以这种方式传递凭据吗?我的猜测是“不”,这是导致问题的原因,但最好找到问题的实际根源。
  • @Dason auth 再次出错 git2r::clone(url, local_path = ".Test", credentials = cred) 中的错误:'git2r_clone' 中的错误:意外的 HTTP 状态代码:401

标签: r git tfs


【解决方案1】:

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

使用 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

【讨论】:

    猜你喜欢
    • 2013-11-17
    • 2019-02-08
    • 2016-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-22
    • 2014-08-29
    • 1970-01-01
    相关资源
    最近更新 更多