rust-lang / git2-rs

libgit2 bindings for Rust
https://docs.rs/git2
Apache License 2.0
1.65k stars 381 forks source link

push the code is not working on windows #938

Open phostann opened 1 year ago

phostann commented 1 year ago

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)

renat33112 commented 1 year ago

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

Olaroll commented 7 months ago

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

maojinhua commented 3 weeks ago

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