Commit 73294339443011dce770c0d35a72b71113f0830b

schu 2011-07-07T21:24:12

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>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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;