In-memory remotes don't have names
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
diff --git a/include/git2/remote.h b/include/git2/remote.h
index aa3f93c..319976f 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -61,7 +61,6 @@ GIT_EXTERN(int) git_remote_create(
*
* @param out pointer to the new remote object
* @param repo the associated repository. May be NULL for a "dangling" remote.
- * @param name the optional remote's name. May be NULL.
* @param url the remote repository's URL
* @param fetch the fetch refspec to use for this remote. May be NULL for defaults.
* @return 0, GIT_EINVALIDSPEC or an error code
@@ -69,7 +68,6 @@ GIT_EXTERN(int) git_remote_create(
GIT_EXTERN(int) git_remote_create_inmemory(
git_remote **out,
git_repository *repo,
- const char *name,
const char *url,
const char *fetch);
diff --git a/src/remote.c b/src/remote.c
index f591af8..4d4614e 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -162,12 +162,12 @@ on_error:
return -1;
}
-int git_remote_create_inmemory(git_remote **out, git_repository *repo, const char *name, const char *url, const char *fetch)
+int git_remote_create_inmemory(git_remote **out, git_repository *repo, const char *url, const char *fetch)
{
int error;
git_remote *remote;
- if ((error = create_internal(&remote, repo, name, url, fetch)) < 0)
+ if ((error = create_internal(&remote, repo, NULL, url, fetch)) < 0)
return error;
remote->inmem = true;
@@ -1326,6 +1326,11 @@ int git_remote_rename(
assert(remote && new_name);
+ if (remote->inmem) {
+ giterr_set(GITERR_INVALID, "Can't rename an in-memory remote.");
+ return GIT_EINVALIDSPEC;
+ }
+
if ((error = ensure_remote_name_is_valid(new_name)) < 0)
return error;
diff --git a/tests-clar/network/remotelocal.c b/tests-clar/network/remotelocal.c
index 1839679..01492ac 100644
--- a/tests-clar/network/remotelocal.c
+++ b/tests-clar/network/remotelocal.c
@@ -50,7 +50,7 @@ static void connect_to_local_repository(const char *local_repository)
{
git_buf_sets(&file_path_buf, cl_git_path_url(local_repository));
- cl_git_pass(git_remote_create_inmemory(&remote, repo, NULL, git_buf_cstr(&file_path_buf), NULL));
+ cl_git_pass(git_remote_create_inmemory(&remote, repo, git_buf_cstr(&file_path_buf), NULL));
cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
}
diff --git a/tests-clar/network/remoterename.c b/tests-clar/network/remoterename.c
index e960cd7..90c464e 100644
--- a/tests-clar/network/remoterename.c
+++ b/tests-clar/network/remoterename.c
@@ -148,29 +148,6 @@ void test_network_remoterename__cannot_overwrite_an_existing_remote(void)
cl_assert_equal_i(GIT_EEXISTS, git_remote_rename(_remote, "test_with_pushurl", dont_call_me_cb, NULL));
}
-void test_network_remoterename__renaming_an_inmemory_nameless_remote_notifies_the_inability_to_update_the_fetch_refspec(void)
-{
- git_remote *remote;
-
- char *expected_refspecs[] = {
- "+refs/heads/*:refs/remotes/volatile/*",
- NULL
- };
-
- assert_config_entry_existence(_repo, "remote.volatile.url", false);
-
- cl_git_pass(git_remote_create_inmemory(
- &remote,
- _repo,
- NULL,
- "git://github.com/libgit2/volatile.git",
- "+refs/heads/*:refs/remotes/volatile/*"));
-
- cl_git_pass(git_remote_rename(remote, "durable", ensure_refspecs, &expected_refspecs));
-
- git_remote_free(remote);
-}
-
void test_network_remoterename__renaming_a_remote_moves_the_underlying_reference(void)
{
git_reference *underlying;
@@ -185,3 +162,13 @@ void test_network_remoterename__renaming_a_remote_moves_the_underlying_reference
cl_git_pass(git_reference_lookup(&underlying, _repo, "refs/remotes/just/renamed/master"));
git_reference_free(underlying);
}
+
+void test_network_remoterename__cannot_rename_an_inmemory_remote(void)
+{
+ git_remote *remote;
+
+ cl_git_pass(git_remote_create_inmemory(&remote, _repo, "file:///blah", NULL));
+ cl_git_fail(git_remote_rename(remote, "newname", NULL, NULL));
+
+ git_remote_free(remote);
+}
diff --git a/tests-clar/network/remotes.c b/tests-clar/network/remotes.c
index b776353..456fbc3 100644
--- a/tests-clar/network/remotes.c
+++ b/tests-clar/network/remotes.c
@@ -255,7 +255,7 @@ void test_network_remotes__cant_save_inmem_remote(void)
{
git_remote *remote;
- cl_git_pass(git_remote_create_inmemory(&remote, _repo, NULL, "git://github.com/libgit2/libgit2", NULL));
+ cl_git_pass(git_remote_create_inmemory(&remote, _repo, "git://github.com/libgit2/libgit2", NULL));
cl_git_fail(git_remote_save(remote));
git_remote_free(remote);
@@ -282,12 +282,12 @@ void test_network_remotes__cannot_initialize_a_remote_with_an_invalid_name(void)
cl_assert_equal_i(
GIT_EINVALIDSPEC,
- git_remote_create_inmemory(&remote, _repo, "Inv@{id", "git://github.com/libgit2/libgit2", NULL));
+ 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_inmemory(&remote, _repo, "", "git://github.com/libgit2/libgit2", NULL));
+ git_remote_create(&remote, _repo, "", "git://github.com/libgit2/libgit2"));
cl_assert_equal_p(remote, NULL);
}
@@ -331,7 +331,7 @@ void test_network_remotes__check_structure_version(void)
git_remote_free(_remote);
_remote = NULL;
- cl_git_pass(git_remote_create_inmemory(&_remote, _repo, NULL, "test-protocol://localhost", NULL));
+ cl_git_pass(git_remote_create_inmemory(&_remote, _repo, "test-protocol://localhost", NULL));
transport.version = 0;
cl_git_fail(git_remote_set_transport(_remote, &transport));