1 #include "clar_libgit2.h"
3 CL_IN_CATEGORY("network")
5 static git_repository
*_repo
;
8 void test_network_fetch__initialize(void)
10 cl_git_pass(git_repository_init(&_repo
, "./fetch", 0));
13 void test_network_fetch__cleanup(void)
15 git_repository_free(_repo
);
16 cl_fixture_cleanup("./fetch");
19 static int update_tips(const char *refname
, const git_oid
*a
, const git_oid
*b
, void *data
)
21 GIT_UNUSED(refname
); GIT_UNUSED(a
); GIT_UNUSED(b
); GIT_UNUSED(data
);
28 static void progress(const git_transfer_progress
*stats
, void *payload
)
30 int *bytes_received
= (int*)payload
;
31 *bytes_received
= stats
->received_bytes
;
34 static void do_fetch(const char *url
, int flag
, int n
)
37 git_remote_callbacks callbacks
;
38 int bytes_received
= 0;
40 memset(&callbacks
, 0, sizeof(git_remote_callbacks
));
41 callbacks
.update_tips
= update_tips
;
44 cl_git_pass(git_remote_add(&remote
, _repo
, "test", url
));
45 git_remote_set_callbacks(remote
, &callbacks
);
46 git_remote_set_autotag(remote
, flag
);
47 cl_git_pass(git_remote_connect(remote
, GIT_DIR_FETCH
));
48 cl_git_pass(git_remote_download(remote
, progress
, &bytes_received
));
49 git_remote_disconnect(remote
);
50 cl_git_pass(git_remote_update_tips(remote
));
51 cl_assert_equal_i(counter
, n
);
52 cl_assert(bytes_received
> 0);
54 git_remote_free(remote
);
57 void test_network_fetch__default_git(void)
59 do_fetch("git://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_AUTO
, 6);
62 void test_network_fetch__default_http(void)
64 do_fetch("http://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_AUTO
, 6);
67 void test_network_fetch__no_tags_git(void)
69 do_fetch("git://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_NONE
, 3);
72 void test_network_fetch__no_tags_http(void)
74 do_fetch("http://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_NONE
, 3);