]>
git.proxmox.com Git - libgit2.git/blob - tests/online/remotes.c
1 #include "clar_libgit2.h"
3 #define URL "https://github.com/libgit2/TestGitRepository"
4 #define REFSPEC "refs/heads/first-merge:refs/remotes/origin/first-merge"
6 static int remote_single_branch(git_remote
**out
, git_repository
*repo
, const char *name
, const char *url
, void *payload
)
10 cl_git_pass(git_remote_create_with_fetchspec(out
, repo
, name
, url
, REFSPEC
));
15 void test_online_remotes__single_branch(void)
17 git_clone_options opts
= GIT_CLONE_OPTIONS_INIT
;
23 opts
.remote_cb
= remote_single_branch
;
24 opts
.checkout_branch
= "first-merge";
26 cl_git_pass(git_clone(&repo
, URL
, "./single-branch", &opts
));
27 cl_git_pass(git_reference_list(&refs
, repo
));
29 for (i
= 0; i
< refs
.count
; i
++) {
30 if (!git__prefixcmp(refs
.strings
[i
], "refs/heads/"))
33 cl_assert_equal_i(1, count
);
35 git_strarray_dispose(&refs
);
37 cl_git_pass(git_remote_lookup(&remote
, repo
, "origin"));
38 cl_git_pass(git_remote_get_fetch_refspecs(&refs
, remote
));
40 cl_assert_equal_i(1, refs
.count
);
41 cl_assert_equal_s(REFSPEC
, refs
.strings
[0]);
43 git_strarray_dispose(&refs
);
44 git_remote_free(remote
);
45 git_repository_free(repo
);
48 void test_online_remotes__restricted_refspecs(void)
50 git_clone_options opts
= GIT_CLONE_OPTIONS_INIT
;
53 opts
.remote_cb
= remote_single_branch
;
55 cl_git_fail_with(GIT_EINVALIDSPEC
, git_clone(&repo
, URL
, "./restrict-refspec", &opts
));
58 void test_online_remotes__detached_remote_fails_downloading(void)
62 cl_git_pass(git_remote_create_detached(&remote
, URL
));
63 cl_git_pass(git_remote_connect(remote
, GIT_DIRECTION_FETCH
, NULL
, NULL
, NULL
));
64 cl_git_fail(git_remote_download(remote
, NULL
, NULL
));
66 git_remote_free(remote
);
69 void test_online_remotes__detached_remote_fails_uploading(void)
73 cl_git_pass(git_remote_create_detached(&remote
, URL
));
74 cl_git_pass(git_remote_connect(remote
, GIT_DIRECTION_FETCH
, NULL
, NULL
, NULL
));
75 cl_git_fail(git_remote_upload(remote
, NULL
, NULL
));
77 git_remote_free(remote
);
80 void test_online_remotes__detached_remote_fails_pushing(void)
84 cl_git_pass(git_remote_create_detached(&remote
, URL
));
85 cl_git_pass(git_remote_connect(remote
, GIT_DIRECTION_FETCH
, NULL
, NULL
, NULL
));
86 cl_git_fail(git_remote_push(remote
, NULL
, NULL
));
88 git_remote_free(remote
);
91 void test_online_remotes__detached_remote_succeeds_ls(void)
93 const char *refs
[] = {
95 "refs/heads/first-merge",
97 "refs/heads/no-parent",
98 "refs/tags/annotated_tag",
99 "refs/tags/annotated_tag^{}",
101 "refs/tags/commit_tree",
102 "refs/tags/nearly-dangling",
104 const git_remote_head
**heads
;
108 cl_git_pass(git_remote_create_detached(&remote
, URL
));
109 cl_git_pass(git_remote_connect(remote
, GIT_DIRECTION_FETCH
, NULL
, NULL
, NULL
));
110 cl_git_pass(git_remote_ls(&heads
, &n
, remote
));
112 cl_assert_equal_sz(n
, 9);
113 for (i
= 0; i
< n
; i
++) {
116 for (j
= 0; j
< ARRAY_SIZE(refs
); j
++) {
117 if (!strcmp(heads
[i
]->name
, refs
[j
])) {
123 cl_assert_(found
, heads
[i
]->name
);
126 git_remote_free(remote
);