reference_rename: fix flaw in force-renaming reference_rename didn't respect the force flag. Fixed. Reported-by: nulltoken <emeric.fermas@gmail.com> Signed-off-by: schu <schu-github@schulog.org>
diff --git a/src/refs.c b/src/refs.c
index 5e0fe09..843c69a 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -1309,8 +1309,12 @@ int git_reference_rename(git_reference *ref, const char *new_name, int force)
new_name = normalized;
error = git_reference_lookup(&new_ref, ref->owner, new_name);
- if (error == GIT_SUCCESS && !force)
- return git__throw(GIT_EEXISTS, "Failed to rename reference. Reference already exists");
+ if (error == GIT_SUCCESS) {
+ if (!force)
+ return git__throw(GIT_EEXISTS, "Failed to rename reference. Reference already exists");
+
+ error = git_reference_delete(new_ref);
+ }
if (error < GIT_SUCCESS && error != GIT_ENOTFOUND)
goto cleanup;