fn credentials(
		&self,
		url: &str,
		username_from_url: Option<&str>,
		allowed_types: git2::CredentialType,
	) -> std::result::Result<Cred, GitError> {
		log::debug!(
			"creds: '{}' {:?} ({:?})",
			url,
			username_from_url,
			allowed_types
		);

		// This boolean is used to avoid multiple calls to credentials callback.
		if self.first_call_to_credentials.load(Ordering::Relaxed) {
			self.first_call_to_credentials
				.store(false, Ordering::Relaxed);
		} else {
			return Err(GitError::from_str("Bad credentials."));
		}

		match &self.basic_credential {
			_ if allowed_types.is_ssh_key() => {
				match username_from_url {
					Some(username) => {
						Cred::ssh_key_from_agent(username)
					}
					None => Err(GitError::from_str(
						" Couldn't extract username from url.",
					)),
				}
			}
			Some(BasicAuthCredential {
				username: Some(user),
				password: Some(pwd),
			}) if allowed_types.is_user_pass_plaintext() => {
				Cred::userpass_plaintext(user, pwd)
			}
			Some(BasicAuthCredential {
				username: Some(user),
				password: _,
			}) if allowed_types.is_username() => Cred::username(user),
			_ if allowed_types.is_default() => Cred::default(),
			_ => Err(GitError::from_str("Couldn't find credentials")),
		}
	}
// If credentials are bad, we don't ask the user to re-fill their creds. We push an error and they will be able to restart their action (for example a push) and retype their creds.
// This behavior is explained in a issue on git2-rs project : https://github.com/rust-lang/git2-rs/issues/347
// An implementation reference is done in cargo : https://github.com/rust-lang/cargo/blob/9fb208dddb12a3081230a5fd8f470e01df8faa25/src/cargo/sources/git/utils.rs#L588
// There is also a guide about libgit2 authentication : https://libgit2.org/docs/guides/authentication/
If credentials are bad, we don't ask the user to re-fill their creds. We push an error and they will be able to restart their action (for example a push) and retype their creds.
If credentials are bad we don ' t ask the user to re - fill their creds . We push an error and they will be able to restart their action ( for example a push ) and retype their creds .
fn credentials(
		&self,
		url: &str,
		username_from_url: Option<&str>,
		allowed_types: git2::CredentialType,
	) -> std::result::Result<Cred, GitError> {
		log::debug!(
			"creds: '{}' {:?} ({:?})",
			url,
			username_from_url,
			allowed_types
		);
		// This boolean is used to avoid multiple calls to credentials callback.
		if self.first_call_to_credentials.load(Ordering::Relaxed) {
			self.first_call_to_credentials
				.store(false, Ordering::Relaxed);
		} else {
			return Err(GitError::from_str("Bad credentials."));
		}
		match &self.basic_credential {
			_ if allowed_types.is_ssh_key() => {
				match username_from_url {
					Some(username) => {
						Cred::ssh_key_from_agent(username)
					}
					None => Err(GitError::from_str(
						" Couldn't extract username from url.",
					)),
				}
			}
			Some(BasicAuthCredential {
				username: Some(user),
				password: Some(pwd),
			}) if allowed_types.is_user_pass_plaintext() => {
				Cred::userpass_plaintext(user, pwd)
			}
			Some(BasicAuthCredential {
				username: Some(user),
				password: _,
			}) if allowed_types.is_username() => Cred::username(user),
			_ if allowed_types.is_default() => Cred::default(),
			_ => Err(GitError::from_str("Couldn't find credentials")),
		}
	}
fn credentials ( & self , url : & str , username_from_url : Option < & str > , allowed_types : git2 :: CredentialType , ) -> std :: result :: Result < Cred , GitError > { log :: debug ! ( " " url username_from_url allowed_types ) ; // This boolean is used to avoid multiple calls to credentials callback. if self . first_call_to_credentials . load ( Ordering :: Relaxed ) { self . first_call_to_credentials . store ( false , Ordering :: Relaxed ) ; } else { return Err ( GitError :: from_str ( " " ) ) ; } match & self . basic_credential { _ if allowed_types . is_ssh_key ( ) => { match username_from_url { Some ( username ) => { Cred :: ssh_key_from_agent ( username ) } None => Err ( GitError :: from_str ( " " , ) ) , } } Some ( BasicAuthCredential { username : Some ( user ) , password : Some ( pwd ) , } ) if allowed_types . is_user_pass_plaintext ( ) => { Cred :: userpass_plaintext ( user , pwd ) } Some ( BasicAuthCredential { username : Some ( user ) , password : _ , } ) if allowed_types . is_username ( ) => Cred :: username ( user ) , _ if allowed_types . is_default ( ) => Cred :: default ( ) , _ => Err ( GitError :: from_str ( " " ) ) , } }
If credentials are bad, we don't ask the user to re-fill their creds.
If credentials are bad we don ' t ask the user to re - fill their creds .
&self
url
&str
username_from_url
Option<&str>
allowed_types
git2::CredentialType