summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/git2/refs.h11
-rw-r--r--src/refs.c11
-rw-r--r--tests/refs/delete.c14
3 files changed, 36 insertions, 0 deletions
diff --git a/include/git2/refs.h b/include/git2/refs.h
index 0e5f779cf..970faf744 100644
--- a/include/git2/refs.h
+++ b/include/git2/refs.h
@@ -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
diff --git a/src/refs.c b/src/refs.c
index 90340d09c..bdf2da37e 100644
--- a/src/refs.c
+++ b/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);
}
+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)
{
diff --git a/tests/refs/delete.c b/tests/refs/delete.c
index 5e4afb138..9d1c3fd79 100644
--- a/tests/refs/delete.c
+++ b/tests/refs/delete.c
@@ -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));
+}