]>
Commit | Line | Data |
---|---|---|
db1f7e59 | 1 | #include "clay_libgit2.h" |
2 | #include "transport.h" | |
3 | #include "buffer.h" | |
4 | #include "path.h" | |
e2580375 | 5 | #include "posix.h" |
db1f7e59 | 6 | |
7 | static git_repository *repo; | |
8 | static git_buf file_path_buf = GIT_BUF_INIT; | |
9 | static git_remote *remote; | |
10 | ||
11 | static void build_local_file_url(git_buf *out, const char *fixture) | |
12 | { | |
e2580375 | 13 | const char *in_buf; |
14 | ||
db1f7e59 | 15 | git_buf path_buf = GIT_BUF_INIT; |
16 | ||
e2580375 | 17 | cl_git_pass(git_path_prettify_dir(&path_buf, fixture, NULL)); |
db1f7e59 | 18 | cl_git_pass(git_buf_puts(out, "file://")); |
19 | ||
20 | #ifdef _MSC_VER | |
21 | /* | |
22 | * A FILE uri matches the following format: file://[host]/path | |
23 | * where "host" can be empty and "path" is an absolute path to the resource. | |
24 | * | |
25 | * In this test, no hostname is used, but we have to ensure the leading triple slashes: | |
26 | * | |
27 | * *nix: file:///usr/home/... | |
28 | * Windows: file:///C:/Users/... | |
29 | */ | |
30 | cl_git_pass(git_buf_putc(out, '/')); | |
31 | #endif | |
32 | ||
e2580375 | 33 | in_buf = git_buf_cstr(&path_buf); |
34 | ||
35 | /* | |
36 | * A very hacky Url encoding that only takes care of escaping the spaces | |
37 | */ | |
38 | while (*in_buf) { | |
39 | if (*in_buf == ' ') | |
40 | cl_git_pass(git_buf_puts(out, "%20")); | |
41 | else | |
42 | cl_git_pass(git_buf_putc(out, *in_buf)); | |
43 | ||
44 | in_buf++; | |
45 | } | |
db1f7e59 | 46 | |
47 | git_buf_free(&path_buf); | |
48 | } | |
49 | ||
50 | void test_network_remotelocal__initialize(void) | |
51 | { | |
db1f7e59 | 52 | cl_git_pass(git_repository_init(&repo, "remotelocal/", 0)); |
53 | cl_assert(repo != NULL); | |
db1f7e59 | 54 | } |
55 | ||
56 | void test_network_remotelocal__cleanup(void) | |
57 | { | |
58 | git_remote_free(remote); | |
59 | git_buf_free(&file_path_buf); | |
60 | git_repository_free(repo); | |
61 | cl_fixture_cleanup("remotelocal"); | |
62 | } | |
63 | ||
64 | static int count_ref__cb(git_remote_head *head, void *payload) | |
65 | { | |
66 | int *count = (int *)payload; | |
67 | ||
d16e4b2b | 68 | (void)head; |
db1f7e59 | 69 | (*count)++; |
70 | ||
71 | return GIT_SUCCESS; | |
72 | } | |
73 | ||
e2580375 | 74 | static void connect_to_local_repository(const char *local_repository) |
75 | { | |
76 | build_local_file_url(&file_path_buf, local_repository); | |
77 | ||
78 | cl_git_pass(git_remote_new(&remote, repo, git_buf_cstr(&file_path_buf), NULL)); | |
79 | cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH)); | |
80 | ||
81 | } | |
82 | ||
db1f7e59 | 83 | void test_network_remotelocal__retrieve_advertised_references(void) |
84 | { | |
85 | int how_many_refs = 0; | |
86 | ||
e2580375 | 87 | connect_to_local_repository(cl_fixture("testrepo.git")); |
88 | ||
db1f7e59 | 89 | cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs)); |
90 | ||
91 | cl_assert(how_many_refs == 12); /* 1 HEAD + 9 refs + 2 peeled tags */ | |
92 | } | |
e2580375 | 93 | |
94 | void test_network_remotelocal__retrieve_advertised_references_from_spaced_repository(void) | |
95 | { | |
96 | int how_many_refs = 0; | |
97 | ||
98 | cl_fixture_sandbox("testrepo.git"); | |
99 | cl_git_pass(p_rename("testrepo.git", "spaced testrepo.git")); | |
100 | ||
101 | connect_to_local_repository("spaced testrepo.git"); | |
102 | ||
103 | cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs)); | |
104 | ||
105 | cl_assert(how_many_refs == 12); /* 1 HEAD */ | |
106 | ||
107 | cl_fixture_cleanup("spaced testrepo.git"); | |
108 | } |