Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to clone specific tag using git_clone() #370

Open
jablkojem opened this issue Apr 3, 2017 · 3 comments
Open

how to clone specific tag using git_clone() #370

jablkojem opened this issue Apr 3, 2017 · 3 comments

Comments

@jablkojem
Copy link

Hi all,
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 :

#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 help

@jablkojem
Copy link
Author

I added

const char* checkout_branch ="v0.0.1";
clone_opts.checkout_branch = checkout_branch;

but now there is an error message
Reference 'refs/remotes/origin/v0.0.1' not found

@apflieger
Copy link

I don't know all of this but did you try to use the complete ref ? that is refs/tags/v0.0.1
I read roughly the code, I doubt it would work that easily. You might have to fetch tags and then checkout

@jbg
Copy link

jbg commented Jul 2, 2020

#126 (which you linked to) explains that libgit doesn't implement passing a tag as the branch to clone like the git command does. you will need to checkout the tag after cloning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants