{"thread":{"id":"37910","subject":"[PATCH] replace: fix replacing object with itself","startedAt":"2014-11-09T00:05:31Z","lastAt":"2014-11-09T17:35:52Z","messageCount":3,"participants":["Manzur Mukhitdinov","Jeff King","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"251568","messageId":"1415491531-29913-1-git-send-email-manzurmm@gmail.com","threadId":"37910","inReplyTo":null,"subject":"[PATCH] replace: fix replacing object with itself","fromName":"Manzur Mukhitdinov","fromEmail":"manzurmm@gmail.com","sentAt":"2014-11-09T00:05:31Z","receivedAt":"2014-11-09T00:05:31Z","isPatch":true,"sender":{"key":"manzurmm@gmail.com","avatar":"https://gravatar.com/avatar/5e48a8390e02919dedd50464608fa1cdae9ffa475efaa453d91cb618f67f018d?d=mp&s=160"},"body":"When object is replaced with itself git shows unhelpful messages like(git log):\n    \"fatal: replace depth too high for object <SHA1>\"\n\nPrevents user from replacing object with itself(with test for checking\nthis case).\n\nSigned-off-by: Manzur Mukhitdinov <manzurmm@gmail.com>\n---\n builtin/replace.c  | 3 +++\n t/t6050-replace.sh | 6 ++++++\n 2 files changed, 9 insertions(+)\n\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex 294b61b..b7e05ad 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -186,6 +186,9 @@ static int replace_object(const char *object_ref, const char *replace_ref, int f\n \tif (get_sha1(replace_ref, repl))\n \t\tdie(\"Failed to resolve '%s' as a valid ref.\", replace_ref);\n \n+\tif (!hashcmp(object, repl))\n+\t\treturn error(\"new object is the same as the old one: '%s'\", sha1_to_hex(object));\n+\n \treturn replace_object_sha1(object_ref, object, replace_ref, repl, force);\n }\n \ndiff --git a/t/t6050-replace.sh b/t/t6050-replace.sh\nindex 4d5a25e..f2b0307 100755\n--- a/t/t6050-replace.sh\n+++ b/t/t6050-replace.sh\n@@ -440,4 +440,10 @@ test_expect_success GPG '--graft on a commit with a mergetag' '\n \tgit replace -d $HASH10\n '\n \n+test_expect_success 'replacing object with itself must fail' '\n+    test_must_fail git replace $HASH1 $HASH1 &&\n+    HASH8=$(git rev-parse --verify HEAD) &&\n+    test_must_fail git replace HEAD $HASH8\n+'\n+\n test_done\n-- \n1.9.1\n"},{"id":"251575","messageId":"20141109055842.GB13445@peff.net","threadId":"37910","inReplyTo":"1415491531-29913-1-git-send-email-manzurmm@gmail.com","subject":"Re: [PATCH] replace: fix replacing object with itself","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2014-11-09T05:58:43Z","receivedAt":"2014-11-09T05:58:43Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Nov 09, 2014 at 01:05:31AM +0100, Manzur Mukhitdinov wrote:\n\n> When object is replaced with itself git shows unhelpful messages like(git log):\n>     \"fatal: replace depth too high for object <SHA1>\"\n> \n> Prevents user from replacing object with itself(with test for checking\n> this case).\n\nI thought we already did this in the last round of git-replace patches,\nbut it looks like we only did it for the newly added --edit and --graft\ncases, not \"git replace X X\". I think this is probably a good step. I've\nalso considered that this should be another way of deleting the\nreplacement, but I think we decided that was too magical.\n\n> diff --git a/builtin/replace.c b/builtin/replace.c\n> index 294b61b..b7e05ad 100644\n> --- a/builtin/replace.c\n> +++ b/builtin/replace.c\n> @@ -186,6 +186,9 @@ static int replace_object(const char *object_ref, const char *replace_ref, int f\n>  \tif (get_sha1(replace_ref, repl))\n>  \t\tdie(\"Failed to resolve '%s' as a valid ref.\", replace_ref);\n>  \n> +\tif (!hashcmp(object, repl))\n> +\t\treturn error(\"new object is the same as the old one: '%s'\", sha1_to_hex(object));\n> +\n>  \treturn replace_object_sha1(object_ref, object, replace_ref, repl, force);\n\nI think all of the callers of replace_object_sha1 do this same check\nnow. Can we just move the check into that function instead of adding\nanother instance of it?\n\n-Peff\n"},{"id":"251625","messageId":"xmqqy4rkcm4n.fsf@gitster.dls.corp.google.com","threadId":"37910","inReplyTo":"20141109055842.GB13445@peff.net","subject":"Re: [PATCH] replace: fix replacing object with itself","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-11-09T17:35:52Z","receivedAt":"2014-11-09T17:35:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> I think all of the callers of replace_object_sha1 do this same check\n> now. Can we just move the check into that function instead of adding\n> another instance of it?\n\nGood thinking.  Thanks.\n"}]}