summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Turner <dturner@twopensource.com>2016-02-24 17:58:47 -0500
committerJunio C Hamano <gitster@pobox.com>2016-02-25 16:01:02 -0800
commitfe4e79996af79e125ba70a1e9bea099b54dd4570 (patch)
treebe850ce281f96aa79c09c22618b7c1b8e8b52bf6
parent5f41af8e4300d62ae93c59c4571ca97c4ce4f914 (diff)
downloadgit-fe4e79996af79e125ba70a1e9bea099b54dd4570.tar.gz
refs: handle non-normal ref renames
Forbid cross-backend ref renames. This would be pretty weird, but since it will break, we should prevent it. Also make the files backend deal with all non-normal ref renames. Signed-off-by: David Turner <dturner@twopensource.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--refs.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/refs.c b/refs.c
index 9ce92c116a..cef4c1b546 100644
--- a/refs.c
+++ b/refs.c
@@ -1415,5 +1415,15 @@ int delete_refs(struct string_list *refnames)
int rename_ref(const char *oldref, const char *newref, const char *logmsg)
{
- return the_refs_backend->rename_ref(oldref, newref, logmsg);
+ if ((ref_type(oldref) == REF_TYPE_NORMAL) !=
+ (ref_type(newref) == REF_TYPE_NORMAL)) {
+ return error(
+ _("Both ref arguments to rename_ref must be normal, "
+ "or both must be per-worktree/pseudorefs"));
+ }
+ if (ref_type(oldref) == REF_TYPE_NORMAL)
+ /* The files backend always deals with non-normal refs */
+ return the_refs_backend->rename_ref(oldref, newref, logmsg);
+ else
+ return refs_be_files.rename_ref(oldref, newref, logmsg);
}