Skip to content

Commit 2479083

Browse files
chriscoolgitster
authored andcommitted
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>
1 parent b6e3884 commit 2479083

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

builtin/replace.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ static int edit_and_replace(const char *object_ref, int force)
268268
{
269269
char *tmpfile = git_pathdup("REPLACE_EDITOBJ");
270270
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];
272273

273274
if (get_sha1(object_ref, old) < 0)
274275
die("Not a valid object name: '%s'", object_ref);
@@ -277,6 +278,8 @@ static int edit_and_replace(const char *object_ref, int force)
277278
if (type < 0)
278279
die("unable to get object type for %s", sha1_to_hex(old));
279280

281+
check_ref_valid(old, prev, ref, sizeof(ref), force);
282+
280283
export_object(old, tmpfile);
281284
if (launch_editor(tmpfile, NULL, NULL) < 0)
282285
die("editing object file failed");

0 commit comments

Comments
 (0)