]> git.proxmox.com Git - libgit2.git/blobdiff - tests/network/remote/remotes.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / network / remote / remotes.c
index df424e961811b51a8a47b3be65d1c123ad29da37..79c4f39fa21c9d15538a480f7bd3c3d433b09094 100644 (file)
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "buffer.h"
+#include "config/config_helpers.h"
 #include "refspec.h"
 #include "remote.h"
 
@@ -11,7 +11,7 @@ void test_network_remote_remotes__initialize(void)
 {
        _repo = cl_git_sandbox_init("testrepo.git");
 
-       cl_git_pass(git_remote_load(&_remote, _repo, "test"));
+       cl_git_pass(git_remote_lookup(&_remote, _repo, "test"));
 
        _refspec = git_remote_get_refspec(_remote, 0);
        cl_assert(_refspec != NULL);
@@ -27,88 +27,245 @@ void test_network_remote_remotes__cleanup(void)
 
 void test_network_remote_remotes__parsing(void)
 {
+       git_str url = GIT_STR_INIT;
        git_remote *_remote2 = NULL;
 
        cl_assert_equal_s(git_remote_name(_remote), "test");
        cl_assert_equal_s(git_remote_url(_remote), "git://github.com/libgit2/libgit2");
        cl_assert(git_remote_pushurl(_remote) == NULL);
 
-       cl_assert_equal_s(git_remote__urlfordirection(_remote, GIT_DIRECTION_FETCH),
-                                         "git://github.com/libgit2/libgit2");
-       cl_assert_equal_s(git_remote__urlfordirection(_remote, GIT_DIRECTION_PUSH),
-                                         "git://github.com/libgit2/libgit2");
+       cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, NULL));
+       cl_assert_equal_s(url.ptr, "git://github.com/libgit2/libgit2");
 
-       cl_git_pass(git_remote_load(&_remote2, _repo, "test_with_pushurl"));
+       cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, NULL));
+       cl_assert_equal_s(url.ptr, "git://github.com/libgit2/libgit2");
+
+       cl_git_pass(git_remote_lookup(&_remote2, _repo, "test_with_pushurl"));
        cl_assert_equal_s(git_remote_name(_remote2), "test_with_pushurl");
        cl_assert_equal_s(git_remote_url(_remote2), "git://github.com/libgit2/fetchlibgit2");
        cl_assert_equal_s(git_remote_pushurl(_remote2), "git://github.com/libgit2/pushlibgit2");
 
-       cl_assert_equal_s(git_remote__urlfordirection(_remote2, GIT_DIRECTION_FETCH),
-                                         "git://github.com/libgit2/fetchlibgit2");
-       cl_assert_equal_s(git_remote__urlfordirection(_remote2, GIT_DIRECTION_PUSH),
-                                         "git://github.com/libgit2/pushlibgit2");
+       cl_git_pass(git_remote__urlfordirection(&url, _remote2, GIT_DIRECTION_FETCH, NULL));
+       cl_assert_equal_s(url.ptr, "git://github.com/libgit2/fetchlibgit2");
+
+       cl_git_pass(git_remote__urlfordirection(&url, _remote2, GIT_DIRECTION_PUSH, NULL));
+       cl_assert_equal_s(url.ptr, "git://github.com/libgit2/pushlibgit2");
 
        git_remote_free(_remote2);
+       git_str_dispose(&url);
 }
 
-void test_network_remote_remotes__pushurl(void)
+static int remote_ready_callback(git_remote *remote, int direction, void *payload)
 {
-       cl_git_pass(git_remote_set_pushurl(_remote, "git://github.com/libgit2/notlibgit2"));
-       cl_assert_equal_s(git_remote_pushurl(_remote), "git://github.com/libgit2/notlibgit2");
+       if (direction == GIT_DIRECTION_PUSH) {
+               const char *url = git_remote_pushurl(remote);
+
+               cl_assert_equal_p(url, NULL);;
+               cl_assert_equal_s(payload, "payload");
+               return git_remote_set_instance_pushurl(remote, "push_url");
+       }
+
+       if (direction == GIT_DIRECTION_FETCH) {
+               const char *url = git_remote_url(remote);
+
+               cl_assert_equal_s(url, "git://github.com/libgit2/libgit2");
+               cl_assert_equal_s(payload, "payload");
+               return git_remote_set_instance_url(remote, "fetch_url");
+       }
+
+       return -1;
+}
+
+void test_network_remote_remotes__remote_ready(void)
+{
+       git_str url = GIT_STR_INIT;
+
+       git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+       callbacks.remote_ready = remote_ready_callback;
+       callbacks.payload = "payload";
 
-       cl_git_pass(git_remote_set_pushurl(_remote, NULL));
+       cl_assert_equal_s(git_remote_name(_remote), "test");
+       cl_assert_equal_s(git_remote_url(_remote), "git://github.com/libgit2/libgit2");
        cl_assert(git_remote_pushurl(_remote) == NULL);
+
+       cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, &callbacks));
+       cl_assert_equal_s(url.ptr, "fetch_url");
+
+       cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, &callbacks));
+       cl_assert_equal_s(url.ptr, "push_url");
+
+       git_str_dispose(&url);
 }
 
-void test_network_remote_remotes__error_when_not_found(void)
+#ifndef GIT_DEPRECATE_HARD
+static int urlresolve_callback(git_buf *url_resolved, const char *url, int direction, void *payload)
 {
-       git_remote *r;
-       cl_git_fail_with(git_remote_load(&r, _repo, "does-not-exist"), GIT_ENOTFOUND);
+       int error = -1;
+
+       cl_assert(strcmp(url, "git://github.com/libgit2/libgit2") == 0);
+       cl_assert(strcmp(payload, "payload") == 0);
+       cl_assert(url_resolved->size == 0);
+
+       if (direction == GIT_DIRECTION_PUSH)
+               error = git_buf_set(url_resolved, "pushresolve", strlen("pushresolve") + 1);
+       if (direction == GIT_DIRECTION_FETCH)
+               error = git_buf_set(url_resolved, "fetchresolve", strlen("fetchresolve") + 1);
 
-       cl_assert(giterr_last() != NULL);
-       cl_assert(giterr_last()->klass == GITERR_CONFIG);
+       return error;
 }
+#endif
 
-void test_network_remote_remotes__error_when_no_push_available(void)
+void test_network_remote_remotes__urlresolve(void)
 {
-       git_remote *r;
-       git_push *p;
+#ifndef GIT_DEPRECATE_HARD
+       git_str url = GIT_STR_INIT;
 
-       cl_git_pass(git_remote_create_anonymous(&r, _repo, cl_fixture("testrepo.git"), NULL));
+       git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+       callbacks.resolve_url = urlresolve_callback;
+       callbacks.payload = "payload";
 
-       cl_git_pass(git_remote_set_transport(r, git_transport_local, NULL));
+       cl_assert_equal_s(git_remote_name(_remote), "test");
+       cl_assert_equal_s(git_remote_url(_remote), "git://github.com/libgit2/libgit2");
+       cl_assert(git_remote_pushurl(_remote) == NULL);
 
-       cl_git_pass(git_remote_connect(r, GIT_DIRECTION_PUSH));
+       cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, &callbacks));
+       cl_assert_equal_s(url.ptr, "fetchresolve");
 
-       /* Make sure that push is really not available */
-       r->transport->push = NULL;
+       cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, &callbacks));
+       cl_assert_equal_s(url.ptr, "pushresolve");
 
-       cl_git_pass(git_push_new(&p, r));
-       cl_git_pass(git_push_add_refspec(p, "refs/heads/master"));
-       cl_git_fail_with(git_push_finish(p), GIT_ERROR);
+       git_str_dispose(&url);
+#endif
+}
 
-       git_push_free(p);
-       git_remote_free(r);
+#ifndef GIT_DEPRECATE_HARD
+static int urlresolve_passthrough_callback(git_buf *url_resolved, const char *url, int direction, void *payload)
+{
+       GIT_UNUSED(url_resolved);
+       GIT_UNUSED(url);
+       GIT_UNUSED(direction);
+       GIT_UNUSED(payload);
+       return GIT_PASSTHROUGH;
 }
+#endif
 
-void test_network_remote_remotes__supported_urls(void)
+void test_network_remote_remotes__urlresolve_passthrough(void)
 {
-       int ssh_supported = 0, https_supported = 0;
+#ifndef GIT_DEPRECATE_HARD
+       git_str url = GIT_STR_INIT;
+       const char *orig_url = "git://github.com/libgit2/libgit2";
 
-#ifdef GIT_SSH
-       ssh_supported = 1;
-#endif
+       git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+       callbacks.resolve_url = urlresolve_passthrough_callback;
 
-#if defined(GIT_SSL) || defined(GIT_WINHTTP)
-       https_supported = 1;
+       cl_assert_equal_s(git_remote_name(_remote), "test");
+       cl_assert_equal_s(git_remote_url(_remote), orig_url);
+       cl_assert(git_remote_pushurl(_remote) == NULL);
+
+       cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, &callbacks));
+       cl_assert_equal_s(url.ptr, orig_url);
+
+       cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, &callbacks));
+       cl_assert_equal_s(url.ptr, orig_url);
+
+       git_str_dispose(&url);
 #endif
+}
+
+void test_network_remote_remotes__instance_url(void)
+{
+       git_str url = GIT_STR_INIT;
+       const char *orig_url = "git://github.com/libgit2/libgit2";
+
+       cl_assert_equal_s(git_remote_name(_remote), "test");
+       cl_assert_equal_s(git_remote_url(_remote), orig_url);
+
+       cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, NULL));
+       cl_assert_equal_s(url.ptr, orig_url);
+       git_str_clear(&url);
+
+       cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, NULL));
+       cl_assert_equal_s(url.ptr, orig_url);
+       git_str_clear(&url);
 
-       cl_assert(git_remote_supported_url("git://github.com/libgit2/libgit2"));
-       cl_assert(git_remote_supported_url("http://github.com/libgit2/libgit2"));
+       /* Setting the instance url updates the fetch and push URLs */
+       git_remote_set_instance_url(_remote, "https://github.com/new/remote/url");
+       cl_assert_equal_s(git_remote_url(_remote), "https://github.com/new/remote/url");
+       cl_assert_equal_p(git_remote_pushurl(_remote), NULL);
 
-       cl_assert_equal_i(ssh_supported, git_remote_supported_url("git@github.com:libgit2/libgit2.git"));
-       cl_assert_equal_i(ssh_supported, git_remote_supported_url("ssh://git@github.com/libgit2/libgit2.git"));
-       cl_assert_equal_i(https_supported, git_remote_supported_url("https://github.com/libgit2/libgit2.git"));
+       cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, NULL));
+       cl_assert_equal_s(url.ptr, "https://github.com/new/remote/url");
+       git_str_clear(&url);
+
+       cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, NULL));
+       cl_assert_equal_s(url.ptr, "https://github.com/new/remote/url");
+       git_str_clear(&url);
+
+       /* Setting the instance push url updates only the push URL */
+       git_remote_set_instance_pushurl(_remote, "https://github.com/new/push/url");
+       cl_assert_equal_s(git_remote_url(_remote), "https://github.com/new/remote/url");
+       cl_assert_equal_s(git_remote_pushurl(_remote), "https://github.com/new/push/url");
+
+       cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, NULL));
+       cl_assert_equal_s(url.ptr, "https://github.com/new/remote/url");
+       git_str_clear(&url);
+
+       cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, NULL));
+       cl_assert_equal_s(url.ptr, "https://github.com/new/push/url");
+       git_str_clear(&url);
+
+       git_str_dispose(&url);
+}
+
+void test_network_remote_remotes__pushurl(void)
+{
+       const char *name = git_remote_name(_remote);
+       git_remote *mod;
+
+       cl_git_pass(git_remote_set_pushurl(_repo, name, "git://github.com/libgit2/notlibgit2"));
+       cl_git_pass(git_remote_lookup(&mod, _repo, name));
+       cl_assert_equal_s(git_remote_pushurl(mod), "git://github.com/libgit2/notlibgit2");
+       git_remote_free(mod);
+
+       cl_git_pass(git_remote_set_pushurl(_repo, name, NULL));
+       cl_git_pass(git_remote_lookup(&mod, _repo, name));
+       cl_assert(git_remote_pushurl(mod) == NULL);
+       git_remote_free(mod);
+}
+
+void test_network_remote_remotes__error_when_not_found(void)
+{
+       git_remote *r;
+       cl_git_fail_with(git_remote_lookup(&r, _repo, "does-not-exist"), GIT_ENOTFOUND);
+
+       cl_assert(git_error_last() != NULL);
+       cl_assert(git_error_last()->klass == GIT_ERROR_CONFIG);
+}
+
+void test_network_remote_remotes__error_when_no_push_available(void)
+{
+       git_remote *r;
+       git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+       char *specs = {
+               "refs/heads/master",
+       };
+       git_strarray arr = {
+               &specs,
+               1,
+       };
+
+
+       cl_git_pass(git_remote_create_anonymous(&r, _repo, cl_fixture("testrepo.git")));
+
+       callbacks.transport = git_transport_local;
+       cl_git_pass(git_remote_connect(r, GIT_DIRECTION_PUSH, &callbacks, NULL, NULL));
+
+       /* Make sure that push is really not available */
+       r->transport->push = NULL;
+
+       cl_git_fail_with(-1, git_remote_upload(r, &arr, NULL));
+
+       git_remote_free(r);
 }
 
 void test_network_remote_remotes__refspec_parsing(void)
@@ -123,9 +280,12 @@ void test_network_remote_remotes__add_fetchspec(void)
 
        size = git_remote_refspec_count(_remote);
 
-       cl_git_pass(git_remote_add_fetch(_remote, "refs/*:refs/*"));
-
+       cl_git_pass(git_remote_add_fetch(_repo, "test", "refs/*:refs/*"));
        size++;
+
+       git_remote_free(_remote);
+       cl_git_pass(git_remote_lookup(&_remote, _repo, "test"));
+
        cl_assert_equal_i((int)size, (int)git_remote_refspec_count(_remote));
 
        _refspec = git_remote_get_refspec(_remote, size - 1);
@@ -133,6 +293,8 @@ void test_network_remote_remotes__add_fetchspec(void)
        cl_assert_equal_s(git_refspec_dst(_refspec), "refs/*");
        cl_assert_equal_s(git_refspec_string(_refspec), "refs/*:refs/*");
        cl_assert_equal_b(_refspec->push, false);
+
+       cl_git_fail_with(GIT_EINVALIDSPEC, git_remote_add_fetch(_repo, "test", "refs/*/foo/*:refs/*"));
 }
 
 void test_network_remote_remotes__dup(void)
@@ -149,11 +311,11 @@ void test_network_remote_remotes__dup(void)
        cl_git_pass(git_remote_get_fetch_refspecs(&array, _remote));
        cl_assert_equal_i(1, (int)array.count);
        cl_assert_equal_s("+refs/heads/*:refs/remotes/test/*", array.strings[0]);
-       git_strarray_free(&array);
+       git_strarray_dispose(&array);
 
        cl_git_pass(git_remote_get_push_refspecs(&array, _remote));
        cl_assert_equal_i(0, (int)array.count);
-       git_strarray_free(&array);
+       git_strarray_dispose(&array);
 
        git_remote_free(dup);
 }
@@ -164,8 +326,12 @@ void test_network_remote_remotes__add_pushspec(void)
 
        size = git_remote_refspec_count(_remote);
 
-       cl_git_pass(git_remote_add_push(_remote, "refs/*:refs/*"));
+       cl_git_pass(git_remote_add_push(_repo, "test", "refs/*:refs/*"));
        size++;
+
+       git_remote_free(_remote);
+       cl_git_pass(git_remote_lookup(&_remote, _repo, "test"));
+
        cl_assert_equal_i((int)size, (int)git_remote_refspec_count(_remote));
 
        _refspec = git_remote_get_refspec(_remote, size - 1);
@@ -176,58 +342,6 @@ void test_network_remote_remotes__add_pushspec(void)
        cl_assert_equal_b(_refspec->push, true);
 }
 
-void test_network_remote_remotes__save(void)
-{
-       git_strarray array;
-       const char *fetch_refspec1 = "refs/heads/ns1/*:refs/remotes/upstream/ns1/*";
-       const char *fetch_refspec2 = "refs/heads/ns2/*:refs/remotes/upstream/ns2/*";
-       const char *push_refspec1 = "refs/heads/ns1/*:refs/heads/ns1/*";
-       const char *push_refspec2 = "refs/heads/ns2/*:refs/heads/ns2/*";
-
-       git_remote_free(_remote);
-       _remote = NULL;
-
-       /* Set up the remote and save it to config */
-       cl_git_pass(git_remote_create(&_remote, _repo, "upstream", "git://github.com/libgit2/libgit2"));
-       git_remote_clear_refspecs(_remote);
-
-       cl_git_pass(git_remote_add_fetch(_remote, fetch_refspec1));
-       cl_git_pass(git_remote_add_fetch(_remote, fetch_refspec2));
-       cl_git_pass(git_remote_add_push(_remote, push_refspec1));
-       cl_git_pass(git_remote_add_push(_remote, push_refspec2));
-       cl_git_pass(git_remote_set_pushurl(_remote, "git://github.com/libgit2/libgit2_push"));
-       cl_git_pass(git_remote_save(_remote));
-       git_remote_free(_remote);
-       _remote = NULL;
-
-       /* Load it from config and make sure everything matches */
-       cl_git_pass(git_remote_load(&_remote, _repo, "upstream"));
-
-       cl_git_pass(git_remote_get_fetch_refspecs(&array, _remote));
-       cl_assert_equal_i(2, (int)array.count);
-       cl_assert_equal_s(fetch_refspec1, array.strings[0]);
-       cl_assert_equal_s(fetch_refspec2, array.strings[1]);
-       git_strarray_free(&array);
-
-       cl_git_pass(git_remote_get_push_refspecs(&array, _remote));
-       cl_assert_equal_i(2, (int)array.count);
-       cl_assert_equal_s(push_refspec1, array.strings[0]);
-       cl_assert_equal_s(push_refspec2, array.strings[1]);
-       git_strarray_free(&array);
-
-       cl_assert_equal_s(git_remote_url(_remote), "git://github.com/libgit2/libgit2");
-       cl_assert_equal_s(git_remote_pushurl(_remote), "git://github.com/libgit2/libgit2_push");
-
-       /* remove the pushurl again and see if we can save that too */
-       cl_git_pass(git_remote_set_pushurl(_remote, NULL));
-       cl_git_pass(git_remote_save(_remote));
-       git_remote_free(_remote);
-       _remote = NULL;
-
-       cl_git_pass(git_remote_load(&_remote, _repo, "upstream"));
-       cl_assert(git_remote_pushurl(_remote) == NULL);
-}
-
 void test_network_remote_remotes__fnmatch(void)
 {
        cl_assert(git_refspec_src_matches(_refspec, "refs/heads/master"));
@@ -240,7 +354,7 @@ void test_network_remote_remotes__transform(void)
 
        cl_git_pass(git_refspec_transform(&ref, _refspec, "refs/heads/master"));
        cl_assert_equal_s(ref.ptr, "refs/remotes/test/master");
-       git_buf_free(&ref);
+       git_buf_dispose(&ref);
 }
 
 void test_network_remote_remotes__transform_destination_to_source(void)
@@ -249,7 +363,7 @@ void test_network_remote_remotes__transform_destination_to_source(void)
 
        cl_git_pass(git_refspec_rtransform(&ref, _refspec, "refs/remotes/test/master"));
        cl_assert_equal_s(ref.ptr, "refs/heads/master");
-       git_buf_free(&ref);
+       git_buf_dispose(&ref);
 }
 
 void test_network_remote_remotes__missing_refspecs(void)
@@ -261,11 +375,38 @@ void test_network_remote_remotes__missing_refspecs(void)
 
        cl_git_pass(git_repository_config(&cfg, _repo));
        cl_git_pass(git_config_set_string(cfg, "remote.specless.url", "http://example.com"));
-       cl_git_pass(git_remote_load(&_remote, _repo, "specless"));
+       cl_git_pass(git_remote_lookup(&_remote, _repo, "specless"));
 
        git_config_free(cfg);
 }
 
+void test_network_remote_remotes__nonmatch_upstream_refspec(void)
+{
+       git_config *config;
+       git_remote *remote;
+       char *specstr[] = {
+               "refs/tags/*:refs/tags/*",
+       };
+       git_strarray specs = {
+               specstr,
+               1,
+       };
+
+       cl_git_pass(git_remote_create(&remote, _repo, "taggy", git_repository_path(_repo)));
+
+       /*
+        * Set the current branch's upstream remote to a dummy ref so we call into the code
+        * which tries to check for the current branch's upstream in the refspecs
+        */
+       cl_git_pass(git_repository_config(&config, _repo));
+       cl_git_pass(git_config_set_string(config, "branch.master.remote", "taggy"));
+       cl_git_pass(git_config_set_string(config, "branch.master.merge", "refs/heads/foo"));
+
+       cl_git_pass(git_remote_fetch(remote, &specs, NULL, NULL));
+
+       git_remote_free(remote);
+}
+
 void test_network_remote_remotes__list(void)
 {
        git_strarray list;
@@ -273,7 +414,7 @@ void test_network_remote_remotes__list(void)
 
        cl_git_pass(git_remote_list(&list, _repo));
        cl_assert(list.count == 5);
-       git_strarray_free(&list);
+       git_strarray_dispose(&list);
 
        cl_git_pass(git_repository_config(&cfg, _repo));
 
@@ -285,7 +426,7 @@ void test_network_remote_remotes__list(void)
 
        cl_git_pass(git_remote_list(&list, _repo));
        cl_assert(list.count == 7);
-       git_strarray_free(&list);
+       git_strarray_dispose(&list);
 
        git_config_free(cfg);
 }
@@ -295,7 +436,7 @@ void test_network_remote_remotes__loading_a_missing_remote_returns_ENOTFOUND(voi
        git_remote_free(_remote);
        _remote = NULL;
 
-       cl_assert_equal_i(GIT_ENOTFOUND, git_remote_load(&_remote, _repo, "just-left-few-minutes-ago"));
+       cl_assert_equal_i(GIT_ENOTFOUND, git_remote_lookup(&_remote, _repo, "just-left-few-minutes-ago"));
 }
 
 void test_network_remote_remotes__loading_with_an_invalid_name_returns_EINVALIDSPEC(void)
@@ -303,7 +444,7 @@ void test_network_remote_remotes__loading_with_an_invalid_name_returns_EINVALIDS
        git_remote_free(_remote);
        _remote = NULL;
 
-       cl_assert_equal_i(GIT_EINVALIDSPEC, git_remote_load(&_remote, _repo, "Inv@{id"));
+       cl_assert_equal_i(GIT_EINVALIDSPEC, git_remote_lookup(&_remote, _repo, "Inv@{id"));
 }
 
 /*
@@ -326,7 +467,7 @@ void test_network_remote_remotes__add(void)
        git_remote_free(_remote);
        _remote = NULL;
 
-       cl_git_pass(git_remote_load(&_remote, _repo, "addtest"));
+       cl_git_pass(git_remote_lookup(&_remote, _repo, "addtest"));
        cl_assert_equal_i(GIT_REMOTE_DOWNLOAD_TAGS_AUTO, git_remote_autotag(_remote));
 
        _refspec = git_vector_get(&_remote->refspecs, 0);
@@ -336,79 +477,33 @@ void test_network_remote_remotes__add(void)
        cl_assert_equal_s(git_remote_url(_remote), "http://github.com/libgit2/libgit2");
 }
 
-void test_network_remote_remotes__cannot_add_a_nameless_remote(void)
-{
-       git_remote *remote;
-
-       cl_assert_equal_i(
-               GIT_EINVALIDSPEC,
-               git_remote_create(&remote, _repo, NULL, "git://github.com/libgit2/libgit2"));
-}
-
-void test_network_remote_remotes__cannot_save_an_inmemory_remote(void)
-{
-       git_remote *remote;
-
-       cl_git_pass(git_remote_create_anonymous(&remote, _repo, "git://github.com/libgit2/libgit2", NULL));
-
-       cl_assert_equal_p(NULL, git_remote_name(remote));
-
-       cl_git_fail(git_remote_save(remote));
-       git_remote_free(remote);
-}
-
-void test_network_remote_remotes__cannot_add_a_remote_with_an_invalid_name(void)
-{
-       git_remote *remote = NULL;
-
-       cl_assert_equal_i(
-               GIT_EINVALIDSPEC,
-               git_remote_create(&remote, _repo, "Inv@{id", "git://github.com/libgit2/libgit2"));
-       cl_assert_equal_p(remote, NULL);
-
-       cl_assert_equal_i(
-               GIT_EINVALIDSPEC,
-               git_remote_create(&remote, _repo, "", "git://github.com/libgit2/libgit2"));
-       cl_assert_equal_p(remote, NULL);
-}
-
 void test_network_remote_remotes__tagopt(void)
 {
-       const char *opt;
-       git_config *cfg;
+       const char *name = git_remote_name(_remote);
 
-       cl_git_pass(git_repository_config(&cfg, _repo));
+       git_remote_set_autotag(_repo, name, GIT_REMOTE_DOWNLOAD_TAGS_ALL);
+       assert_config_entry_value(_repo, "remote.test.tagopt", "--tags");
 
-       git_remote_set_autotag(_remote, GIT_REMOTE_DOWNLOAD_TAGS_ALL);
-       cl_git_pass(git_remote_save(_remote));
-       cl_git_pass(git_config_get_string(&opt, cfg, "remote.test.tagopt"));
-       cl_assert_equal_s("--tags", opt);
+       git_remote_set_autotag(_repo, name, GIT_REMOTE_DOWNLOAD_TAGS_NONE);
+       assert_config_entry_value(_repo, "remote.test.tagopt", "--no-tags");
 
-       git_remote_set_autotag(_remote, GIT_REMOTE_DOWNLOAD_TAGS_NONE);
-       cl_git_pass(git_remote_save(_remote));
-       cl_git_pass(git_config_get_string(&opt, cfg, "remote.test.tagopt"));
-       cl_assert_equal_s("--no-tags", opt);
-
-       git_remote_set_autotag(_remote, GIT_REMOTE_DOWNLOAD_TAGS_AUTO);
-       cl_git_pass(git_remote_save(_remote));
-       cl_assert(git_config_get_string(&opt, cfg, "remote.test.tagopt") == GIT_ENOTFOUND);
-
-       git_config_free(cfg);
+       git_remote_set_autotag(_repo, name, GIT_REMOTE_DOWNLOAD_TAGS_AUTO);
+       assert_config_entry_existence(_repo, "remote.test.tagopt", false);
 }
 
 void test_network_remote_remotes__can_load_with_an_empty_url(void)
 {
        git_remote *remote = NULL;
 
-       cl_git_pass(git_remote_load(&remote, _repo, "empty-remote-url"));
+       cl_git_pass(git_remote_lookup(&remote, _repo, "empty-remote-url"));
 
        cl_assert(remote->url == NULL);
        cl_assert(remote->pushurl == NULL);
 
-       cl_git_fail(git_remote_connect(remote, GIT_DIRECTION_FETCH));
+       cl_git_fail(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL, NULL));
 
-       cl_assert(giterr_last() != NULL);
-       cl_assert(giterr_last()->klass == GITERR_INVALID);
+       cl_assert(git_error_last() != NULL);
+       cl_assert(git_error_last()->klass == GIT_ERROR_INVALID);
 
        git_remote_free(remote);
 }
@@ -417,12 +512,12 @@ void test_network_remote_remotes__can_load_with_only_an_empty_pushurl(void)
 {
        git_remote *remote = NULL;
 
-       cl_git_pass(git_remote_load(&remote, _repo, "empty-remote-pushurl"));
+       cl_git_pass(git_remote_lookup(&remote, _repo, "empty-remote-pushurl"));
 
        cl_assert(remote->url == NULL);
        cl_assert(remote->pushurl == NULL);
 
-       cl_git_fail(git_remote_connect(remote, GIT_DIRECTION_FETCH));
+       cl_git_fail(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL, NULL));
 
        git_remote_free(remote);
 }
@@ -432,42 +527,7 @@ void test_network_remote_remotes__returns_ENOTFOUND_when_neither_url_nor_pushurl
        git_remote *remote = NULL;
 
        cl_git_fail_with(
-               git_remote_load(&remote, _repo, "no-remote-url"), GIT_ENOTFOUND);
-}
-
-void assert_cannot_create_remote(const char *name, int expected_error)
-{
-       git_remote *remote = NULL;
-
-       cl_git_fail_with(
-               git_remote_create(&remote, _repo, name, "git://github.com/libgit2/libgit2"),
-               expected_error);
-
-       cl_assert_equal_p(remote, NULL);
-}
-
-void test_network_remote_remotes__cannot_create_a_remote_which_name_conflicts_with_an_existing_remote(void)
-{
-       assert_cannot_create_remote("test", GIT_EEXISTS);
-}
-
-void test_network_remote_remotes__cannot_create_a_remote_which_name_is_invalid(void)
-{
-       assert_cannot_create_remote("/", GIT_EINVALIDSPEC);
-       assert_cannot_create_remote("//", GIT_EINVALIDSPEC);
-       assert_cannot_create_remote(".lock", GIT_EINVALIDSPEC);
-       assert_cannot_create_remote("a.lock", GIT_EINVALIDSPEC);
-}
-
-void test_network_remote_remote__git_remote_create_with_fetchspec(void)
-{
-       git_remote *remote;
-       git_strarray array;
-
-       cl_git_pass(git_remote_create_with_fetchspec(&remote, _repo, "test-new", "git://github.com/libgit2/libgit2", "+refs/*:refs/*"));
-       git_remote_get_fetch_refspecs(&array, remote);
-       cl_assert_equal_s("+refs/*:refs/*", array.strings[0]);
-       git_remote_free(remote);
+               git_remote_lookup(&remote, _repo, "no-remote-url"), GIT_ENOTFOUND);
 }
 
 static const char *fetch_refspecs[] = {
@@ -488,75 +548,28 @@ void test_network_remote_remotes__query_refspecs(void)
        git_strarray array;
        int i;
 
-       cl_git_pass(git_remote_create_anonymous(&remote, _repo, "git://github.com/libgit2/libgit2", NULL));
+       cl_git_pass(git_remote_create_with_fetchspec(&remote, _repo, "query", "git://github.com/libgit2/libgit2", NULL));
+       git_remote_free(remote);
 
        for (i = 0; i < 3; i++) {
-               cl_git_pass(git_remote_add_fetch(remote, fetch_refspecs[i]));
-               cl_git_pass(git_remote_add_push(remote, push_refspecs[i]));
+               cl_git_pass(git_remote_add_fetch(_repo, "query", fetch_refspecs[i]));
+               cl_git_pass(git_remote_add_push(_repo, "query", push_refspecs[i]));
        }
 
+       cl_git_pass(git_remote_lookup(&remote, _repo, "query"));
+
        cl_git_pass(git_remote_get_fetch_refspecs(&array, remote));
        for (i = 0; i < 3; i++) {
                cl_assert_equal_s(fetch_refspecs[i], array.strings[i]);
        }
-       git_strarray_free(&array);
+       git_strarray_dispose(&array);
 
        cl_git_pass(git_remote_get_push_refspecs(&array, remote));
        for (i = 0; i < 3; i++) {
                cl_assert_equal_s(push_refspecs[i], array.strings[i]);
        }
-       git_strarray_free(&array);
+       git_strarray_dispose(&array);
 
        git_remote_free(remote);
-}
-
-static int remote_single_branch(git_remote **out, git_repository *repo, const char *name, const char *url, void *payload)
-{
-       char *fetch_refspecs[] = {
-               "refs/heads/first-merge:refs/remotes/origin/first-merge",
-       };
-       git_strarray fetch_refspecs_strarray = {
-               fetch_refspecs,
-               1,
-       };
-
-       GIT_UNUSED(payload);
-
-       cl_git_pass(git_remote_create(out, repo, name, url));
-       cl_git_pass(git_remote_set_fetch_refspecs(*out, &fetch_refspecs_strarray));
-
-       return 0;
-}
-
-void test_network_remote_remotes__single_branch(void)
-{
-       git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
-       git_repository *repo;
-       git_strarray refs;
-       size_t i, count = 0;
-
-       opts.remote_cb = remote_single_branch;
-       opts.checkout_branch = "first-merge";
-
-       cl_git_pass(git_clone(&repo, "git://github.com/libgit2/TestGitRepository", "./single-branch", &opts));
-       cl_git_pass(git_reference_list(&refs, repo));
-
-       for (i = 0; i < refs.count; i++) {
-               if (!git__prefixcmp(refs.strings[i], "refs/heads/"))
-                       count++;
-       }
-       cl_assert_equal_i(1, count);
-
-       git_strarray_free(&refs);
-       git_repository_free(repo);
-}
-
-void test_network_remote_remotes__restricted_refspecs(void)
-{
-       git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
-       git_repository *repo;
-
-       opts.remote_cb = remote_single_branch;
-
-       cl_git_fail_with(GIT_EINVALIDSPEC, git_clone(&repo, "git://github.com/libgit2/TestGitRepository", "./restrict-refspec", &opts));
+       git_remote_delete(_repo, "test");
 }