Issue fetching submodules with credentials callback

未关闭
#1,167 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
42/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
rust
领域
tooling

调研方向

从使用 RepoBuilder::clone、RemoteCallbacks::credentials、SubmoduleUpdateOptions::new、update_opts.fetch 和 submodule.update 的复现流程开始。比较克隆期间传递 callback 的方式与 submodule 更新执行 fetch 的方式,然后确认 SSH 密钥 callback 得到应用,并且 submodule 更新在没有出现“no callback set”错误的情况下完成。

由索引模型根据 Issue 内容生成。

描述

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))?;
    }
主要语言
Rust
星标
2.1k
派生
470
平均合并
2 天 17 小时
30 天内合并 PR
18

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

rust-lang/git2-rs 的其他 Issue

查看 rust-lang/git2-rs 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。