Commit a6ed1fcb by Edward Thomson

Merge pull request #2593 from libgit2/cmn/remote-delete-name

remote: accept a repository and remote name for deletion
parents bab92a8d 262eec23
......@@ -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.
......
......@@ -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
......
......@@ -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;
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment