mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-04 20:45:07 +00:00
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.
This commit is contained in:
parent
b7ae71ecf2
commit
5367ec4b84
@ -406,6 +406,17 @@ GIT_EXTERN(int) git_reference_rename(
|
|||||||
*/
|
*/
|
||||||
GIT_EXTERN(int) git_reference_delete(git_reference *ref);
|
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.
|
* Fill a list with all the references that can be found in a repository.
|
||||||
*
|
*
|
||||||
|
11
src/refs.c
11
src/refs.c
@ -127,6 +127,17 @@ int git_reference_delete(git_reference *ref)
|
|||||||
return git_refdb_delete(ref->db, ref->name, old_id, old_target);
|
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,
|
int git_reference_lookup(git_reference **ref_out,
|
||||||
git_repository *repo, const char *name)
|
git_repository *repo, const char *name)
|
||||||
{
|
{
|
||||||
|
@ -91,3 +91,17 @@ void test_refs_delete__packed_only(void)
|
|||||||
git_reference_free(ref);
|
git_reference_free(ref);
|
||||||
git_refdb_free(refdb);
|
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));
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user