diff options
author | Philip Kelley <phkelley@hotmail.com> | 2014-06-25 13:20:27 -0400 |
---|---|---|
committer | Philip Kelley <phkelley@hotmail.com> | 2014-06-26 22:34:37 -0400 |
commit | 1697cd6ff5d29c95106ff4b7bd56ebba5d51b8c1 (patch) | |
tree | 05e0f995c3782e0dd9b220b0fcc8ad09fc8dd96f /tests/clone | |
parent | 86cb34cb110c6a1ec6e1d1525418c70f2f617d6b (diff) | |
download | libgit2-1697cd6ff5d29c95106ff4b7bd56ebba5d51b8c1.tar.gz |
Improvements to git_transport extensibility
git_remote_set_transport now takes a transport factory rather than a transport
git_clone_options now allows the caller to specify a remote creation callback
Diffstat (limited to 'tests/clone')
-rw-r--r-- | tests/clone/nonetwork.c | 19 | ||||
-rw-r--r-- | tests/clone/transport.c | 50 |
2 files changed, 66 insertions, 3 deletions
diff --git a/tests/clone/nonetwork.c b/tests/clone/nonetwork.c index 4bdc6e13b..ab3e8f50d 100644 --- a/tests/clone/nonetwork.c +++ b/tests/clone/nonetwork.c @@ -110,12 +110,25 @@ void test_clone_nonetwork__fail_with_already_existing_but_non_empty_directory(vo cl_git_fail(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options)); } +int custom_origin_name_remote_create( + git_remote **out, + git_repository *repo, + const char *name, + const char *url, + void *payload) +{ + GIT_UNUSED(name); + GIT_UNUSED(payload); + + return git_remote_create(out, repo, "my_origin", url); +} + void test_clone_nonetwork__custom_origin_name(void) { - g_options.remote_name = "my_origin"; - cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options)); + g_options.remote_cb = custom_origin_name_remote_create; + cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options)); - cl_git_pass(git_remote_load(&g_remote, g_repo, "my_origin")); + cl_git_pass(git_remote_load(&g_remote, g_repo, "my_origin")); } void test_clone_nonetwork__defaults(void) diff --git a/tests/clone/transport.c b/tests/clone/transport.c new file mode 100644 index 000000000..27568f228 --- /dev/null +++ b/tests/clone/transport.c @@ -0,0 +1,50 @@ +#include "clar_libgit2.h" + +#include "git2/clone.h" +#include "git2/transport.h" +#include "fileops.h" + +static int custom_transport( + git_transport **out, + git_remote *owner, + void *payload) +{ + *((int*)payload) = 1; + + return git_transport_local(out, owner, payload); +} + +static int custom_transport_remote_create( + git_remote **out, + git_repository *repo, + const char *name, + const char *url, + void *payload) +{ + int error; + + if ((error = git_remote_create(out, repo, name, url)) < 0) + return error; + + if ((error = git_remote_set_transport(*out, custom_transport, payload)) < 0) + return error; + + return 0; +} + +void test_clone_transport__custom_transport(void) +{ + git_repository *repo; + git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; + int custom_transport_used = 0; + + clone_opts.remote_cb = custom_transport_remote_create; + clone_opts.remote_cb_payload = &custom_transport_used; + + cl_git_pass(git_clone(&repo, cl_fixture("testrepo.git"), "./custom_transport.git", &clone_opts)); + git_repository_free(repo); + + cl_git_pass(git_futils_rmdir_r("./custom_transport.git", NULL, GIT_RMDIR_REMOVE_FILES)); + + cl_assert(custom_transport_used == 1); +} |