1 #include "clar_libgit2.h"
7 static int transfer_cb(const git_transfer_progress
*stats
, void *payload
)
9 int *callcount
= (int*)payload
;
15 static void cleanup_local_repo(void *path
)
17 cl_fixture_cleanup((char *)path
);
20 void test_network_fetchlocal__complete(void)
25 git_strarray refnames
= {0};
27 const char *url
= cl_git_fixture_url("testrepo.git");
28 git_remote_callbacks callbacks
= GIT_REMOTE_CALLBACKS_INIT
;
30 callbacks
.transfer_progress
= transfer_cb
;
31 callbacks
.payload
= &callcount
;
33 cl_set_cleanup(&cleanup_local_repo
, "foo");
34 cl_git_pass(git_repository_init(&repo
, "foo", true));
36 cl_git_pass(git_remote_create(&origin
, repo
, GIT_REMOTE_ORIGIN
, url
));
37 git_remote_set_callbacks(origin
, &callbacks
);
38 cl_git_pass(git_remote_connect(origin
, GIT_DIRECTION_FETCH
));
39 cl_git_pass(git_remote_download(origin
, NULL
));
40 cl_git_pass(git_remote_update_tips(origin
, NULL
, NULL
));
42 cl_git_pass(git_reference_list(&refnames
, repo
));
43 cl_assert_equal_i(19, (int)refnames
.count
);
44 cl_assert(callcount
> 0);
46 git_strarray_free(&refnames
);
47 git_remote_free(origin
);
48 git_repository_free(repo
);
51 static void cleanup_sandbox(void *unused
)
54 cl_git_sandbox_cleanup();
57 void test_network_fetchlocal__partial(void)
59 git_repository
*repo
= cl_git_sandbox_init("partial-testrepo");
62 git_strarray refnames
= {0};
64 git_remote_callbacks callbacks
= GIT_REMOTE_CALLBACKS_INIT
;
66 callbacks
.transfer_progress
= transfer_cb
;
67 callbacks
.payload
= &callcount
;
69 cl_set_cleanup(&cleanup_sandbox
, NULL
);
70 cl_git_pass(git_reference_list(&refnames
, repo
));
71 cl_assert_equal_i(1, (int)refnames
.count
);
73 url
= cl_git_fixture_url("testrepo.git");
74 cl_git_pass(git_remote_create(&origin
, repo
, GIT_REMOTE_ORIGIN
, url
));
75 git_remote_set_callbacks(origin
, &callbacks
);
76 cl_git_pass(git_remote_connect(origin
, GIT_DIRECTION_FETCH
));
77 cl_git_pass(git_remote_download(origin
, NULL
));
78 cl_git_pass(git_remote_update_tips(origin
, NULL
, NULL
));
80 git_strarray_free(&refnames
);
82 cl_git_pass(git_reference_list(&refnames
, repo
));
83 cl_assert_equal_i(20, (int)refnames
.count
); /* 18 remote + 1 local */
84 cl_assert(callcount
> 0);
86 git_strarray_free(&refnames
);
87 git_remote_free(origin
);
90 static int remote_mirror_cb(git_remote
**out
, git_repository
*repo
,
91 const char *name
, const char *url
, void *payload
)
98 if ((error
= git_remote_create(&remote
, repo
, name
, url
)) < 0)
101 git_remote_clear_refspecs(remote
);
103 if ((error
= git_remote_add_fetch(remote
, "+refs/*:refs/*")) < 0) {
104 git_remote_free(remote
);
112 void test_network_fetchlocal__clone_into_mirror(void)
114 git_clone_options opts
= GIT_CLONE_OPTIONS_INIT
;
115 git_repository
*repo
;
119 opts
.remote_cb
= remote_mirror_cb
;
120 cl_git_pass(git_clone(&repo
, cl_git_fixture_url("testrepo.git"), "./foo.git", &opts
));
122 cl_git_pass(git_reference_lookup(&head
, repo
, "HEAD"));
123 cl_assert_equal_i(GIT_REF_SYMBOLIC
, git_reference_type(head
));
124 cl_assert_equal_s("refs/heads/master", git_reference_symbolic_target(head
));
126 git_reference_free(head
);
127 git_repository_free(repo
);
128 cl_fixture_cleanup("./foo.git");
131 void test_network_fetchlocal__multi_remotes(void)
133 git_repository
*repo
= cl_git_sandbox_init("testrepo.git");
134 git_remote
*test
, *test2
;
135 git_strarray refnames
= {0};
136 git_remote_callbacks callbacks
= GIT_REMOTE_CALLBACKS_INIT
;
138 callbacks
.transfer_progress
= transfer_cb
;
139 cl_git_pass(git_remote_load(&test
, repo
, "test"));
140 cl_git_pass(git_remote_set_url(test
, cl_git_fixture_url("testrepo.git")));
141 git_remote_set_callbacks(test
, &callbacks
);
142 cl_git_pass(git_remote_connect(test
, GIT_DIRECTION_FETCH
));
143 cl_git_pass(git_remote_download(test
, NULL
));
144 cl_git_pass(git_remote_update_tips(test
, NULL
, NULL
));
146 cl_git_pass(git_reference_list(&refnames
, repo
));
147 cl_assert_equal_i(32, (int)refnames
.count
);
149 cl_git_pass(git_remote_load(&test2
, repo
, "test_with_pushurl"));
150 cl_git_pass(git_remote_set_url(test2
, cl_git_fixture_url("testrepo.git")));
151 git_remote_set_callbacks(test2
, &callbacks
);
152 cl_git_pass(git_remote_connect(test2
, GIT_DIRECTION_FETCH
));
153 cl_git_pass(git_remote_download(test2
, NULL
));
154 cl_git_pass(git_remote_update_tips(test2
, NULL
, NULL
));
156 cl_git_pass(git_reference_list(&refnames
, repo
));
157 cl_assert_equal_i(44, (int)refnames
.count
);
159 git_strarray_free(&refnames
);
160 git_remote_free(test
);
161 git_remote_free(test2
);
162 git_repository_free(repo
);