]> git.proxmox.com Git - libgit2.git/blame - tests-clar/network/remotelocal.c
config: set an error message when asked to delete a non-existent key
[libgit2.git] / tests-clar / network / remotelocal.c
CommitLineData
3fd1520c 1#include "clar_libgit2.h"
db1f7e59 2#include "transport.h"
3#include "buffer.h"
4#include "path.h"
e2580375 5#include "posix.h"
db1f7e59 6
7static git_repository *repo;
8static git_buf file_path_buf = GIT_BUF_INIT;
9static git_remote *remote;
10
11static 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
50void 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
56void 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
64static 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
e172cf08 71 return 0;
db1f7e59 72}
73
79fd4230 74static int ensure_peeled__cb(git_remote_head *head, void *payload)
75{
76 GIT_UNUSED(payload);
77
78 if(strcmp(head->name, "refs/tags/test^{}") != 0)
79 return 0;
80
81 return git_oid_streq(&head->oid, "e90810b8df3e80c413d903f631643c716887138d");
82}
83
e2580375 84static void connect_to_local_repository(const char *local_repository)
85{
86 build_local_file_url(&file_path_buf, local_repository);
87
baaa8a44 88 cl_git_pass(git_remote_new(&remote, repo, NULL, git_buf_cstr(&file_path_buf), NULL));
e2580375 89 cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH));
90
91}
92
db1f7e59 93void test_network_remotelocal__retrieve_advertised_references(void)
94{
95 int how_many_refs = 0;
96
e2580375 97 connect_to_local_repository(cl_fixture("testrepo.git"));
98
db1f7e59 99 cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
100
3f46f313 101 cl_assert(how_many_refs == 14); /* 1 HEAD + 6 heads + 1 lightweight tag + 3 annotated tags + 3 peeled target */
db1f7e59 102}
e2580375 103
104void test_network_remotelocal__retrieve_advertised_references_from_spaced_repository(void)
105{
106 int how_many_refs = 0;
107
108 cl_fixture_sandbox("testrepo.git");
109 cl_git_pass(p_rename("testrepo.git", "spaced testrepo.git"));
110
111 connect_to_local_repository("spaced testrepo.git");
112
113 cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
114
3f46f313 115 cl_assert(how_many_refs == 14); /* 1 HEAD + 6 heads + 1 lightweight tag + 3 annotated tags + 3 peeled target */
e2580375 116
79fd4230 117 git_remote_free(remote); /* Disconnect from the "spaced repo" before the cleanup */
118 remote = NULL;
119
e2580375 120 cl_fixture_cleanup("spaced testrepo.git");
121}
79fd4230 122
123void test_network_remotelocal__nested_tags_are_completely_peeled(void)
124{
125 connect_to_local_repository(cl_fixture("testrepo.git"));
126
127 cl_git_pass(git_remote_ls(remote, &ensure_peeled__cb, NULL));
128}