簡體   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