Commit 5367ec4b by Carlos Martín Nieto

refs: add an unconditional delete

Add it under the git_reference_remove() name, letting the user pass the
repo and name, analogous to unconditional setting/creation.
parent b7ae71ec
......@@ -407,6 +407,17 @@ GIT_EXTERN(int) git_reference_rename(
GIT_EXTERN(int) git_reference_delete(git_reference *ref);
/**
* Delete an existing reference by name
*
* This method removes the named reference from the repository without
* looking at its old value.
*
* @param ref The reference to remove
* @return 0, GIT_EMODIFIED or an error code
*/
GIT_EXTERN(int) git_reference_remove(git_repository *repo, const char *name);
/**
* Fill a list with all the references that can be found in a repository.
*
* The string array will be filled with the names of all references; these
......
......@@ -127,6 +127,17 @@ int git_reference_delete(git_reference *ref)
return git_refdb_delete(ref->db, ref->name, old_id, old_target);
}
int git_reference_remove(git_repository *repo, const char *name)
{
git_refdb *db;
int error;
if ((error = git_repository_refdb__weakptr(&db, repo)) < 0)
return error;
return git_refdb_delete(db, name, NULL, NULL);
}
int git_reference_lookup(git_reference **ref_out,
git_repository *repo, const char *name)
{
......
......@@ -91,3 +91,17 @@ void test_refs_delete__packed_only(void)
git_reference_free(ref);
git_refdb_free(refdb);
}
void test_refs_delete__remove(void)
{
git_reference *ref;
/* Check that passing no old values lets us delete */
cl_git_pass(git_reference_lookup(&ref, g_repo, packed_test_head_name));
git_reference_free(ref);
cl_git_pass(git_reference_remove(g_repo, packed_test_head_name));
cl_git_fail(git_reference_lookup(&ref, g_repo, packed_test_head_name));
}
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