Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gitcreds should check git version #26

Open
MyKo101 opened this issue Jan 14, 2021 · 9 comments
Open

gitcreds should check git version #26

MyKo101 opened this issue Jan 14, 2021 · 9 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@MyKo101
Copy link

MyKo101 commented Jan 14, 2021

I was trying to follow along with the Github credentials guide on usethis and when I got to the point of running gitcreds::gitcreds_set() I got the following error:

> gitcreds::gitcreds_set()
Error in throw(new_error("git_error", args = args, stdout = out, status = attr(out,  : 
  System git failed

In this functions, there's a tryCatch() intending to grab gitcreds_no_credentials and return NULL, however the error being thrown here is not a gitcreds_no_credentials condition and so the error was seeping through. The code goes on to run gitcreds_set_new(url) if the condition is caught and I was getting the same error response.

It took me way too long to realise my git version was out of date and after updating the error went away.

It would be useful for gitcreds to check a user's git version at some point in the process because the error I was receiving was very uninformative.

@gaborcsardi
Copy link
Member

Hi, which version of gitcreds is this? I think the most recent version prints the output from git at least. Also, what was your git version before the upgrade?

@gaborcsardi gaborcsardi added the bug an unexpected problem or unintended behavior label Jan 25, 2021
@MyKo101
Copy link
Author

MyKo101 commented Jan 25, 2021

Unfortunately since I've updated my git version, I don't know which version of git I was actually using. Do you know if there is any way to find out which version I was using? Would it be in any of the .git/ files of an old repo?

I'm on gitcred version 0.1.0.

I think that the throw(new_error(...)) line is supposed to be doing as you say, output the git output when an error is hit. But since it's hitting an unexpected git error (because of my ancient version), it's not being caught in the right way.

@gaborcsardi
Copy link
Member

gitcreds 0.1.1 prints the output of git, I believe.

@gaborcsardi
Copy link
Member

This is what I get for git 1.7.7:

Error in new_git_error("git_error", args = args, stdout = out, status = attr(out,  :
  System git failed: git: 'credential' is not a git command. See 'git --help'.

Is this better?

@gaborcsardi
Copy link
Member

Checking the git version programmatically seems hard, because the git version strings are quite creative. E.g. my 1.7.7 prints this:

> system("git --version")
git version 1.7.7.GIT

So I am afraid that we would do more harm with trying to parse these strings.

@MyKo101
Copy link
Author

MyKo101 commented Jan 27, 2021

Looking at the documentation for git, I believe that the credential command was introduced in version 2.25. Anything older than this wouldn't work with gitcreds, right?

I think the git versions also all have the three standard parts (major.minor.patch) followed by other system-type versions (mine is now 2.30.0.windows.1

Something like this should work as a check:


git_version <- function(){
  gv_raw <- system("git --version",intern=T)
  v_location <- regexpr("([0-9]*?\\.[0-9]*?\\.[0-9]*\\.)",gv_raw)
  gv_str <- regmatches(gv_raw,v_location)
  as.numeric_version(substr(gv_str,1,nchar(gv_str)-1))
}

git_version()

if(git_version() < "2.25")
  stop("git credentials only available in ")

I don't know a way to test this function with other versions of git though so the results might be unpredictable so I understand your apprehension.

@gaborcsardi
Copy link
Member

No, it is much older than that:

❯ git --version
git version 2.9.2

❯ git credential
usage: git credential [fill|approve|reject]

@MyKo101
Copy link
Author

MyKo101 commented Jan 27, 2021

I've just had a quick look at the archive and it looks like credentials was available at least as far back as 1.8.0, if your example of 1.7.7 is correct then it must have been introduced between those.

This is what I get for git 1.7.7:

Error in new_git_error("git_error", args = args, stdout = out, status = attr(out,  :
  System git failed: git: 'credential' is not a git command. See 'git --help'.

Is this better?

Is this error just forwarding on the error from git? Would it be possible to put in a little bit that says "Try updating git" or something to that effect?

@gaborcsardi
Copy link
Member

gaborcsardi commented Jan 27, 2021

I am not sure if it is possible to determine if the problem is an old git version. git credential can fail various ways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants