rust-lang / rust-lang/git2-rs

push the code is not working on windows

Open
#938 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.1k
Forks
450
Avg merge
11m
Merged PRs (30d)
1

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the push entry point shown in the issue, especially RemoteCallbacks::credentials and PushOptions, and reproduce the reported SSH hostkey-preference error on Windows. Compare the Windows behavior with the working macOS path and trace how git2 handles the callback; done means pushing the selected local branch through origin succeeds on Windows without that error.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, rust
Domain
devtools, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.