git_clone() 克隆 .git 文件夹 (libgit2)

git_clone() clone just .git folder (libgit2)

本文关键字:git libgit2 文件夹 克隆 clone      更新时间:2023-10-16

当我执行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;

评论完这2行后,它正在工作

注释

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

clone_opts.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;