From: Manzur Mukhitdinov <manzurmm@gmail.com>
To: git@vger.kernel.org
Cc: Manzur Mukhitdinov <manzurmm@gmail.com>, Jeff King <peff@peff.net>
Subject: [PATCH] replace: fix replacing object with itself
Date: Sun, 9 Nov 2014 01:05:31 +0100 [thread overview]
Message-ID: <1415491531-29913-1-git-send-email-manzurmm@gmail.com> (raw)
When object is replaced with itself git shows unhelpful messages like(git log):
"fatal: replace depth too high for object <SHA1>"
Prevents user from replacing object with itself(with test for checking
this case).
Signed-off-by: Manzur Mukhitdinov <manzurmm@gmail.com>
---
builtin/replace.c | 3 +++
t/t6050-replace.sh | 6 ++++++
2 files changed, 9 insertions(+)
diff --git a/builtin/replace.c b/builtin/replace.c
index 294b61b..b7e05ad 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -186,6 +186,9 @@ static int replace_object(const char *object_ref, const char *replace_ref, int f
if (get_sha1(replace_ref, repl))
die("Failed to resolve '%s' as a valid ref.", replace_ref);
+ if (!hashcmp(object, repl))
+ return error("new object is the same as the old one: '%s'", sha1_to_hex(object));
+
return replace_object_sha1(object_ref, object, replace_ref, repl, force);
}
diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh
index 4d5a25e..f2b0307 100755
--- a/t/t6050-replace.sh
+++ b/t/t6050-replace.sh
@@ -440,4 +440,10 @@ test_expect_success GPG '--graft on a commit with a mergetag' '
git replace -d $HASH10
'
+test_expect_success 'replacing object with itself must fail' '
+ test_must_fail git replace $HASH1 $HASH1 &&
+ HASH8=$(git rev-parse --verify HEAD) &&
+ test_must_fail git replace HEAD $HASH8
+'
+
test_done
--
1.9.1
next reply other threads:[~2014-11-09 0:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-09 0:05 Manzur Mukhitdinov [this message]
2014-11-09 5:58 ` [PATCH] replace: fix replacing object with itself Jeff King
2014-11-09 17:35 ` Junio C Hamano
-- strict thread matches above, loose matches on Subject: below --
2014-11-10 23:20 Manzur Mukhitdinov
2014-11-11 3:03 ` Jeff King
2014-11-13 14:05 Manzur Mukhitdinov
2014-11-14 22:45 ` Junio C Hamano
2014-11-15 11:55 ` Christian Couder
2014-11-16 18:59 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1415491531-29913-1-git-send-email-manzurmm@gmail.com \
--to=manzurmm@gmail.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).