]>
Commit | Line | Data |
---|---|---|
3fd1520c | 1 | #include "clar_libgit2.h" |
db1f7e59 | 2 | #include "buffer.h" |
3 | #include "path.h" | |
e2580375 | 4 | #include "posix.h" |
db1f7e59 | 5 | |
6 | static git_repository *repo; | |
7 | static git_buf file_path_buf = GIT_BUF_INIT; | |
8 | static git_remote *remote; | |
9 | ||
db1f7e59 | 10 | void test_network_remotelocal__initialize(void) |
11 | { | |
db1f7e59 | 12 | cl_git_pass(git_repository_init(&repo, "remotelocal/", 0)); |
13 | cl_assert(repo != NULL); | |
db1f7e59 | 14 | } |
15 | ||
16 | void test_network_remotelocal__cleanup(void) | |
17 | { | |
db1f7e59 | 18 | git_buf_free(&file_path_buf); |
9094d30b SC |
19 | |
20 | git_remote_free(remote); | |
21 | remote = NULL; | |
22 | ||
db1f7e59 | 23 | git_repository_free(repo); |
9094d30b SC |
24 | repo = NULL; |
25 | ||
db1f7e59 | 26 | cl_fixture_cleanup("remotelocal"); |
27 | } | |
28 | ||
29 | static int count_ref__cb(git_remote_head *head, void *payload) | |
30 | { | |
31 | int *count = (int *)payload; | |
32 | ||
d16e4b2b | 33 | (void)head; |
db1f7e59 | 34 | (*count)++; |
35 | ||
e172cf08 | 36 | return 0; |
db1f7e59 | 37 | } |
38 | ||
79fd4230 | 39 | static int ensure_peeled__cb(git_remote_head *head, void *payload) |
40 | { | |
41 | GIT_UNUSED(payload); | |
42 | ||
43 | if(strcmp(head->name, "refs/tags/test^{}") != 0) | |
44 | return 0; | |
45 | ||
46 | return git_oid_streq(&head->oid, "e90810b8df3e80c413d903f631643c716887138d"); | |
47 | } | |
48 | ||
e2580375 | 49 | static void connect_to_local_repository(const char *local_repository) |
50 | { | |
2ff1a0d0 | 51 | git_buf_sets(&file_path_buf, cl_git_path_url(local_repository)); |
e2580375 | 52 | |
0642c143 | 53 | cl_git_pass(git_remote_create_inmemory(&remote, repo, NULL, git_buf_cstr(&file_path_buf))); |
df705148 | 54 | cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH)); |
e2580375 | 55 | |
56 | } | |
57 | ||
36c88422 AS |
58 | void test_network_remotelocal__connected(void) |
59 | { | |
60 | connect_to_local_repository(cl_fixture("testrepo.git")); | |
61 | cl_assert(git_remote_connected(remote)); | |
62 | ||
63 | git_remote_disconnect(remote); | |
64 | cl_assert(!git_remote_connected(remote)); | |
65 | } | |
66 | ||
db1f7e59 | 67 | void test_network_remotelocal__retrieve_advertised_references(void) |
68 | { | |
69 | int how_many_refs = 0; | |
70 | ||
e2580375 | 71 | connect_to_local_repository(cl_fixture("testrepo.git")); |
72 | ||
db1f7e59 | 73 | cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs)); |
74 | ||
e16fc07f | 75 | cl_assert_equal_i(how_many_refs, 26); |
db1f7e59 | 76 | } |
e2580375 | 77 | |
78 | void test_network_remotelocal__retrieve_advertised_references_from_spaced_repository(void) | |
79 | { | |
80 | int how_many_refs = 0; | |
81 | ||
82 | cl_fixture_sandbox("testrepo.git"); | |
83 | cl_git_pass(p_rename("testrepo.git", "spaced testrepo.git")); | |
84 | ||
85 | connect_to_local_repository("spaced testrepo.git"); | |
86 | ||
87 | cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs)); | |
88 | ||
e16fc07f | 89 | cl_assert_equal_i(how_many_refs, 26); |
e2580375 | 90 | |
79fd4230 | 91 | git_remote_free(remote); /* Disconnect from the "spaced repo" before the cleanup */ |
92 | remote = NULL; | |
93 | ||
e2580375 | 94 | cl_fixture_cleanup("spaced testrepo.git"); |
95 | } | |
79fd4230 | 96 | |
97 | void test_network_remotelocal__nested_tags_are_completely_peeled(void) | |
98 | { | |
99 | connect_to_local_repository(cl_fixture("testrepo.git")); | |
100 | ||
101 | cl_git_pass(git_remote_ls(remote, &ensure_peeled__cb, NULL)); | |
102 | } |