]> git.proxmox.com Git - libgit2.git/blame - tests/libgit2/network/remote/remotes.c
Merge https://salsa.debian.org/debian/libgit2 into proxmox/bullseye
[libgit2.git] / tests / libgit2 / network / remote / remotes.c
CommitLineData
3fd1520c 1#include "clar_libgit2.h"
9a97f49e 2#include "config/config_helpers.h"
279afd2a 3#include "refspec.h"
eff5b499 4#include "remote.h"
3a2626f3 5
9462c471
VM
6static git_remote *_remote;
7static git_repository *_repo;
8static const git_refspec *_refspec;
3a2626f3 9
624924e8 10void test_network_remote_remotes__initialize(void)
3a2626f3 11{
e497b16c 12 _repo = cl_git_sandbox_init("testrepo.git");
9462c471 13
209425ce 14 cl_git_pass(git_remote_lookup(&_remote, _repo, "test"));
9462c471 15
1ffd0806 16 _refspec = git_remote_get_refspec(_remote, 0);
9462c471 17 cl_assert(_refspec != NULL);
3a2626f3
CMN
18}
19
624924e8 20void test_network_remote_remotes__cleanup(void)
3a2626f3 21{
9462c471 22 git_remote_free(_remote);
9094d30b
SC
23 _remote = NULL;
24
e497b16c 25 cl_git_sandbox_cleanup();
3a2626f3
CMN
26}
27
624924e8 28void test_network_remote_remotes__parsing(void)
3a2626f3 29{
e579e0f7 30 git_str url = GIT_STR_INIT;
8689a69d
SC
31 git_remote *_remote2 = NULL;
32
946a6dc4
VM
33 cl_assert_equal_s(git_remote_name(_remote), "test");
34 cl_assert_equal_s(git_remote_url(_remote), "git://github.com/libgit2/libgit2");
8689a69d
SC
35 cl_assert(git_remote_pushurl(_remote) == NULL);
36
22a2d3d5
UG
37 cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, NULL));
38 cl_assert_equal_s(url.ptr, "git://github.com/libgit2/libgit2");
39
40 cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, NULL));
41 cl_assert_equal_s(url.ptr, "git://github.com/libgit2/libgit2");
eff5b499 42
209425ce 43 cl_git_pass(git_remote_lookup(&_remote2, _repo, "test_with_pushurl"));
8689a69d
SC
44 cl_assert_equal_s(git_remote_name(_remote2), "test_with_pushurl");
45 cl_assert_equal_s(git_remote_url(_remote2), "git://github.com/libgit2/fetchlibgit2");
46 cl_assert_equal_s(git_remote_pushurl(_remote2), "git://github.com/libgit2/pushlibgit2");
eff5b499 47
22a2d3d5
UG
48 cl_git_pass(git_remote__urlfordirection(&url, _remote2, GIT_DIRECTION_FETCH, NULL));
49 cl_assert_equal_s(url.ptr, "git://github.com/libgit2/fetchlibgit2");
50
51 cl_git_pass(git_remote__urlfordirection(&url, _remote2, GIT_DIRECTION_PUSH, NULL));
52 cl_assert_equal_s(url.ptr, "git://github.com/libgit2/pushlibgit2");
eff5b499 53
8689a69d 54 git_remote_free(_remote2);
e579e0f7 55 git_str_dispose(&url);
22a2d3d5
UG
56}
57
c25aa7cd
PP
58static int remote_ready_callback(git_remote *remote, int direction, void *payload)
59{
60 if (direction == GIT_DIRECTION_PUSH) {
61 const char *url = git_remote_pushurl(remote);
62
63 cl_assert_equal_p(url, NULL);;
64 cl_assert_equal_s(payload, "payload");
65 return git_remote_set_instance_pushurl(remote, "push_url");
66 }
67
68 if (direction == GIT_DIRECTION_FETCH) {
69 const char *url = git_remote_url(remote);
70
71 cl_assert_equal_s(url, "git://github.com/libgit2/libgit2");
72 cl_assert_equal_s(payload, "payload");
73 return git_remote_set_instance_url(remote, "fetch_url");
74 }
75
76 return -1;
77}
78
79void test_network_remote_remotes__remote_ready(void)
80{
e579e0f7 81 git_str url = GIT_STR_INIT;
c25aa7cd
PP
82
83 git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
84 callbacks.remote_ready = remote_ready_callback;
85 callbacks.payload = "payload";
86
87 cl_assert_equal_s(git_remote_name(_remote), "test");
88 cl_assert_equal_s(git_remote_url(_remote), "git://github.com/libgit2/libgit2");
89 cl_assert(git_remote_pushurl(_remote) == NULL);
90
91 cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, &callbacks));
92 cl_assert_equal_s(url.ptr, "fetch_url");
93
94 cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, &callbacks));
95 cl_assert_equal_s(url.ptr, "push_url");
96
e579e0f7 97 git_str_dispose(&url);
c25aa7cd
PP
98}
99
100#ifndef GIT_DEPRECATE_HARD
22a2d3d5
UG
101static int urlresolve_callback(git_buf *url_resolved, const char *url, int direction, void *payload)
102{
e579e0f7
MB
103 int error = -1;
104
22a2d3d5
UG
105 cl_assert(strcmp(url, "git://github.com/libgit2/libgit2") == 0);
106 cl_assert(strcmp(payload, "payload") == 0);
107 cl_assert(url_resolved->size == 0);
108
109 if (direction == GIT_DIRECTION_PUSH)
e579e0f7 110 error = git_buf_set(url_resolved, "pushresolve", strlen("pushresolve") + 1);
22a2d3d5 111 if (direction == GIT_DIRECTION_FETCH)
e579e0f7 112 error = git_buf_set(url_resolved, "fetchresolve", strlen("fetchresolve") + 1);
22a2d3d5 113
e579e0f7 114 return error;
22a2d3d5 115}
c25aa7cd 116#endif
22a2d3d5
UG
117
118void test_network_remote_remotes__urlresolve(void)
119{
c25aa7cd 120#ifndef GIT_DEPRECATE_HARD
e579e0f7 121 git_str url = GIT_STR_INIT;
22a2d3d5
UG
122
123 git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
124 callbacks.resolve_url = urlresolve_callback;
125 callbacks.payload = "payload";
126
127 cl_assert_equal_s(git_remote_name(_remote), "test");
128 cl_assert_equal_s(git_remote_url(_remote), "git://github.com/libgit2/libgit2");
129 cl_assert(git_remote_pushurl(_remote) == NULL);
130
131 cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, &callbacks));
132 cl_assert_equal_s(url.ptr, "fetchresolve");
133
134 cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, &callbacks));
135 cl_assert_equal_s(url.ptr, "pushresolve");
136
e579e0f7 137 git_str_dispose(&url);
c25aa7cd 138#endif
22a2d3d5
UG
139}
140
c25aa7cd 141#ifndef GIT_DEPRECATE_HARD
22a2d3d5
UG
142static int urlresolve_passthrough_callback(git_buf *url_resolved, const char *url, int direction, void *payload)
143{
144 GIT_UNUSED(url_resolved);
145 GIT_UNUSED(url);
146 GIT_UNUSED(direction);
147 GIT_UNUSED(payload);
148 return GIT_PASSTHROUGH;
149}
c25aa7cd 150#endif
22a2d3d5
UG
151
152void test_network_remote_remotes__urlresolve_passthrough(void)
153{
c25aa7cd 154#ifndef GIT_DEPRECATE_HARD
e579e0f7 155 git_str url = GIT_STR_INIT;
22a2d3d5
UG
156 const char *orig_url = "git://github.com/libgit2/libgit2";
157
158 git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
159 callbacks.resolve_url = urlresolve_passthrough_callback;
160
161 cl_assert_equal_s(git_remote_name(_remote), "test");
162 cl_assert_equal_s(git_remote_url(_remote), orig_url);
163 cl_assert(git_remote_pushurl(_remote) == NULL);
164
165 cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, &callbacks));
166 cl_assert_equal_s(url.ptr, orig_url);
167
168 cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, &callbacks));
169 cl_assert_equal_s(url.ptr, orig_url);
170
e579e0f7 171 git_str_dispose(&url);
c25aa7cd
PP
172#endif
173}
174
175void test_network_remote_remotes__instance_url(void)
176{
e579e0f7 177 git_str url = GIT_STR_INIT;
c25aa7cd
PP
178 const char *orig_url = "git://github.com/libgit2/libgit2";
179
180 cl_assert_equal_s(git_remote_name(_remote), "test");
181 cl_assert_equal_s(git_remote_url(_remote), orig_url);
182
183 cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, NULL));
184 cl_assert_equal_s(url.ptr, orig_url);
e579e0f7 185 git_str_clear(&url);
c25aa7cd
PP
186
187 cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, NULL));
188 cl_assert_equal_s(url.ptr, orig_url);
e579e0f7 189 git_str_clear(&url);
c25aa7cd
PP
190
191 /* Setting the instance url updates the fetch and push URLs */
192 git_remote_set_instance_url(_remote, "https://github.com/new/remote/url");
193 cl_assert_equal_s(git_remote_url(_remote), "https://github.com/new/remote/url");
194 cl_assert_equal_p(git_remote_pushurl(_remote), NULL);
195
196 cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, NULL));
197 cl_assert_equal_s(url.ptr, "https://github.com/new/remote/url");
e579e0f7 198 git_str_clear(&url);
c25aa7cd
PP
199
200 cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, NULL));
201 cl_assert_equal_s(url.ptr, "https://github.com/new/remote/url");
e579e0f7 202 git_str_clear(&url);
c25aa7cd
PP
203
204 /* Setting the instance push url updates only the push URL */
205 git_remote_set_instance_pushurl(_remote, "https://github.com/new/push/url");
206 cl_assert_equal_s(git_remote_url(_remote), "https://github.com/new/remote/url");
207 cl_assert_equal_s(git_remote_pushurl(_remote), "https://github.com/new/push/url");
208
209 cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, NULL));
210 cl_assert_equal_s(url.ptr, "https://github.com/new/remote/url");
e579e0f7 211 git_str_clear(&url);
c25aa7cd
PP
212
213 cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, NULL));
214 cl_assert_equal_s(url.ptr, "https://github.com/new/push/url");
e579e0f7 215 git_str_clear(&url);
c25aa7cd 216
e579e0f7 217 git_str_dispose(&url);
8689a69d
SC
218}
219
624924e8 220void test_network_remote_remotes__pushurl(void)
8689a69d 221{
22261344
CMN
222 const char *name = git_remote_name(_remote);
223 git_remote *mod;
224
225 cl_git_pass(git_remote_set_pushurl(_repo, name, "git://github.com/libgit2/notlibgit2"));
226 cl_git_pass(git_remote_lookup(&mod, _repo, name));
227 cl_assert_equal_s(git_remote_pushurl(mod), "git://github.com/libgit2/notlibgit2");
228 git_remote_free(mod);
229
230 cl_git_pass(git_remote_set_pushurl(_repo, name, NULL));
231 cl_git_pass(git_remote_lookup(&mod, _repo, name));
232 cl_assert(git_remote_pushurl(mod) == NULL);
233 git_remote_free(mod);
3a2626f3
CMN
234}
235
d723dbed
AS
236void test_network_remote_remotes__error_when_not_found(void)
237{
238 git_remote *r;
209425ce 239 cl_git_fail_with(git_remote_lookup(&r, _repo, "does-not-exist"), GIT_ENOTFOUND);
d723dbed 240
ac3d33df
JK
241 cl_assert(git_error_last() != NULL);
242 cl_assert(git_error_last()->klass == GIT_ERROR_CONFIG);
d723dbed
AS
243}
244
624924e8 245void test_network_remote_remotes__error_when_no_push_available(void)
b90eb84f
SB
246{
247 git_remote *r;
058b753c 248 git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
fe794b2e
CMN
249 char *specs = {
250 "refs/heads/master",
251 };
252 git_strarray arr = {
253 &specs,
254 1,
255 };
256
b90eb84f 257
ae5b9362 258 cl_git_pass(git_remote_create_anonymous(&r, _repo, cl_fixture("testrepo.git")));
b90eb84f 259
058b753c 260 callbacks.transport = git_transport_local;
07bd3e57 261 cl_git_pass(git_remote_connect(r, GIT_DIRECTION_PUSH, &callbacks, NULL, NULL));
b90eb84f
SB
262
263 /* Make sure that push is really not available */
1697cd6f 264 r->transport->push = NULL;
4cc326e9 265
fe794b2e 266 cl_git_fail_with(-1, git_remote_upload(r, &arr, NULL));
b90eb84f 267
b90eb84f
SB
268 git_remote_free(r);
269}
270
624924e8 271void test_network_remote_remotes__refspec_parsing(void)
3a2626f3 272{
946a6dc4
VM
273 cl_assert_equal_s(git_refspec_src(_refspec), "refs/heads/*");
274 cl_assert_equal_s(git_refspec_dst(_refspec), "refs/remotes/test/*");
3a2626f3
CMN
275}
276
4330ab26 277void test_network_remote_remotes__add_fetchspec(void)
bcb8c007 278{
4330ab26
CMN
279 size_t size;
280
1ffd0806 281 size = git_remote_refspec_count(_remote);
4330ab26 282
77254990 283 cl_git_pass(git_remote_add_fetch(_repo, "test", "refs/*:refs/*"));
4330ab26 284 size++;
77254990
CMN
285
286 git_remote_free(_remote);
287 cl_git_pass(git_remote_lookup(&_remote, _repo, "test"));
288
0f938c6b 289 cl_assert_equal_i((int)size, (int)git_remote_refspec_count(_remote));
4330ab26 290
1ffd0806 291 _refspec = git_remote_get_refspec(_remote, size - 1);
946a6dc4
VM
292 cl_assert_equal_s(git_refspec_src(_refspec), "refs/*");
293 cl_assert_equal_s(git_refspec_dst(_refspec), "refs/*");
1be680c4 294 cl_assert_equal_s(git_refspec_string(_refspec), "refs/*:refs/*");
0f938c6b 295 cl_assert_equal_b(_refspec->push, false);
c6e942fb
CMN
296
297 cl_git_fail_with(GIT_EINVALIDSPEC, git_remote_add_fetch(_repo, "test", "refs/*/foo/*:refs/*"));
bcb8c007
CMN
298}
299
40ef47dd
AS
300void test_network_remote_remotes__dup(void)
301{
302 git_strarray array;
303 git_remote *dup;
304
305 cl_git_pass(git_remote_dup(&dup, _remote));
306
307 cl_assert_equal_s(git_remote_name(dup), git_remote_name(_remote));
308 cl_assert_equal_s(git_remote_url(dup), git_remote_url(_remote));
309 cl_assert_equal_s(git_remote_pushurl(dup), git_remote_pushurl(_remote));
310
311 cl_git_pass(git_remote_get_fetch_refspecs(&array, _remote));
312 cl_assert_equal_i(1, (int)array.count);
313 cl_assert_equal_s("+refs/heads/*:refs/remotes/test/*", array.strings[0]);
22a2d3d5 314 git_strarray_dispose(&array);
40ef47dd
AS
315
316 cl_git_pass(git_remote_get_push_refspecs(&array, _remote));
317 cl_assert_equal_i(0, (int)array.count);
22a2d3d5 318 git_strarray_dispose(&array);
991b2840
AS
319
320 git_remote_free(dup);
40ef47dd
AS
321}
322
4330ab26 323void test_network_remote_remotes__add_pushspec(void)
bcb8c007 324{
4330ab26
CMN
325 size_t size;
326
1ffd0806 327 size = git_remote_refspec_count(_remote);
4330ab26 328
77254990 329 cl_git_pass(git_remote_add_push(_repo, "test", "refs/*:refs/*"));
4330ab26 330 size++;
77254990
CMN
331
332 git_remote_free(_remote);
333 cl_git_pass(git_remote_lookup(&_remote, _repo, "test"));
334
0f938c6b 335 cl_assert_equal_i((int)size, (int)git_remote_refspec_count(_remote));
4330ab26 336
1ffd0806 337 _refspec = git_remote_get_refspec(_remote, size - 1);
946a6dc4
VM
338 cl_assert_equal_s(git_refspec_src(_refspec), "refs/*");
339 cl_assert_equal_s(git_refspec_dst(_refspec), "refs/*");
1be680c4 340 cl_assert_equal_s(git_refspec_string(_refspec), "refs/*:refs/*");
4330ab26 341
0f938c6b 342 cl_assert_equal_b(_refspec->push, true);
bcb8c007
CMN
343}
344
624924e8 345void test_network_remote_remotes__fnmatch(void)
3a2626f3 346{
3fbcac89
VM
347 cl_assert(git_refspec_src_matches(_refspec, "refs/heads/master"));
348 cl_assert(git_refspec_src_matches(_refspec, "refs/heads/multi/level/branch"));
3a2626f3
CMN
349}
350
624924e8 351void test_network_remote_remotes__transform(void)
3a2626f3 352{
bf522e08 353 git_buf ref = GIT_BUF_INIT;
3a2626f3 354
bf522e08 355 cl_git_pass(git_refspec_transform(&ref, _refspec, "refs/heads/master"));
96f12e70 356 cl_assert_equal_s(ref.ptr, "refs/remotes/test/master");
ac3d33df 357 git_buf_dispose(&ref);
3a2626f3 358}
279afd2a 359
624924e8 360void test_network_remote_remotes__transform_destination_to_source(void)
db4bb415 361{
bf522e08 362 git_buf ref = GIT_BUF_INIT;
db4bb415 363
bf522e08
CMN
364 cl_git_pass(git_refspec_rtransform(&ref, _refspec, "refs/remotes/test/master"));
365 cl_assert_equal_s(ref.ptr, "refs/heads/master");
ac3d33df 366 git_buf_dispose(&ref);
279afd2a 367}
9554cd51 368
624924e8 369void test_network_remote_remotes__missing_refspecs(void)
9554cd51
CMN
370{
371 git_config *cfg;
372
373 git_remote_free(_remote);
d5cf4665 374 _remote = NULL;
9554cd51
CMN
375
376 cl_git_pass(git_repository_config(&cfg, _repo));
377 cl_git_pass(git_config_set_string(cfg, "remote.specless.url", "http://example.com"));
209425ce 378 cl_git_pass(git_remote_lookup(&_remote, _repo, "specless"));
9554cd51
CMN
379
380 git_config_free(cfg);
381}
8171998f 382
0f838d27
CMN
383void test_network_remote_remotes__nonmatch_upstream_refspec(void)
384{
385 git_config *config;
386 git_remote *remote;
387 char *specstr[] = {
388 "refs/tags/*:refs/tags/*",
389 };
390 git_strarray specs = {
391 specstr,
392 1,
393 };
394
395 cl_git_pass(git_remote_create(&remote, _repo, "taggy", git_repository_path(_repo)));
396
397 /*
398 * Set the current branch's upstream remote to a dummy ref so we call into the code
399 * which tries to check for the current branch's upstream in the refspecs
400 */
401 cl_git_pass(git_repository_config(&config, _repo));
402 cl_git_pass(git_config_set_string(config, "branch.master.remote", "taggy"));
403 cl_git_pass(git_config_set_string(config, "branch.master.merge", "refs/heads/foo"));
404
8f0104ec 405 cl_git_pass(git_remote_fetch(remote, &specs, NULL, NULL));
0f838d27
CMN
406
407 git_remote_free(remote);
408}
409
624924e8 410void test_network_remote_remotes__list(void)
8171998f
CMN
411{
412 git_strarray list;
413 git_config *cfg;
414
415 cl_git_pass(git_remote_list(&list, _repo));
aec87f71 416 cl_assert(list.count == 5);
22a2d3d5 417 git_strarray_dispose(&list);
8171998f
CMN
418
419 cl_git_pass(git_repository_config(&cfg, _repo));
aec87f71 420
421 /* Create a new remote */
8171998f 422 cl_git_pass(git_config_set_string(cfg, "remote.specless.url", "http://example.com"));
aec87f71 423
424 /* Update a remote (previously without any url/pushurl entry) */
425 cl_git_pass(git_config_set_string(cfg, "remote.no-remote-url.pushurl", "http://example.com"));
426
8171998f 427 cl_git_pass(git_remote_list(&list, _repo));
aec87f71 428 cl_assert(list.count == 7);
22a2d3d5 429 git_strarray_dispose(&list);
8171998f
CMN
430
431 git_config_free(cfg);
432}
9fb70f37 433
624924e8 434void test_network_remote_remotes__loading_a_missing_remote_returns_ENOTFOUND(void)
9fb70f37 435{
d5cf4665
SC
436 git_remote_free(_remote);
437 _remote = NULL;
438
209425ce 439 cl_assert_equal_i(GIT_ENOTFOUND, git_remote_lookup(&_remote, _repo, "just-left-few-minutes-ago"));
9fb70f37 440}
a209a025 441
624924e8 442void test_network_remote_remotes__loading_with_an_invalid_name_returns_EINVALIDSPEC(void)
032ba9e4 443{
d5cf4665
SC
444 git_remote_free(_remote);
445 _remote = NULL;
446
209425ce 447 cl_assert_equal_i(GIT_EINVALIDSPEC, git_remote_lookup(&_remote, _repo, "Inv@{id"));
032ba9e4 448}
449
d27bf665 450/*
451 * $ git remote add addtest http://github.com/libgit2/libgit2
452 *
453 * $ cat .git/config
454 * [...]
455 * [remote "addtest"]
456 * url = http://github.com/libgit2/libgit2
a146ba9e 457 * fetch = +refs/heads/\*:refs/remotes/addtest/\*
d27bf665 458 */
624924e8 459void test_network_remote_remotes__add(void)
a209a025
CMN
460{
461 git_remote_free(_remote);
d5cf4665
SC
462 _remote = NULL;
463
40b99d05 464 cl_git_pass(git_remote_create(&_remote, _repo, "addtest", "http://github.com/libgit2/libgit2"));
215af2cc 465 cl_assert_equal_i(GIT_REMOTE_DOWNLOAD_TAGS_AUTO, git_remote_autotag(_remote));
d5cf4665 466
a209a025 467 git_remote_free(_remote);
d5cf4665 468 _remote = NULL;
a209a025 469
209425ce 470 cl_git_pass(git_remote_lookup(&_remote, _repo, "addtest"));
215af2cc 471 cl_assert_equal_i(GIT_REMOTE_DOWNLOAD_TAGS_AUTO, git_remote_autotag(_remote));
472
4330ab26 473 _refspec = git_vector_get(&_remote->refspecs, 0);
a7f8065f 474 cl_assert_equal_s("refs/heads/*", git_refspec_src(_refspec));
d27bf665 475 cl_assert(git_refspec_force(_refspec) == 1);
a7f8065f 476 cl_assert_equal_s("refs/remotes/addtest/*", git_refspec_dst(_refspec));
8689a69d 477 cl_assert_equal_s(git_remote_url(_remote), "http://github.com/libgit2/libgit2");
a209a025 478}
218c88a9 479
624924e8 480void test_network_remote_remotes__tagopt(void)
218c88a9 481{
35a8a8c5
CMN
482 const char *name = git_remote_name(_remote);
483
484 git_remote_set_autotag(_repo, name, GIT_REMOTE_DOWNLOAD_TAGS_ALL);
9a97f49e 485 assert_config_entry_value(_repo, "remote.test.tagopt", "--tags");
218c88a9 486
35a8a8c5 487 git_remote_set_autotag(_repo, name, GIT_REMOTE_DOWNLOAD_TAGS_NONE);
9a97f49e 488 assert_config_entry_value(_repo, "remote.test.tagopt", "--no-tags");
218c88a9 489
35a8a8c5 490 git_remote_set_autotag(_repo, name, GIT_REMOTE_DOWNLOAD_TAGS_AUTO);
9a97f49e 491 assert_config_entry_existence(_repo, "remote.test.tagopt", false);
218c88a9 492}
a2a61894 493
0b9ebb54 494void test_network_remote_remotes__can_load_with_an_empty_url(void)
a2a61894 495{
d5cf4665 496 git_remote *remote = NULL;
a2a61894 497
209425ce 498 cl_git_pass(git_remote_lookup(&remote, _repo, "empty-remote-url"));
0b9ebb54 499
ece24ef7 500 cl_assert(remote->url == NULL);
501 cl_assert(remote->pushurl == NULL);
502
07bd3e57 503 cl_git_fail(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL, NULL));
0b9ebb54 504
ac3d33df
JK
505 cl_assert(git_error_last() != NULL);
506 cl_assert(git_error_last()->klass == GIT_ERROR_INVALID);
ece24ef7 507
0b9ebb54 508 git_remote_free(remote);
a2a61894 509}
10711769 510
c9ffa84b 511void test_network_remote_remotes__can_load_with_only_an_empty_pushurl(void)
512{
513 git_remote *remote = NULL;
514
209425ce 515 cl_git_pass(git_remote_lookup(&remote, _repo, "empty-remote-pushurl"));
c9ffa84b 516
517 cl_assert(remote->url == NULL);
518 cl_assert(remote->pushurl == NULL);
519
07bd3e57 520 cl_git_fail(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL, NULL));
c9ffa84b 521
522 git_remote_free(remote);
523}
524
525void test_network_remote_remotes__returns_ENOTFOUND_when_neither_url_nor_pushurl(void)
526{
527 git_remote *remote = NULL;
528
529 cl_git_fail_with(
209425ce 530 git_remote_lookup(&remote, _repo, "no-remote-url"), GIT_ENOTFOUND);
c9ffa84b 531}
532
bc6374ea
CMN
533static const char *fetch_refspecs[] = {
534 "+refs/heads/*:refs/remotes/origin/*",
535 "refs/tags/*:refs/tags/*",
536 "+refs/pull/*:refs/pull/*",
537};
538
539static const char *push_refspecs[] = {
540 "refs/heads/*:refs/heads/*",
541 "refs/tags/*:refs/tags/*",
542 "refs/notes/*:refs/notes/*",
543};
544
545void test_network_remote_remotes__query_refspecs(void)
546{
547 git_remote *remote;
548 git_strarray array;
549 int i;
550
77254990
CMN
551 cl_git_pass(git_remote_create_with_fetchspec(&remote, _repo, "query", "git://github.com/libgit2/libgit2", NULL));
552 git_remote_free(remote);
bc6374ea
CMN
553
554 for (i = 0; i < 3; i++) {
77254990
CMN
555 cl_git_pass(git_remote_add_fetch(_repo, "query", fetch_refspecs[i]));
556 cl_git_pass(git_remote_add_push(_repo, "query", push_refspecs[i]));
bc6374ea
CMN
557 }
558
77254990
CMN
559 cl_git_pass(git_remote_lookup(&remote, _repo, "query"));
560
bc6374ea
CMN
561 cl_git_pass(git_remote_get_fetch_refspecs(&array, remote));
562 for (i = 0; i < 3; i++) {
563 cl_assert_equal_s(fetch_refspecs[i], array.strings[i]);
564 }
22a2d3d5 565 git_strarray_dispose(&array);
bc6374ea
CMN
566
567 cl_git_pass(git_remote_get_push_refspecs(&array, remote));
568 for (i = 0; i < 3; i++) {
569 cl_assert_equal_s(push_refspecs[i], array.strings[i]);
570 }
22a2d3d5 571 git_strarray_dispose(&array);
bc6374ea
CMN
572
573 git_remote_free(remote);
77254990 574 git_remote_delete(_repo, "test");
bc6374ea 575}