Closed AmeliaMN closed 2 years ago
gitcreds only looks at the PATH. Try setting the PATH in your .Renviron
. If you are able to run system("git --version")
then you should be able to run gitcreds.
Can you point me to some documentation for setting the PATH in .Renviron
? I tried what made sense to me and it didn't work.
But, the situation right now is indeed I can run system("git --version")
but not gitcreds
stuff.
> system("git --version")
[1] 127
> gitcreds::gitcreds_set()
Error in throw(new_error("gitcreds_nogit_error")) :
Could not find system git
But, the situation right now is indeed I can run system("git --version")
No, the 127 is an error. This is how the correct output loos like:
❯ system("git --version")
git version 2.34.1
If you are on Windows, it is probably something like this:
PATH=C:/the/path/to/git;${PATH}
Thank you! I had the $PATH
part, but not the {}
around it. Slashes on Windows go the other way, and it appears that the whole thing needs to be wrapped in quotes, but it seems like I've been able to set it in my .Renviron
.
Now I can see
> system("git --version")
git version 2.15.1.windows.2
[1] 0
gitcreds
is still not happy, but it may be file permission issues,
> gitcreds::gitcreds_set()
Error in new_git_error("git_error", args = args, stdout = out, status = attr(out, :
System git failed: error: cannot spawn sh: No such file or directory
error: cannot spawn sh: No such file or directory
error: cannot spawn rpostback-askpass: No such file or directory
fatal: could not read Username for 'https://github.com': terminal prompts disabled
Slashes on Windows go the other way,
No, R handles both ways, I actually tried this on Windows. I don't think you need quotes, either, but they don't hurt.
gitcreds is still not happy
It is possible that you also need to find where sh.exe
is within the git installation, and put that on the PATH as well.
You can also check what credential helper is set up for you, maybe that is not right:
system("git config credential.helper")
Btw. can you use the git credential store from a terminal, if the path is set correctly? E.g. can you add a token, and then push without giving the token every time?
Ah, the credential.helper must be the problem! I get
> system("git config credential.helper")
manager
[1] 0
Which seems like it is probably a failure. Is this something that needs to be installed separately? If so, it sounds like I'll be talking to my IT folks after all.
As for the quotes, at least on this system (looks like Windows 10?) if I don't use them, I lose access to all my packages. On restart, R says
Error: package or namespace load failed for ‘stats’ in inDL(x, as.logical(local), as.logical(now), ...):
unable to load shared object 'C:/Users/mcna6887/Documents/R/R-4.0.2/library/stats/libs/x64/stats.dll':
LoadLibrary failure: The specified module could not be found.
During startup - Warning message:
package ‘stats’ in options("defaultPackages") was not found
Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared object 'C:/Users/mcna6887/Documents/R/R-4.0.2/library/stats/libs/x64/stats.dll':
LoadLibrary failure: The specified module could not be found.
and any subsequent library()
calls I attempt get the same error. Somehow, having quotes fixes that. I've tried it with the slashes both directions, thinking that perhaps it could be unquoted with the other slashes, but no dice.
Which seems like it is probably a failure.
manager
is good, actually.
I would try to use the git credential store from the command line first:
git credential fill
url=https://github.com
and then press ENTER twice.protocol=https
host=github.com
username=PersonalAccessToken
password=<PAT here>
If you don't have a token stored yet, then you'll get something like Username for 'https://github.com'
and you can press CTRL+C here to interrupt.
Does this work from the command line? If not, and you still get the same errors about sh.exe
, then try to search for sh.exe
or bash.exe
within the git installation, and add that to the PATH as well.
OTOH, if this is too hard to get working, then you can just use the GITHUB_PAT
environment variable, like before, gitcreds and usethis still supports that.
That fixed it!! It took me a bit to realize you meant that I should CTRL+C out of that and then go back to R/RStudio to try the gitcreds
thing (lots of tempting GitHub and SSH popups appeared), but I eventually got it.
Luckily, I have access to hundreds of computers with the same setup so I can easily reproduce my steps and find the minimal set that needs to be done...
For the record, with the weird git
install at my institution I needed to:
where git
in a git terminal).Renviron
, making sure there were quotes around the stringgit credential fill
gitcreds::gitcreds_set()
Either order of initializing things with git credential fill
and letting RStudio know the PATH to git works. I think I understand this well enough to help my students with it. Phew.
Thank you so much! I do wonder if it would be worth an addition to the error message from gitcreds
and/or a section in happygitwithr.
Of course I just got back to my office after trying this on a bunch of computers in my classroom while students worked on things, and the office computer is sufficiently borked that the steps don't work. I think I had been mucking around with the git credential manager before you suggested it, and obviously messed something up. Instead of the tempting GitHub and SSH popups I get on the fresh computers, this one gives
warning: invalid credential line: ?
fatal: unable to read credential from stdin
when I try the git credential fill
thing. I've googled and the internet suggests deleting the credential from the Windows Credential Manager, but that doesn't fix the issue for me. I think I likely added something strange to the file, but since I don't know what it's called I can't go kill it.
OK, this is really weird that that sequence of step would fix this issue. And also, you can't really require students to do all those steps, either. :(
It is also not worth spending a lot of effort on this, because this is an old git version, and an old credential manager, git does not use manager
any more, and it is unmaintained: https://github.com/microsoft/Git-Credential-Manager-for-Windows#notice-this-project-is-no-longer-being-maintained-warning
So I suggest you try one last thing: set the credential helper to wincreds
if that is available:
git config credential.helper wincreds
and then try using gitcreds_set()
etc. If this works, great!
If it does not work, then maybe you can ask IT to update git? 2.15.1 is about 5 years old, and a lot of things changed in the default credential helpers.
I am going to close this now, hopefully you could solve this in some way, if nothing else via setting a GITHUB_PAT
env var.
I started this as an issue on happygitwithr, but Jenny suggested it would be a better issue here. git is installed on a machine (well really, a bunch of machines-- these are managed by ITS at my academic institution) in a somewhat non-standard way. Sadly, this non-standard way seems to be making it impossible to use
gitcreds
.I can
git
in my RStudio terminalUnfortunately, I cannot
gitcreds
, such asAny other suggestions for getting
gitcreds
to recognize my system git, or am I stuck trying to convince my IT folks to install git differently?