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

feature: support git credential helpers #773

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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