]> git.proxmox.com Git - libgit2.git/blob - tests-clar/network/fetch.c
Improve docs, examples, warnings
[libgit2.git] / tests-clar / network / fetch.c
1 #include "clar_libgit2.h"
2
3 CL_IN_CATEGORY("network")
4
5 static git_repository *_repo;
6 static int counter;
7
8 void test_network_fetch__initialize(void)
9 {
10 cl_git_pass(git_repository_init(&_repo, "./fetch", 0));
11 }
12
13 void test_network_fetch__cleanup(void)
14 {
15 git_repository_free(_repo);
16 cl_fixture_cleanup("./fetch");
17 }
18
19 static int update_tips(const char *refname, const git_oid *a, const git_oid *b, void *data)
20 {
21 GIT_UNUSED(refname); GIT_UNUSED(a); GIT_UNUSED(b); GIT_UNUSED(data);
22
23 ++counter;
24
25 return 0;
26 }
27
28 static void progress(const git_transfer_progress *stats, void *payload)
29 {
30 int *bytes_received = (int*)payload;
31 *bytes_received = stats->received_bytes;
32 }
33
34 static void do_fetch(const char *url, int flag, int n)
35 {
36 git_remote *remote;
37 git_remote_callbacks callbacks;
38 int bytes_received = 0;
39
40 memset(&callbacks, 0, sizeof(git_remote_callbacks));
41 callbacks.update_tips = update_tips;
42 counter = 0;
43
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);
53
54 git_remote_free(remote);
55 }
56
57 void test_network_fetch__default_git(void)
58 {
59 do_fetch("git://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_AUTO, 6);
60 }
61
62 void test_network_fetch__default_http(void)
63 {
64 do_fetch("http://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_AUTO, 6);
65 }
66
67 void test_network_fetch__no_tags_git(void)
68 {
69 do_fetch("git://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_NONE, 3);
70 }
71
72 void test_network_fetch__no_tags_http(void)
73 {
74 do_fetch("http://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_NONE, 3);
75 }