c++ - git_clone() 只克隆 .git 文件夹 (libgit2)

标签 c++ git libgit2

当我执行 git_clone() 时,它运行成功,但它只克隆 .git 文件夹。当我使用

git clone http:/url.adress.com/myRemoteRepo C:/destination/to/clone

在终端中,它还会克隆另一个文件夹,而不仅仅是 .git 文件夹,我希望 git_clone() 以这种方式工作,这可能吗?

我的代码:

  int num=0;

git_libgit2_init();

git_repository *cloned_repo = NULL;

int error = git_clone(&cloned_repo, all_urls.at(num).c_str(), clone_to.at(num).c_str(), &clone_opts); 

if (error != 0) {

    const git_error *err = giterr_last();

    cerr << "error in clone num " << num << " -> message :" << err->message << endl;

}

else cout << endl << "Clone " << num << " succesful" << "(from url : " << all_urls.at(num) << "    " << "to path : " << clone_to.at(num) << ")" << endl;

git_repository_free(cloned_repo);

git_libgit2_shutdown();

这是我如何设置选项

git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
        // git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
        // clone_opts.checkout_opts = checkout_opts;
        clone_opts.fetch_opts.callbacks.credentials = cred_acquire_cb;

评论这两行后,它正在工作

最佳答案

它在注释掉 checkout 选项后起作用的原因是 git_checkout_options 默认为 checkout 策略试运行。另一方面,GIT_CLONE_OPTIONS_INIT 将 checkout 策略初始化为 GIT_CHECKOUT_SAFE。您可以通过在 checkout 选项上设置策略来获得相同的行为:

clone_opts.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;

关于c++ - git_clone() 只克隆 .git 文件夹 (libgit2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43224315/

相关文章:

libgit2 - 如何使用libgit2运行 "git log filename"?

c++ - 指向函数的指针 C++

c++ -::std::remove_cv<> 应该适用于函数类型吗?

git - 在 Composer 项目中使用 VCS 的最佳实践

git - 如何使用 ssh 将 repo 克隆到远程服务器

libgit2 - 任何基于 libgit2 的本地 git 命令行工具?

c++ - 编译器或定义行为的可能优化

c++ - C++中的宏处理器

git - 如何在所有单元测试通过后立即 merge 推送?

c - 如何设计一个返回 oid 数组的函数