I’m trying to use libgit2 to first clone a bare repository and later on to update it with changes from a github origin. The cloning works fine:
git_repository *_repository
git_clone_bare(&_repository, REPOSITORY_URL, path, &transferProgressCallback, NULL);
git_repository_free(_repository);
But when I try to update the repository from origin libgit2 always downloads the entire repository again. It just doesn’t fetch the changes only. I’m using this code:
git_remote *remote;
git_repository *_repository;
git_repository_open(&_repository, path);
git_remote_load(&remote, _repository, "origin");
git_remote_connect(remote, GIT_DIR_FETCH);
git_remote_download(remote, &transferProgressCallback, NULL);
git_remote_disconnect(remote);
git_remote_update_tips(remote);
git_remote_free(remote);
(I removed the error handling.) I use a callback like this to report the progress:
void transferProgressCallback(const git_transfer_progress *stats, void *payload) {
float receivedMegaBytes = (float)stats->received_bytes/(1024*1024.0);
float progress = ((float)stats->received_objects / (float)stats->total_objects) * 100.0;
printf("Loading: %.1f (%.1f)\n", progress, receivedMegaBytes);
}
According to the callback everything is downloaded (same number of bytes as with git_clone_bare). I must be missing something or doing something wrong, right? But I don’t see where. All I want is that the code fetches changes only (that is stuff not present locally). But instead it keeps fetching all of the entire repository.
Please, what could be the problem here? Thank you very much in advance!
That’s very weird. I cannot reproduce the issue.
Which version of libgit2 are you running against?
I’ve locally added a test to the libgit2 fetch suite which reproduces your issue and… it passes against the current latest development tip of libgit2. The following urls were successfully checked:
UPDATE:
I’ve sent a pull request to the libgit2 project in order to make sure the test also pass on Travis, the CI server.
UPDATE 2:
Ok, I’ve done some more troubleshooting and I still can’t reproduce the issue.
The code below, even if this is not a real test (as it requires some interaction from the user), demonstrates what is explained above.
Below the output of the console, resulting of the second download. One can note that only 3 objects are being retrieved:
And the repository holds 6 objects (3 from the first commit, 3 from the second one):
From my perspective, it looks like libgit2 is indeed able to download a differential pack.