libgit2 身份验证:如何知道何时失败

时间:2021-02-04 07:31:41

标签: c++ libgit2

我在 GNU/Linux 上使用 libgit2 0.2.27-1。我正在尝试在我的应用程序 (C++) 中连接到 Github 的封闭存储库。但我遇到了一个问题。我测试了自己的应用程序并尝试输入一些错误的凭据。使用 libgit2 (C),我无法知道身份验证何时失败。只要它构建一个空的 git 结构,这对我来说就是一个问题。如果我提供了正确的凭据,一切都很好。 当我启动我的函数时,我会监控更新(下载、对象、索引...),但是如果我输入了错误的凭据,该函数将永远不会返回并且永远不会给出错误(git_last_error(),在我的版本中为 giterr_last())。此外,我找不到任何适合我的情况的回调处理程序。我也没有找到中止 git_clone 的方法。这是我使用的:

int do_clone(const char *url, const char *path)
{
    progress_data pd = Terminal and Visual Studio Screenshot;
    git_repository *cloned_repo = nullptr;
    git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
    git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
    int error;

    // Set up options
    *cons << "Setuping clone operation...";
    checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
    checkout_opts.progress_cb = checkout_progress;
    checkout_opts.progress_payload = &pd;
    clone_opts.checkout_opts = checkout_opts;
    clone_opts.fetch_opts.callbacks.sideband_progress = sideband_progress;
    clone_opts.fetch_opts.callbacks.transfer_progress = &fetch_progress;
    clone_opts.fetch_opts.callbacks.credentials = cred_acquire_cb;
    clone_opts.fetch_opts.callbacks.payload = &pd;
    *cons << "Setup finished.";

    // Do the clone
    *cons << "Started cloning.";
    error = git_clone(&cloned_repo, url, path, &clone_opts);
    *cons << "FINISHED: " << error << "\n";

    if (error != 0) {
        const git_error *err = giterr_last();
        if (err) {
            *cons << "ERROR " << err->klass << ": " << err->message << "\n";
        } else {
            *cons << "ERROR " << error << ": no detailed info\n";
        }
    } else if (cloned_repo) {
        git_repository_free(cloned_repo);
    }
    return error;
}

*注意所有代码都是有效的。我只是想念如何停止该功能或如何知道身份验证失败的时间。

0 个答案:

没有答案
相关问题