How to push to remote with the rust git2 crate

Viewed 24

I'm trying to push my git repository using git2. I can't seem to get it right. Here's my code:

pub fn push(repo: Repository) -> Result<(), git2::Error> {
    let mut opts = PushOptions::default();
    let mut callbacks = RemoteCallbacks::new();
    callbacks.credentials(|_url, _username_from_url, _allowed_types| {
        println!("Cred input callback has been called");
        let password: String = scanpw!("Password for 'https://CrazyVideoGamer@github.com': ");
        Cred::userpass_plaintext("CrazyVideoGamer", &password)
    });
    opts.remote_callbacks(callbacks);
    repo.find_remote("origin")?
        .push::<&str>(&[], Some(&mut opts))
}

scanpw! simply prompts me for my password. But for some reason, when I try to run this code, it always asks me for my password over and over again. Why isn't this working?

Here's the gif of me trying to input my password: https://drive.google.com/file/d/13CfOsabotma1LSsqGuyCwxQTKJrvBnKx/view?usp=sharing

0 Answers
Related