Trouble with credentials in usethis::pr_init()

I'm attempting to explore the pr_* functions from package usethis following along with the pull request article but I've run into some trouble with credentials. It feels like something simple but I haven't figure it out on either of my computers.

I did some initial set-up, getting my GitHub PAT and such into .Renviron following the usethis setup article. I use SSH transport protocol for Git, which has been set up for a while but I found I needed to copy my public key into my GitHub account again to get things working.

I'm on a Windows 7 machine, so the default NULL credentials for SSH don't work out of the box but git2r::cred_ssh_key() returns the correct information so to fork and clone I do

library(usethis)
use_git_credentials(credentials = git2r::cred_ssh_key())
create_from_github("aosmith16/data-manipulation-workshop")

✔ Creating 'C:/Users/muldoona/Desktop/data-manipulation-workshop/'
✔ Cloning repo from 'git@github.com:aosmith16/data-manipulation-workshop.git' into 'C:/Users/muldoona/Desktop/data-manipulation-workshop'
✔ Setting active project to 'C:/Users/muldoona/Desktop/data-manipulation-workshop'
✔ Opening 'C:/Users/muldoona/Desktop/data-manipulation-workshop/' in new RStudio session
✔ Setting active project to '<no active project>'

So that looks OK to me. I switch over to the new instance of RStudio with that project.

Following along with the article, I now want to use pr_init() to make a new branch. I again set my credentials but this time I get an authentication error when using pr_init() (I get the same error if I don't set credentials):

library(usethis)

use_git_credentials(credentials = git2r::cred_ssh_key())
pr_init(branch = "testbranch")
✔ Checking that local branch 'master' has the changes in 'origin/master'
Error in git2r::fetch(repo, name = remref_remote(remref), refspec = branch,  : 
  Error in 'git2r_remote_fetch': error authenticating: failed connecting agent

I can reproduce the error if I use git2r::fetch() with no credentials set. Like

git2r::fetch(".", name = "origin")
Error in git2r::fetch(".", name = "origin") : 
  Error in 'git2r_remote_fetch': error authenticating: failed connecting agent

If I manually set credentials in git2r::fetch() it doesn't give an error.

git2r::fetch(".", name = "origin", credentials = git2r::cred_ssh_key())

I'm playing around with one of my own repositories, but the same thing happens with the rladies/praise repo from the pull request article.

I've got the latest development versions of usethis and git2r, I've searched error messages and such and have now run out of ideas. :thinking: Can anyone see what I'm missing here?

1 Like

It turned out there was a bug in git2r::fetch() without credentials in functions used within pr_init(). You can see the usethis GitHub issue and conversation here.

If anyone else runs into this, it is now fixed in the development version of usethis

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.