ok/jj
1
0
Fork 0
forked from mirrors/jj

feature: support git credential helpers

This commit is contained in:
Ruben Slabbert 2022-11-20 10:13:39 +10:00 committed by Martin von Zweigbergk
parent 84efed420f
commit 68b77d123d
3 changed files with 10 additions and 3 deletions

View file

@ -62,6 +62,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* The username and hostname that appear in the operation log are now
configurable via config options `operation.username` and `operation.hostname`.
* `jj git` subcommands now support credential helpers.
### Fixed bugs
* (#463) A bug in the export of branches to Git caused spurious conflicted

View file

@ -20,8 +20,8 @@ a comparison with Git, including how workflows are different, see the
you miss any particular configuration options.
* The configuration of remotes (`[remote "<name>"]`).
* `core.excludesFile`
* **Authentication: Partial.** Only `ssh-agent` or a password-less key file at
`~/.ssh/id_rsa` (and only at exactly that path).
* **Authentication: Partial.** Only `ssh-agent`, a password-less key file at
`~/.ssh/id_rsa` (and only at exactly that path), or a `credential.helper`.
* **Branches: Yes.** You can read more about
[how branches work in Jujutsu](branches.md)
and [how they interoperate with Git](#branches).

View file

@ -553,7 +553,12 @@ impl<'a> RemoteCallbacks<'a> {
// TODO: We should expose the callbacks to the caller instead -- the library
// crate shouldn't read environment variables.
callbacks.credentials(move |url, username_from_url, allowed_types| {
if let Some(username) = username_from_url {
let git_config = git2::Config::open_default();
let credential_helper = git_config
.and_then(|conf| git2::Cred::credential_helper(&conf, url, username_from_url));
if let Ok(creds) = credential_helper {
return Ok(creds);
} else if let Some(username) = username_from_url {
if allowed_types.contains(git2::CredentialType::SSH_KEY) {
if std::env::var("SSH_AUTH_SOCK").is_ok()
|| std::env::var("SSH_AGENT_PID").is_ok()