replace: die early if replace ref already exists
If a replace ref already exists for an object, it is much better for the user if we error out before we let the user edit the object, rather than after. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
May 17, 2014 at 14:16 UTC
24790835738dc098fa6becedc44aac0341b7d5af
1 file changed
+4
-1
builtin/replace.c
+4
-1
@@ -268,7 +268,8 @@ static int edit_and_replace(const char *object_ref, int force)
268
{
269
char *tmpfile = git_pathdup("REPLACE_EDITOBJ");
270
enum object_type type;
271
- unsigned char old[20], new[20];
271
+ unsigned char old[20], new[20], prev[20];
272
+ char ref[PATH_MAX];
273
274
if (get_sha1(object_ref, old) < 0)
275
die("Not a valid object name: '%s'", object_ref);
@@ -277,6 +278,8 @@ static int edit_and_replace(const char *object_ref, int force)
278
if (type < 0)
279
die("unable to get object type for %s", sha1_to_hex(old));
280
281
+ check_ref_valid(old, prev, ref, sizeof(ref), force);
282
+
283
export_object(old, tmpfile);
284
if (launch_editor(tmpfile, NULL, NULL) < 0)
285
die("editing object file failed");