当我执行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;
评论这两行后,它正在运作
答案 0 :(得分:2)
在评论结帐选项后它的工作原因是git_checkout_options
默认为结账策略的干运行。另一方面,GIT_CLONE_OPTIONS_INIT
将结帐策略初始化为GIT_CHECKOUT_SAFE
。您可以通过在结帐选项上设置策略来获得相同的行为:
clone_opts.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;