]> git.proxmox.com Git - libgit2.git/blob - tests/clone/transport.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / clone / transport.c
1 #include "clar_libgit2.h"
2
3 #include "git2/clone.h"
4 #include "git2/transport.h"
5 #include "git2/sys/transport.h"
6 #include "futils.h"
7
8 static int custom_transport(
9 git_transport **out,
10 git_remote *owner,
11 void *payload)
12 {
13 *((int*)payload) = 1;
14
15 return git_transport_local(out, owner, payload);
16 }
17
18 static int custom_transport_remote_create(
19 git_remote **out,
20 git_repository *repo,
21 const char *name,
22 const char *url,
23 void *payload)
24 {
25 int error;
26
27 GIT_UNUSED(payload);
28
29 if ((error = git_remote_create(out, repo, name, url)) < 0)
30 return error;
31
32 return 0;
33 }
34
35 void test_clone_transport__custom_transport(void)
36 {
37 git_repository *repo;
38 git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
39 int custom_transport_used = 0;
40
41 clone_opts.remote_cb = custom_transport_remote_create;
42 clone_opts.fetch_opts.callbacks.transport = custom_transport;
43 clone_opts.fetch_opts.callbacks.payload = &custom_transport_used;
44
45 cl_git_pass(git_clone(&repo, cl_fixture("testrepo.git"), "./custom_transport.git", &clone_opts));
46 git_repository_free(repo);
47
48 cl_git_pass(git_futils_rmdir_r("./custom_transport.git", NULL, GIT_RMDIR_REMOVE_FILES));
49
50 cl_assert(custom_transport_used == 1);
51 }