how to clone specific tag using git_clone() in lib

2019-09-16 14:40发布

问题:

I want to clone specific tag from my repository in bitbucket. Now I am able to clone just the whole repository. What should I add to my code to clone specific tag?

I have seen this but it doesnt really helped me :

https://github.com/libgit2/git2go/issues/126


git_libgit2_init();

int num = 0;

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;

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();


Thanks for your time