-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
How to use credentials from git-credential helper #4873
Comments
As you've noted, this isn't something that we have built-in support for - we don't exec programs directly for a plurality of reasons. But indeed, it should be relatively straightforward to call out to the We do have an example of credential callbacks but we don't have an example for one that exec's something. |
So for future reference, to get credentials from e.g. printf "protocol=https\nhost=github.com\n" | git credential fill If credential for the given host is stored, those are returned, and otherwise the user is prompted for a username/password. The output is then printed to stdout like this:
Which you can then feed back to git_cred_userpass_plaintext_new in the callback. |
I already wrote a (GPLed) framework executing external commands from libgit2 (for filters and ssh; cf. https://gitlab.com/tortoisegit/tortoisegit/tree/master/src/libgit2). I haven't found the time for extending it for the credential API, yet, but I'm open for contributions. |
To adapt this to a windows C/C++ environment, I needed to use
The reason I used a file instead of piping it in on the command line is passing input and reading output on the same pipe is not possible. The output string was constructed by reading from the pipe using |
Is it possible to make libgit2 authenticate using credentials that the user has previously stored via the command line git? Specifically Git for Windows defaults to storing credentials in Git Credential Manager for Windows which speaks the credential helper protocol.
I think this involves shelling out to
git credential fill
but maybe there is more to it. Is there an example that implements something like this? Agit_cred_
helper function would also be very useful.@dscho
The text was updated successfully, but these errors were encountered: