summaryrefslogtreecommitdiff
path: root/src/refs.c
diff options
context:
space:
mode:
authorschu <schu-github@schulog.org>2011-09-20 11:11:59 +0200
committerschu <schu-github@schulog.org>2011-09-20 11:56:21 +0200
commit93fdbe000c18c94f4f21b7a6613c80bd1dc29e21 (patch)
tree693019a7ff6d34d6bc844847f464e07cb8a7fdbe /src/refs.c
parentb4ec3c648f6bb0a0af0b70b2443643fa2ea1c360 (diff)
downloadlibgit2-93fdbe000c18c94f4f21b7a6613c80bd1dc29e21.tar.gz
refs: fix git_reference_rename()
reference_rename() recently failed when renaming an existing reference refs/heads/foo/bar -> refs/heads/foo because of a change in the underlying functions / error codes. Fixes #412. Signed-off-by: schu <schu-github@schulog.org>
Diffstat (limited to 'src/refs.c')
-rw-r--r--src/refs.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/refs.c b/src/refs.c
index bc8827b46..3711759ae 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -1287,8 +1287,13 @@ int git_reference_rename(git_reference *ref, const char *new_name, int force)
error = git_reference_delete(new_ref);
}
- if (error < GIT_SUCCESS && error != GIT_ENOTFOUND)
- goto cleanup;
+ if (error < GIT_SUCCESS) {
+ git_path_join(aux_path, ref->owner->path_repository, new_name);
+ /* If we couldn't read the reference because it doesn't
+ * exist it's ok - otherwise return */
+ if (git_futils_isfile(aux_path) == GIT_SUCCESS)
+ goto cleanup;
+ }
if ((error = reference_available(ref->owner, new_name, ref->name)) < GIT_SUCCESS)
return git__rethrow(error, "Failed to rename reference. Reference already exists");
@@ -1328,9 +1333,7 @@ int git_reference_rename(git_reference *ref, const char *new_name, int force)
git_hashtable_remove(ref->owner->references.loose_cache, old_name);
}
- /* build new path */
git_path_join(aux_path, ref->owner->path_repository, new_name);
-
if (git_futils_exists(aux_path) == GIT_SUCCESS) {
if (git_futils_isdir(aux_path) == GIT_SUCCESS) {
if ((error = git_futils_rmdir_r(aux_path, 0)) < GIT_SUCCESS)