Skip to content

Instantly share code, notes, and snippets.

@nulltoken
Created May 8, 2012 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nulltoken/2634236 to your computer and use it in GitHub Desktop.
Save nulltoken/2634236 to your computer and use it in GitHub Desktop.
[Libgit2] fetching
#include "clar_libgit2.h"
#include "path.h"
#include "fileops.h"
#include "remote.h"
git_repository *repo;
git_remote *remote;
void test_network_fetch__initialize(void)
{
cl_git_pass(git_repository_init(&repo, "fetched", false));
}
void test_network_fetch__cleanup(void)
{
git_remote_free(remote);
git_repository_free(repo);
if (git_path_isdir("fetched"))
git_futils_rmdir_r("fetched", GIT_DIRREMOVAL_FILES_AND_DIRS);
}
int update_cb(const char *refname, const git_oid *a, const git_oid *b)
{
const char *action;
char a_str[GIT_OID_HEXSZ+1], b_str[GIT_OID_HEXSZ+1];
git_oid_fmt(b_str, b);
b_str[GIT_OID_HEXSZ] = '\0';
if (git_oid_iszero(a)) {
printf("[new] %.20s %s\n", b_str, refname);
} else {
git_oid_fmt(a_str, a);
a_str[GIT_OID_HEXSZ] = '\0';
printf("[updated] %.10s..%.10s %s\n", a_str, b_str, refname);
}
return 0;
}
void test_network_fetch__can_fetch_the_whole_libgit2_repository_through_http(void)
{
git_off_t bytes = 0;
git_indexer_stats stats;
stats.processed = 0;
stats.total = 0;
cl_git_pass(git_remote_new(&remote, repo, "http://github.com/libgit2/libgit2.git", "libgit2"));
cl_git_pass(git_remote_set_fetchspec(remote, "refs/*:refs/*"));
cl_git_pass(git_remote_save(remote));
cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH));
cl_git_pass(git_remote_download(remote, &bytes, &stats));
git_remote_disconnect(remote);
cl_git_pass(git_remote_update_tips(remote, update_cb));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment