Skip to content

Commit

Permalink
feature: support git credential helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
rslabbert authored and martinvonz committed Nov 20, 2022
1 parent 84efed4 commit 68b77d1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/git-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
7 changes: 6 additions & 1 deletion lib/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 68b77d1

Please sign in to comment.