r-lib / gitcreds

Query git credentials from R
https://gitcreds.r-lib.org/
Other
27 stars 10 forks source link

gitcreds_set() appears ineffective #55

Open RossBoylan opened 7 months ago

RossBoylan commented 7 months ago

Problem

gitcreds_set() doesn't seem to be setting anything:

> gitcreds::gitcreds_set()

? Enter password or token: ghp_XXXX
-> Adding new credentials...
-> Removing credentials from cache...
-> Done.
> usethis::gh_token_help()
* GitHub host: 'https://github.com'
* Personal access token for 'https://github.com': <unset>
* To create a personal access token, call `create_github_token()`
* To store a token for current and future use, call `gitcreds::gitcreds_set()`
i Read more in the 'Managing Git(Hub) Credentials' article:
  https://usethis.r-lib.org/articles/articles/git-credentials.html
> gitcreds::gitcreds_get()
Error in throw(new_error("gitcreds_no_credentials", url = url)) : 
  Could not find any credentials

Trying gitcreds_get in a new session later yields the same result

Background Information

Based partly on questions developers asked in a somewhat similar bug, I installed oskeyring and collected additional info:

> gitcreds::gitcreds_list_helpers()
[1] "manager"      "manager-core"

> gitcreds::gitcreds_list()
[[1]]
<oskeyring_windows_item: generic>
 target_name: git:https://RossBoylan@github.com
 persist: local_machine
 username: RossBoylan
 credential_blob: <-- hidden -->

[[2]]
<oskeyring_windows_item: generic>
 target_name: git:https://github.com
 persist: local_machine
 username: Personal Access Token
 credential_blob: <-- hidden -->

[[3]]
<oskeyring_windows_item: generic>
 target_name: git:https://PersonalAccessToken@github.com
 persist: local_machine
 username: PersonalAccessToken
 credential_blob: <-- hidden -->

Warning message:
In gitcreds$throw(gitcreds$new_warning("gitcreds_multiple_helpers")) :
  Multiple credential helpers, only using the first

Running under RStudio 2023.06.1+524 "Mountain Hydrangea" Release (547dcf861cac0253a8abb52c135e44e02ba407a1, 2023-07-07) for windows Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) RStudio/2023.06.1+524 Chrome/110.0.5481.208 Electron/23.3.0 Safari/537.36

R version 4.3.1 (2023-06-16 ucrt) git version 2.43.0.windows.1 gitcred 0.1.2

So both RStudio and R are a little behind current.

I have accessed github in various ways, including ssh, from various applications. In Windows Credential Manager (under Windows Credentials | Generic Credentials) I see at least 5 entries associated with github.com, 3 of which were last modified today. I also see that Windows and Certificate-Based Credentials both say "have been disabled by your system administrator".

gaborcsardi commented 7 months ago

I would try to remove all github tokens from the credential store (after backing them up if you want that), and then add the new token with gitcreds_set().

RossBoylan commented 7 months ago

Thanks. That worked.

I do notice this message on pushes:

>>> C:/Programs/Git/bin/git.exe push origin HEAD:refs/heads/main
git: 'credential-manager-core' is not a git command. See 'git --help'.

I don't know if it's related to my original problem.

So my problem is fixed, but it would be nice if the code could cope with my original situation.

gaborcsardi commented 7 months ago

I think that message means that your setup is / was in a broken state, so it is unlikely that we can reproduce and support that.

I think you have two credential helpers set up, and one of them is not in a working state, so you could try to

RossBoylan commented 7 months ago

I am not sure which credential helpers I have installed, which of them might be broken, or how to remove "extra" helpers. Can you (or anyone) provide additional guidance?

As I reported, in R

> gitcreds::gitcreds_list_helpers()
[1] "manager"      "manager-core"

On the other hand, the git credentials man page suggests

$ git help -a | grep credential-
   credential-cache        Helper to temporarily store passwords in memory
   credential-store        Helper to store credentials on disk
   credential-helper-selector
   credential-manager

which is different. And git help credential-manager, recommended by the man page, finds no documentation; there is also none for credential-manager-core.

Finally, here's my config:

$ git config --show-origin --get-regexp credential
file:C:/Programs/Git/etc/gitconfig      credential.helper manager
file:C:/Programs/Git/etc/gitconfig      credential.https://dev.azure.com.usehttppath true
file:C:/Users/rdboylan/.gitconfig       credential.helper manager-core

It looks as if git for Windows has a default credential helper of manager, but something set my account to use manager-core.

The last 2 chunks are from a git bash shell under MS-Windows; R, RStudio, or VSCode may be adding additional wrinkles.