Skip to content

Commit 96ab67b

Browse files
committed
Add comment and reuse existing variable
1 parent 08d3fcc commit 96ab67b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/cargo/sources/git/utils.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,6 @@ where
451451
let mut ssh_agent_attempts = Vec::new();
452452
let mut any_attempts = false;
453453
let mut tried_sshkey = false;
454-
let mut tried_cred_helper = false;
455454

456455
let mut res = f(&mut |url, username, allowed| {
457456
any_attempts = true;
@@ -504,8 +503,12 @@ where
504503
// but we currently don't! Right now the only way we support fetching a
505504
// plaintext password is through the `credential.helper` support, so
506505
// fetch that here.
507-
if allowed.contains(git2::CredentialType::USER_PASS_PLAINTEXT) && !tried_cred_helper {
508-
tried_cred_helper = true;
506+
//
507+
// If ssh-agent authentication fails, libgit2 will keep calling this
508+
// callback asking for other authentication methods to try. Check
509+
// cred_helper_bad to make sure we only try the git credentail helper
510+
// once, to avoid looping forever.
511+
if allowed.contains(git2::CredentialType::USER_PASS_PLAINTEXT) && cred_helper_bad.is_none() {
509512
let r = git2::Cred::credential_helper(cfg, url, username);
510513
cred_helper_bad = Some(r.is_err());
511514
return r;

0 commit comments

Comments
 (0)