]>
Commit | Line | Data |
---|---|---|
db1f7e59 | 1 | #include "clay_libgit2.h" |
2 | #include "transport.h" | |
3 | #include "buffer.h" | |
4 | #include "path.h" | |
5 | ||
6 | static git_repository *repo; | |
7 | static git_buf file_path_buf = GIT_BUF_INIT; | |
8 | static git_remote *remote; | |
9 | ||
10 | static void build_local_file_url(git_buf *out, const char *fixture) | |
11 | { | |
12 | git_buf path_buf = GIT_BUF_INIT; | |
13 | ||
14 | cl_git_pass(git_path_prettify_dir(&path_buf, cl_fixture(fixture), NULL)); | |
15 | cl_git_pass(git_buf_puts(out, "file://")); | |
16 | ||
17 | #ifdef _MSC_VER | |
18 | /* | |
19 | * A FILE uri matches the following format: file://[host]/path | |
20 | * where "host" can be empty and "path" is an absolute path to the resource. | |
21 | * | |
22 | * In this test, no hostname is used, but we have to ensure the leading triple slashes: | |
23 | * | |
24 | * *nix: file:///usr/home/... | |
25 | * Windows: file:///C:/Users/... | |
26 | */ | |
27 | cl_git_pass(git_buf_putc(out, '/')); | |
28 | #endif | |
29 | ||
30 | cl_git_pass(git_buf_puts(out, git_buf_cstr(&path_buf))); | |
31 | ||
32 | git_buf_free(&path_buf); | |
33 | } | |
34 | ||
35 | void test_network_remotelocal__initialize(void) | |
36 | { | |
37 | cl_fixture("remotelocal"); | |
38 | cl_git_pass(git_repository_init(&repo, "remotelocal/", 0)); | |
39 | cl_assert(repo != NULL); | |
40 | ||
41 | build_local_file_url(&file_path_buf, "testrepo.git"); | |
42 | ||
43 | cl_git_pass(git_remote_new(&remote, repo, git_buf_cstr(&file_path_buf), NULL)); | |
44 | cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH)); | |
45 | } | |
46 | ||
47 | void test_network_remotelocal__cleanup(void) | |
48 | { | |
49 | git_remote_free(remote); | |
50 | git_buf_free(&file_path_buf); | |
51 | git_repository_free(repo); | |
52 | cl_fixture_cleanup("remotelocal"); | |
53 | } | |
54 | ||
55 | static int count_ref__cb(git_remote_head *head, void *payload) | |
56 | { | |
57 | int *count = (int *)payload; | |
58 | ||
59 | (*count)++; | |
60 | ||
61 | return GIT_SUCCESS; | |
62 | } | |
63 | ||
64 | void test_network_remotelocal__retrieve_advertised_references(void) | |
65 | { | |
66 | int how_many_refs = 0; | |
67 | ||
68 | cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs)); | |
69 | ||
70 | cl_assert(how_many_refs == 12); /* 1 HEAD + 9 refs + 2 peeled tags */ | |
71 | } |