Merge branch 'jk/http-auth-redirects'
[gitweb.git] / builtin / replace.c
index 11b0a55ae7f6e3d1a04eeb4026b151144d0315ba..b1bd3ef9946761b146a38d5977a7378175cda047 100644 (file)
@@ -85,6 +85,7 @@ static int replace_object(const char *object_ref, const char *replace_ref,
                          int force)
 {
        unsigned char object[20], prev[20], repl[20];
+       enum object_type obj_type, repl_type;
        char ref[PATH_MAX];
        struct ref_lock *lock;
 
@@ -100,12 +101,21 @@ static int replace_object(const char *object_ref, const char *replace_ref,
        if (check_refname_format(ref, 0))
                die("'%s' is not a valid ref name.", ref);
 
+       obj_type = sha1_object_info(object, NULL);
+       repl_type = sha1_object_info(repl, NULL);
+       if (!force && obj_type != repl_type)
+               die("Objects must be of the same type.\n"
+                   "'%s' points to a replaced object of type '%s'\n"
+                   "while '%s' points to a replacement object of type '%s'.",
+                   object_ref, typename(obj_type),
+                   replace_ref, typename(repl_type));
+
        if (read_ref(ref, prev))
                hashclr(prev);
        else if (!force)
                die("replace ref '%s' already exists", ref);
 
-       lock = lock_any_ref_for_update(ref, prev, 0);
+       lock = lock_any_ref_for_update(ref, prev, 0, NULL);
        if (!lock)
                die("%s: cannot lock the ref", ref);
        if (write_ref_sha1(lock, repl, NULL) < 0)
@@ -118,9 +128,9 @@ int cmd_replace(int argc, const char **argv, const char *prefix)
 {
        int list = 0, delete = 0, force = 0;
        struct option options[] = {
-               OPT_BOOL('l', NULL, &list, N_("list replace refs")),
-               OPT_BOOL('d', NULL, &delete, N_("delete replace refs")),
-               OPT_BOOL('f', NULL, &force, N_("replace the ref if it exists")),
+               OPT_BOOL('l', "list", &list, N_("list replace refs")),
+               OPT_BOOL('d', "delete", &delete, N_("delete replace refs")),
+               OPT_BOOL('f', "force", &force, N_("replace the ref if it exists")),
                OPT_END()
        };