Merge pull request #2593 from libgit2/cmn/remote-delete-name remote: accept a repository and remote name for deletion
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
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 82733f6..b2c8731 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -40,6 +40,9 @@ v0.21 + 1
path of the programs to execute for receive-pack and upload-pack on
the server, git_transport_ssh_with_paths.
+* git_remote_delete() now accepts the repository and the remote's name
+ instead of a loaded remote.
+
* The git_clone_options struct no longer provides the ignore_cert_errors or
remote_name members for remote customization.
diff --git a/include/git2/remote.h b/include/git2/remote.h
index 422c93d..977e9b8 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -602,10 +602,11 @@ GIT_EXTERN(int) git_remote_is_valid_name(const char *remote_name);
* All remote-tracking branches and configuration settings
* for the remote will be removed.
*
-* @param remote A valid remote
+* @param repo the repository in which to act
+* @param name the name of the remove to delete
* @return 0 on success, or an error code.
*/
-GIT_EXTERN(int) git_remote_delete(git_remote *remote);
+GIT_EXTERN(int) git_remote_delete(git_repository *repo, const char *name);
/**
* Retrieve the name of the remote's default branch
diff --git a/src/remote.c b/src/remote.c
index 10b5624..8d928a5 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -2028,29 +2028,15 @@ static int remove_remote_tracking(git_repository *repo, const char *remote_name)
return error;
}
-int git_remote_delete(git_remote *remote)
+int git_remote_delete(git_repository *repo, const char *name)
{
int error;
- git_repository *repo;
-
- assert(remote);
- if (!remote->name) {
- giterr_set(GITERR_INVALID, "Can't delete an anonymous remote.");
- return -1;
- }
-
- repo = git_remote_owner(remote);
-
- if ((error = remove_branch_config_related_entries(repo,
- git_remote_name(remote))) < 0)
- return error;
-
- if ((error = remove_remote_tracking(repo, git_remote_name(remote))) < 0)
- return error;
+ assert(repo && name);
- if ((error = rename_remote_config_section(
- repo, git_remote_name(remote), NULL)) < 0)
+ if ((error = remove_branch_config_related_entries(repo, name)) < 0 ||
+ (error = remove_remote_tracking(repo, name)) < 0 ||
+ (error = rename_remote_config_section(repo, name, NULL)) < 0)
return error;
return 0;
diff --git a/tests/network/remote/delete.c b/tests/network/remote/delete.c
index 664f47a..f23a638 100644
--- a/tests/network/remote/delete.c
+++ b/tests/network/remote/delete.c
@@ -3,38 +3,23 @@
#include "repository.h"
-static git_remote *_remote;
static git_repository *_repo;
void test_network_remote_delete__initialize(void)
{
_repo = cl_git_sandbox_init("testrepo.git");
-
- cl_git_pass(git_remote_load(&_remote, _repo, "test"));
}
void test_network_remote_delete__cleanup(void)
{
- git_remote_free(_remote);
cl_git_sandbox_cleanup();
}
-void test_network_remote_delete__cannot_delete_an_anonymous_remote(void)
-{
- git_remote *remote;
-
- cl_git_pass(git_remote_create_anonymous(&remote, _repo, "git://github.com/libgit2/libgit2", NULL));
-
- cl_git_fail(git_remote_delete(remote));
-
- git_remote_free(remote);
-}
-
void test_network_remote_delete__remove_remote_tracking_branches(void)
{
git_reference *ref;
- cl_git_pass(git_remote_delete(_remote));
+ cl_git_pass(git_remote_delete(_repo, "test"));
cl_git_fail_with(GIT_ENOTFOUND, git_reference_lookup(&ref, _repo, "refs/remotes/test/master"));
}
@@ -42,7 +27,7 @@ void test_network_remote_delete__remove_remote_configuration_settings(void)
{
cl_assert(count_config_entries_match(_repo, "remote\\.test\\.+") > 0);
- cl_git_pass(git_remote_delete(_remote));
+ cl_git_pass(git_remote_delete(_repo, "test"));
cl_assert_equal_i(0, count_config_entries_match(_repo, "remote\\.test\\.+"));
}
@@ -52,7 +37,7 @@ void test_network_remote_delete__remove_branch_upstream_configuration_settings(v
assert_config_entry_existence(_repo, "branch.mergeless.remote", true);
assert_config_entry_existence(_repo, "branch.master.remote", true);
- cl_git_pass(git_remote_delete(_remote));
+ cl_git_pass(git_remote_delete(_repo, "test"));
assert_config_entry_existence(_repo, "branch.mergeless.remote", false);
assert_config_entry_existence(_repo, "branch.mergeless.merge", false);