1
votes

when I perform git_clone() , it runs successfully, but it clones just .git folder. When I use

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

in terminal, it clones also another folders, not just .git folder and I want git_clone() to work that way, is that possible?

My code:

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

There is how I set options

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;

After commenting these 2 lines, it is working

1
clone operations usually are followed by an automatic checkout. That's why there is a checkout_options defined inside clone_opts, but you do not specify how you initialize those... - rodrigo
@rodrigo I added code to set options - Martin.M
after commenting checkou_opts initialization, its working - Martin.M
I'm guessing that the default clone config instructs to checkout HEAD, while the default checkout config does not have any branch set. - rodrigo

1 Answers

2
votes

The reason it works after commenting out the checkout options is that git_checkout_options defaults to dry run for the checkout strategy. GIT_CLONE_OPTIONS_INIT, on the other hand, initializes the checkout strategy to GIT_CHECKOUT_SAFE. You can get the same behavior by setting the strategy on your checkout options:

clone_opts.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;