use_github("hadley/abc") #642
Comments
Why did I comment this code out? # git2r::branch_set_upstream(git2r::head(r), "origin/master")
# git2r::push(r, "origin", "refs/heads/master") |
The recent conversation probably already reminded you ... You probably commented this out because pushing and/or setting tracking branches with |
I have managed to add an existing project to GitHub using SSH and https with v0.11.0 of git2r. library(git2r)
## Add an existing project to GitHub using SSH and git2r. Create a new
## repository on GitHub before running the following R code.
## 1) Create a new repository
repo <- init("test-01")
## 2) Add 'README.md' to local repository
add(repo, "README.md")
## 3) Commit staged 'README.md'. Add sessionInfo to commit message
commit(repo, message = "Initial commit", session = TRUE)
## 4) Add URL for the remote repository
remote_add(repo, "origin", "git@github.com:stewid/test-01.git")
## 5) Create SSH credentials
cred <- cred_ssh_key("~/.ssh/id_rsa.pub", "~/.ssh/id_rsa")
## 6) Push changes in local repository to GitHub
push(repo, "origin", "refs/heads/master", credentials = cred) library(git2r)
## Add an existing project to GitHub using https and git2r. Create a
## new repository on GitHub before running the following R code.
## 1) Create a new repository
repo <- init("test-02")
## 2) Add 'README.md' to local repository
add(repo, "README.md")
## 3) Commit staged 'README.md'. Add sessionInfo to commit message
commit(repo, message = "Initial commit", session = TRUE)
## 4) Add URL for the remote repository
remote_add(repo, "origin", "https://github.com/stewid/test-02.git")
## 5) Create credentials from environmental variables
cred <- cred_env("GITHUB_USER", "GITHUB_PAT")
## 6) Push changes in local repository to GitHub
push(repo, "origin", "refs/heads/master", credentials = cred) sessionInfo: R version 3.2.2 RC (2015-08-08 r68921)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.3 LTS
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] git2r_0.11.0 |
I have done more testing on other platforms with git2r v0.11.0 to push a local repository to GitHub.
|
Thanks @stewid for the explicit example using I guess my hope was that my cached credentials that allow other pushes to "just work", from command line git or RStudio or SourceTree, would get picked up by |
Done in #901 |
@stewid Can you help me out here? I use I usually use https and can affirm that all is well with But the default protocol is ssh. I've now set up SSH keys in order to test Before I go there ... In your example above, are you using an SSH key without a passphrase? Or is your passphrase kept in a keychain or some such and Wondering if my ssh setup is somehow deficient or are we going to have handle the SSH passphrase somehow? |
OK here is the threatened/promised reprex. I assume you both use ssh? Like all the time? And your key has a passphrase? What happens for you? path <- "foo"
dir.create(path)
repo <- init(path)
writeLines("yada yada yada", file.path(path, "example.txt"))
add(repo, "example.txt")
commit(repo, "First commit message")
#> [b3de976] 2015-09-10: First commit message
req <-
httr::POST("https://api.github.com/user/repos",
config = httr::authenticate(Sys.getenv("GITHUB_PAT"),
"x-oauth-basic", "basic"),
encode = "json",
body = list(
name = jsonlite::unbox("foo"),
description = jsonlite::unbox("test branch_set_upstream"),
private = jsonlite::unbox(TRUE)
))
httr::http_status(req)
#> $category
#> [1] "success"
#>
#> $message
#> [1] "success: (201) Created"
httr::content(req)$ssh_url
#> [1] "git@github.com:jennybc/foo.git"
remote_add(repo, "origin", httr::content(req)$ssh_url)
cred <- cred_ssh_key("~/.ssh/id_rsa.pub", "~/.ssh/id_rsa")
push(repo, "origin", "refs/heads/master", credentials = cred)
#> Error in .local(object, ...): Error in 'git2r_push': Failed to authenticate SSH session: Callback returned error
cred <- cred_ssh_key("~/.ssh/id_rsa.pub", "~/.ssh/id_rsa", "<PASSPHRASE GOES HERE>")
push(repo, "origin", "refs/heads/master", credentials = cred)
branch_get_upstream(head(repo))
#> NULL
branch_set_upstream(git2r::head(repo), "origin/master")
branch_get_upstream(head(repo))
#> [b3de97] (origin @ git@github.com:jennybc/foo.git) master In |
Hi @jennybc, I'm testing, will return in a moment. |
Yes
No
Great
Yes, I use ssh
Yes
Yes, but I did not use keys with a passphrase in the example above. The
Does that work? |
OK yes that works. If I do the push via ssh, with a Is it obvious that this should be the case? Is this what you mean by "... and authentication with ssh key is ok"? Does a successful ssh push create some persistent state in What's the intended workflow if public and private keys live in non-default location and we can't use @hadley I will make a new PR shortly to deal with this. |
For operations that might need credentials, e.g.
No
The reason for NULL credentials is not about the passphrase. It tells
To use the @jennybc thanks for your feedback. Much of this functionality is very recently implemented in |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
git init
git push
The text was updated successfully, but these errors were encountered: