git2r
git2r copied to clipboard
Windows issue with git2r
I'm using Windows 10, and follow all the instructions in happy git with r to set up Git for Windows, SSH key with passphrase and everything.
It works great on both Rstudio's terminal (git add, commit, push) and Rstudio's git pane user interface (push pull button).
However, when it comes to using git2r package, it just doesn't work. I read up many solutions here, here, here, here but no help.
Basically things I have tried
- setting git2r::cred_ssh_key
- symbolic link
- package getPass not working (no pop up window to promp passphrase)
- follow the instructions on happy-git-with-r, researching the issue around and tweaking here and there
Repro here
This same repo successfully run using Rstudio UI (pull, commit and push button)
This same repo successfully run using Rstudio terminal
# do stuffs like editing a file or adding files
git add -A
git commit -m 'test commit'
# [master 3f75958] a
# 1 file changed, 1 insertion(+), 1 deletion(-)
git push
# warning: agent returned different signature type ssh-rsa (expected rsa-sha2-
# 512)
# Enumerating objects: 7, done.
# Counting objects: 100% (7/7), done.
# Delta compression using up to 8 threads
# Compressing objects: 100% (4/4), done.
# Writing objects: 100% (5/5), 471 bytes | 157.00 KiB/s, done.
# Total 5 (delta 2), reused 0 (delta 0)
# remote: Resolving deltas: 100% (2/2), completed with 1 local object.
# To github.com:<my_username>/<my_repo>.git
# 082f4f2..3f75958 master -> master
I am not sure what's the warning about but everything went through succesfully everytime without prompting any passphrase thanks to the great instructions provided in happy git with r. The UI and terminal approaches have been working for a few days with no problem at all.
However, when using git2r
library(usethis)
library(git2r)
repo = repository(proj_get())
cred = cred_ssh_key(
publickey = "~/../.ssh/id_rsa.pub",
privatekey = "~/../.ssh/id_rsa"
)
write.csv("sample text", "sample.txt")
add(repo, "sample.txt")
commit(repo, "initial commit")
push(repo)
# Error in push(repo) :
# Error in 'git2r_push': error authenticating: failed connecting agent
push(repo, credentials = cred)
# Rstudio took about 3 minutes to return the error below which is unusual given the UI and terminal # successfully run almost instantaneously
# Error in push(repo, credentials = cred) :
# Error in 'git2r_push': Failed to authenticate SSH session: Unable to send userauth-publickey request
library(getPass)
push(repo, credentials = cred)
# Rstudio took about 3 minutes to return the error below which is unusual given the UI and terminal # successfully run almost instantaneously
# Error in push(repo, credentials = cred) :
# Error in 'git2r_push': Failed to authenticate SSH session: Unable to send userauth-publickey request
# -----------------------------------------------
# Potential issues?????
Sys.getenv('HOME')
# [1] "C:/Users/<username>/Documents"
Sys.getenv('USERPROFILE')
# [1] "C:\\Users\\<username>"
list.files(
Sys.getenv('USERPROFILE'),
all.files = TRUE,
pattern = 'git|ssh'
)
# [1] ".gitconfig" ".lesshst" ".ssh"
# my .ssh symbolic link
list.files(
Sys.getenv('HOME'),
all.files = TRUE,
pattern = 'git|ssh'
)
# [1] ".ssh"
libgit2_features()
# $threads
# [1] FALSE
#
# $https
# [1] TRUE
#
# $ssh
# [1] TRUE
Sys.getenv("SSH_ASKPASS")
# [1] ""
Sys.getenv("GIT_ASKPASS")
# [1] ""
git2r::config()
# programdata:
# color.branch=auto
# color.diff=auto
# color.interactive=true
# color.status=auto
# core.autocrlf=true
# core.fscache=true
# core.symlinks=false
# help.format=html
# rebase.autosquash=true
# global:
# core.autocrlf=true
# core.editor=code-insiders --wait --new-window
# core.sshcommand=C:/Windows/System32/OpenSSH/ssh.exe
# diff.tool=default-difftool
# difftool.default-difftool.cmd=code --wait --diff $LOCAL $REMOTE
# difftool.sourcetree.cmd='' "$LOCAL" "$REMOTE"
# filter.lfs.clean=git-lfs clean -- %f
# filter.lfs.process=git-lfs filter-process
# filter.lfs.required=true
# filter.lfs.smudge=git-lfs smudge -- %f
# mergetool.sourcetree.cmd=''
# mergetool.sourcetree.trustexitcode=true
# push.default=current
# user.email=<my_email>
# user.name=<my_username>
# local:
# branch.master.merge=refs/heads/master
# branch.master.remote=origin
# core.bare=false
# core.filemode=false
# core.ignorecase=true
# core.logallrefupdates=true
# core.repositoryformatversion=0
# core.symlinks=false
# remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
# [email protected]:<my_username>/<my_repo>.git
I don't have any experience dealing with git and SSH before. I am doing hard researching the issue here and there but it just doesn't work.
Does it work if you use an SSH key without a passphrase?
@stewid Thank you for responding. It works if I use a SSH key without passphrase. Here is what I did
-
Remove my SSH key with passphrase from "~/../.ssh/"
-
Follow the instructions on happy git with r and setup and add SSH key without passphrase using Rstudio's built-in Git Shell terminal
-
Successfully pushed using both Rstudio's terminal and UI pull/push buttons
-
Successfully pushed using git2r (same codes as above)
library(usethis)
library(git2r)
repo = repository(proj_get())
cred = cred_ssh_key(
publickey = "~/../.ssh/id_rsa.pub",
privatekey = "~/../.ssh/id_rsa"
)
write.csv("haha", "sample.txt")
add(repo, "sample.txt")
commit(repo, "another commit")
push(repo)
# Error in push(repo) :
# Error in 'git2r_push': error authenticating: failed connecting agent
push(repo, credentials = cred)
Push is done. Tested several times.
Please advise on the issue with using SSH with passphrase. Thank you.