fn push(&self, authentication_method: AuthenticationMethod) -> Result<()> {
        let repo = &self.0;

        // TODO: allow remote to be configurable
        let mut remote = repo.find_remote("origin")?;

        let head = repo.head()?;
        let refspecs: &[&str] = &[head.name().unwrap()];

        let mut remote_callbacks = git2::RemoteCallbacks::new();

        match authentication_method {
            AuthenticationMethod::SshAgent => {
                remote_callbacks.credentials(|_url, username_from_url, _allowed_types| {
                    git2::Cred::ssh_key_from_agent(username_from_url.unwrap())
                });
            }
            AuthenticationMethod::SshKey {
                path: private_key_path,
                passphrase: key_passphrase,
            } => {
                remote_callbacks.credentials(move |_url, username_from_url, _allowed_types| {
                    git2::Cred::ssh_key(
                        username_from_url.unwrap(),
                        Some(&private_key_path.clone().with_extension("pub")),
                        &private_key_path,
                        Some(&key_passphrase.clone()),
                    )
                });
            }
        };

        remote_callbacks.push_update_reference(|refname, status| {
            if let Some(status_message) = status {
                log::error!("error pushing reference {}", refname);
                Err(git2::Error::from_str(status_message))
            } else {
                Ok(())
            }
        });

        let mut push_options = PushOptions::new();
        push_options.remote_callbacks(remote_callbacks);

        remote.push(refspecs, Some(&mut push_options))?;
        Ok(())
    }
/// Pushes the current branch into "origin".
/// The function relies on `ssh-agent` for git authentication.
Pushes the current branch into "origin".
The function relies on `ssh-agent` for git authentication.
Pushes the current branch into " origin " . The function relies on ` ssh - agent ` for git authentication .
fn push(&self, authentication_method: AuthenticationMethod) -> Result<()> {
        let repo = &self.0;
        // TODO: allow remote to be configurable
        let mut remote = repo.find_remote("origin")?;
        let head = repo.head()?;
        let refspecs: &[&str] = &[head.name().unwrap()];
        let mut remote_callbacks = git2::RemoteCallbacks::new();
        match authentication_method {
            AuthenticationMethod::SshAgent => {
                remote_callbacks.credentials(|_url, username_from_url, _allowed_types| {
                    git2::Cred::ssh_key_from_agent(username_from_url.unwrap())
                });
            }
            AuthenticationMethod::SshKey {
                path: private_key_path,
                passphrase: key_passphrase,
            } => {
                remote_callbacks.credentials(move |_url, username_from_url, _allowed_types| {
                    git2::Cred::ssh_key(
                        username_from_url.unwrap(),
                        Some(&private_key_path.clone().with_extension("pub")),
                        &private_key_path,
                        Some(&key_passphrase.clone()),
                    )
                });
            }
        };
        remote_callbacks.push_update_reference(|refname, status| {
            if let Some(status_message) = status {
                log::error!("error pushing reference {}", refname);
                Err(git2::Error::from_str(status_message))
            } else {
                Ok(())
            }
        });
        let mut push_options = PushOptions::new();
        push_options.remote_callbacks(remote_callbacks);
        remote.push(refspecs, Some(&mut push_options))?;
        Ok(())
    }
fn push ( & self , authentication_method : AuthenticationMethod ) -> Result < ( ) > { let repo = & self . 0 ; // TODO: allow remote to be configurable let mut remote = repo . find_remote ( " " ) ? ; let head = repo . head ( ) ? ; let refspecs : & [ & str ] = & [ head . name ( ) . unwrap ( ) ] ; let mut remote_callbacks = git2 :: RemoteCallbacks :: new ( ) ; match authentication_method { AuthenticationMethod :: SshAgent => { remote_callbacks . credentials ( | _url , username_from_url , _allowed_types | { git2 :: Cred :: ssh_key_from_agent ( username_from_url . unwrap ( ) ) } ) ; } AuthenticationMethod :: SshKey { path : private_key_path , passphrase : key_passphrase , } => { remote_callbacks . credentials ( move | _url , username_from_url , _allowed_types | { git2 :: Cred :: ssh_key ( username_from_url . unwrap ( ) , Some ( & private_key_path . clone ( ) . with_extension ( " " ) ) , & private_key_path , Some ( & key_passphrase . clone ( ) ) , ) } ) ; } } ; remote_callbacks . push_update_reference ( | refname , status | { if let Some ( status_message ) = status { log :: error ! ( " " refname ) ; Err ( git2 :: Error :: from_str ( status_message ) ) } else { Ok ( ( ) ) } } ) ; let mut push_options = PushOptions :: new ( ) ; push_options . remote_callbacks ( remote_callbacks ) ; remote . push ( refspecs , Some ( & mut push_options ) ) ? ; Ok ( ( ) ) }
Pushes the current branch into "origin".
Pushes the current branch into " origin " .
&self
authentication_method
AuthenticationMethod
&self
authentication_method
AuthenticationMethod