Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2013-09-25 10:35:24 +0400
committerJonathan Nieder <jrnieder@gmail.com>2013-09-25 10:35:24 +0400
commit80f165a58a41ffd37ec24022db8e568bc5165075 (patch)
treec0c768386b696dc99860044993ce7d8b16938756 /builtin/replace.c
parentd0c789084ca7796562b19a190f9df31038aaa6df (diff)
parent907492534118a88d071676e78fe4bd1427189a37 (diff)
Merge branch 'cc/replace-with-the-same-type'
* cc/replace-with-the-same-type: Doc: 'replace' merge and non-merge commits t6050-replace: use some long option names replace: allow long option names Documentation/replace: add Creating Replacement Objects section t6050-replace: add test to clean up all the replace refs t6050-replace: test that objects are of the same type Documentation/replace: state that objects must be of the same type replace: forbid replacing an object with one of a different type
Diffstat (limited to 'builtin/replace.c')
-rw-r--r--builtin/replace.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/builtin/replace.c b/builtin/replace.c
index 301b45ce6a..b1bd3ef994 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -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,6 +101,15 @@ 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)
@@ -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()
};