git2-rs icon indicating copy to clipboard operation
git2-rs copied to clipboard

push the code is not working on windows

Open phostann opened this issue 1 year ago • 3 comments

here is my code

pub fn push(&self, branch: &str) -> Result<()> {
        let mut remote = self
            .repo
            .find_remote("origin")
            .with_context(|| "Failed to push the repository")?;

        let branch = self
            .repo
            .find_branch(branch, git2::BranchType::Local)
            .with_context(|| "Failed to find the branch")?;

        let refs = branch.into_reference();

        let name = refs.name().with_context(|| "The reference name is none")?;

        let mut callbacks = git2::RemoteCallbacks::new();
        callbacks.credentials(|_url, username_from_url, _allowed_types| {
            tracing::info!("Allowed types: {:?}", _allowed_types);

            Cred::ssh_key(
                username_from_url.unwrap(),
                None,
                std::path::Path::new(self.pub_key.as_str()),
                None,
            )
        });

        let mut options = git2::PushOptions::new();

        options.remote_callbacks(callbacks);

        // push the code to master branch
        remote
            .push(&[name], Some(&mut options))
            .with_context(|| "Failed to push the code")?;

        Ok(())
    }

it's working fine on mac but get an error on windows failed to set hostkey preference: The requested method(s) are not currently supported; class=Ssh (23)

phostann avatar Mar 13 '23 10:03 phostann

Hi @phostann! Have the same issue on windows 11. Did you fix it somehow? Everything working at linux (ubuntu 22.04), but getting the same error on windows 11

renat33112 avatar Jun 05 '23 09:06 renat33112

I also have this error when attempting to clone a repository. Any help or pointers would be much appreciated.

Olaroll avatar Nov 29 '23 01:11 Olaroll

I also have this error when attempting to clone a repository。Everything working at Mac, but getting the same error on windows 11

maojinhua avatar Jul 03 '24 07:07 maojinhua