Issue fetching submodules with credentials callback

Aperta
#1,167 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
42/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
rust
Ambito
tooling

Direzione di ricerca

Inizia con il flusso riprodotto utilizzando RepoBuilder::clone, RemoteCallbacks::credentials, SubmoduleUpdateOptions::new, update_opts.fetch e submodule.update. Confronta il modo in cui viene passato il callback durante la clonazione con il modo in cui gli aggiornamenti dei submodule eseguono il fetch, quindi verifica che il callback della chiave SSH venga rispettato e che l’aggiornamento del submodule venga completato senza l’errore “no callback set”.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

Initialising and updating submodules fails when trying to authenticate via SSH key using the credentials callback. From the error message it seems as though setting the callback to pass to libgit2 doesn't actually get passed over? Either that or this is a libgit2 issue.

Details

Setting a callback with an SSH key credential for cloning the repo works correctly. But after cloning the repo and trying to initialise plus update the submodules, with a credential calllback identical to the one for cloning the repo, the following error occurs:

Error { code: -16, klass: 34, message: "remote authentication required but no callback set" }

Code snippet example to replicate issue:

let state = RefCell::new(State::default());

    let mut cb = RemoteCallbacks::new();
    cb.transfer_progress(|stats| {
        let mut state = state.borrow_mut();
        state.progress = Some(stats.to_owned());
        state.display();
        true
    });

    cb.credentials(|_url, username_from_url, _allowed| {
        Cred::ssh_key(
            username_from_url.unwrap_or("git"),
            None,
            ssh_key_path, // Relevant ssh key located in .ssh directory
            None,
        )
    });

    let mut co = CheckoutBuilder::new();
    co.progress(|path, cur, total| {
        let mut state = state.borrow_mut();
        state.path = path.map(Path::to_path_buf);
        state.current = cur;
        state.total = total;
        state.display();
    });

    let mut fo = FetchOptions::new();
    fo.remote_callbacks(cb);

    let repo = RepoBuilder::new()
        .fetch_options(fo)
        .with_checkout(co)
        .branch("develop")
        .clone(
            repo_url,
            Path::new("/tmp/test-git2/"),
        )?;

    for mut submodule in repo.submodules()? {
        let mut update_opts = SubmoduleUpdateOptions::new();
        let mut cb = RemoteCallbacks::new();
        cb.credentials(|_url, username_from_url, _allowed| {
            Cred::ssh_key(
                username_from_url.unwrap_or("git"),
                None,
                ssh_key_path,
                None,
            )
        });
        let mut fo = FetchOptions::new();
        fo.remote_callbacks(cb);

        update_opts.fetch(fo);

        submodule
            .update(true, Some(&mut update_opts))
            .map_err(|err| color_eyre::eyre::eyre!("Failed to update submodule: {:?}", err))?;
    }
Lingua principale
Rust
Stelle
2.1k
Fork
470
Merge medio
2g 17h
PR unite (30g)
18

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-lang/git2-rs

Tutte le issue di rust-lang/git2-rs

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.