From patchwork Sun Mar 31 13:46:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 10878759 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3901E184E for ; Sun, 31 Mar 2019 13:47:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21BA128942 for ; Sun, 31 Mar 2019 13:47:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 141CF2893E; Sun, 31 Mar 2019 13:47:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FC3028649 for ; Sun, 31 Mar 2019 13:47:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731183AbfCaNrZ (ORCPT ); Sun, 31 Mar 2019 09:47:25 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:55679 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726863AbfCaNrZ (ORCPT ); Sun, 31 Mar 2019 09:47:25 -0400 Received: by mail-wm1-f65.google.com with SMTP id o25so7376110wmf.5 for ; Sun, 31 Mar 2019 06:47:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mqpkrNR1P5CYNde3Z3grem5V4WT7WS4kIpFjg/5cxGc=; b=OFLyKYNdCZDRy/jTSOd5LR2UfZ1CXhf4cBwYQpS7Jw/ZjLZXnBpYZJjmPJmGD1v3On 4nRJZYh6PXgRsDlZFcpkjzZq1kfbGkEO5s8lZWbsQgv71qLU6O9+0y8JpRbmsd6PXaKK HZNWSlnrCx4bqFxGz2JHXCkBBPNsZitzXpsgFIEjYdx/SCWlUDt3CWiie/J60jBS/cRz I662fnAZyS7RSR4L2tY/r5uenpsYdDjMHdl70rJU+5AunkQuScsQWvdV27sXhLiFkpDu 8AR9IQKoXIiftv8bb/wuygR/9Y0e41ZVigVJIfsuxlBFS/6rq8b6bxEgQC+HswnZcVho VUTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mqpkrNR1P5CYNde3Z3grem5V4WT7WS4kIpFjg/5cxGc=; b=I17Q2TQBKeWjra6zP1yB0mVjKx1t1fHZyMMDBcFK0hfhKJ8+onUvN2/TV+8GshA+r+ 9B0Pdi8f9m7J/n3crWSnir5ChZXFNgiJWD9hRNljbM4nKfosJX9raeaou6BIHB4u5ruV h2SjGkSYWw1gxSvMqqtMj0q2kXx75Xn3JrKZaZbWauQimxyt/KGY7VTSH5+DnSD5qsM0 /XbNmWEHojGDSOJI1Rs7xAjQEFh/iY00eNloiGD7oT3wyVnClq53slpd2y5B22m9GPGG DOqUW+IR2zWyb7iBGNbHH9It6NXaCvjBS4HtYagoyopGroiywHI2+wrlTStOESFSn8yp hA6Q== X-Gm-Message-State: APjAAAXNwqZEX15wFGSnVm9paMbrf2Edb2768za0lbySJPcWv2SmGdga llQFn3heC31URk0vy9Srwv4TitQ6 X-Google-Smtp-Source: APXvYqz+ou0gUizo5GytJteGf/mpxg32KeQcZq+0nWkLxH5f6p2WfYoxdHEhrOltqv6mCziw6NvoUw== X-Received: by 2002:a1c:ac07:: with SMTP id v7mr2136952wme.49.1554040043507; Sun, 31 Mar 2019 06:47:23 -0700 (PDT) Received: from localhost.localdomain ([2a04:cec0:10ce:4d96:49c5:28f4:744c:fa99]) by smtp.gmail.com with ESMTPSA id o10sm10290490wru.54.2019.03.31.06.47.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 Mar 2019 06:47:23 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Andreas Schwab , Taylor Blau , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= , Christian Couder Subject: [PATCH v2 1/4] t6050: use test_line_count instead of wc -l Date: Sun, 31 Mar 2019 15:46:56 +0200 Message-Id: <20190331134659.28808-2-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.21.0.69.g2d86a08d09 In-Reply-To: <20190331134659.28808-1-chriscool@tuxfamily.org> References: <20190331134659.28808-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This modernizes a test and makes it more portable. Reviewed-by: Taylor Blau Signed-off-by: Christian Couder --- t/t6050-replace.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index d638119750..41b177936e 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -393,9 +393,11 @@ test_expect_success 'replace ref cleanup' ' ' test_expect_success '--graft with and without already replaced object' ' - test $(git log --oneline | wc -l) = 7 && + git log --oneline >log && + test_line_count = 7 log && git replace --graft $HASH5 && - test $(git log --oneline | wc -l) = 3 && + git log --oneline >log && + test_line_count = 3 log && commit_has_parents $HASH5 && test_must_fail git replace --graft $HASH5 $HASH4 $HASH3 && git replace --force -g $HASH5 $HASH4 $HASH3 && From patchwork Sun Mar 31 13:46:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 10878761 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 572FC17E0 for ; Sun, 31 Mar 2019 13:47:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4298528649 for ; Sun, 31 Mar 2019 13:47:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3168328984; Sun, 31 Mar 2019 13:47:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A00EA2893B for ; Sun, 31 Mar 2019 13:47:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731193AbfCaNr2 (ORCPT ); Sun, 31 Mar 2019 09:47:28 -0400 Received: from mail-wm1-f52.google.com ([209.85.128.52]:54769 "EHLO mail-wm1-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726863AbfCaNr1 (ORCPT ); Sun, 31 Mar 2019 09:47:27 -0400 Received: by mail-wm1-f52.google.com with SMTP id c1so6231528wml.4 for ; Sun, 31 Mar 2019 06:47:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J+z7yJH0rz8re/QWD72sBMaBlK2OUkGVtrqoEeqVwVo=; b=Ix3nwWJb4NDp25QjZAaCOY+be40Hy9rjBDp+HD+Fgs2nWeDpn9kUH71ytIcNdmtpft Qp8wQ5b9H/TvrDB01nCOVau3dhOj/j0LvofAPyIwbnAfbtsAB2iQCInSjn0zZaFsXtHa wv525QV/09yzG1z0Lr8H8cBcLOdlBNWX7eNJUyqMnSTEiZC+8wdlpoAjuq/9kIifAxup O6e2D3lTeY+mlkwxjGuFnatFZ3o2d4qNuj0yZo0KFZ56Q6YiqKnTaPRSOLG9qwMJFLPr zBUkv5UcFagczWn0IPhN6HqHxag88mcJhgqAts/slGTLoVVmTYqdSbApiHvhgJK3FeO4 cljA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=J+z7yJH0rz8re/QWD72sBMaBlK2OUkGVtrqoEeqVwVo=; b=Cd27VY/v6/7G7knZPAKRLGcIqo0a2z8Dv9bctvZDJJ8Av8+Sq7M4wxIuX+j+71ED7r eL+0WC912WPgx231zEC8FJaMOXalcgpcCX6v1qGdLCoLFm2B2db8lJ/a05mBG6JNa7EE qv0GdXyFXu4aQGHJBEhF5FzpI6gecmWpsw6Y9Zp/5JApG2vbxwW54/k2tnBTj8F5yHfE Vcy5YcQSFkTCkcgxN/P3yBunB6u1u+N23EpCXzz9jEr6CTGL0BYYDMvGzDfVCDCmR1Oc FfaE0v6NqoZ7sl+ZhOzp0MIlUe45njs6fOrtVG8fzRIKyyH//UB3T0HdZ9AvOI57WI96 2hZQ== X-Gm-Message-State: APjAAAVrw5IhuyezNj3YSygKYpNuwO59oE6w/bFZ4Z4H9GGm2HfZxBfq JQAOp1juQO6FioTP4M7L2rjXkb54 X-Google-Smtp-Source: APXvYqzsAdtN+cez2sP1xUiHDY7tjCqrlDAF1MKx2MfyztDB9hwzAsJWAg44IB6argcroEnfMYhPrw== X-Received: by 2002:a7b:c404:: with SMTP id k4mr9993064wmi.117.1554040045783; Sun, 31 Mar 2019 06:47:25 -0700 (PDT) Received: from localhost.localdomain ([2a04:cec0:10ce:4d96:49c5:28f4:744c:fa99]) by smtp.gmail.com with ESMTPSA id o10sm10290490wru.54.2019.03.31.06.47.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 Mar 2019 06:47:25 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Andreas Schwab , Taylor Blau , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= , Christian Couder Subject: [PATCH v2 2/4] t6050: redirect expected error output to a file Date: Sun, 31 Mar 2019 15:46:57 +0200 Message-Id: <20190331134659.28808-3-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.21.0.69.g2d86a08d09 In-Reply-To: <20190331134659.28808-1-chriscool@tuxfamily.org> References: <20190331134659.28808-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Otherwise the error from `git rev-parse` is uselessly polluting the debug output. Redirecting to a file, instead of /dev/null, makes it possible to check that we got the error we expected, so let's check that too. Reviewed-by: Taylor Blau Helped-by: Eric Sunshine Helped-by: Ævar Arnfjörð Bjarmason Signed-off-by: Christian Couder --- t/t6050-replace.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index 41b177936e..948d278482 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -40,7 +40,8 @@ commit_peeling_shows_parents () test "$_found" = "$_parent" || return 1 _parent_number=$(( $_parent_number + 1 )) done && - test_must_fail git rev-parse --verify $_commit^$_parent_number + test_must_fail git rev-parse --verify $_commit^$_parent_number 2>err && + test_i18ngrep "Needed a single revision" err } commit_has_parents () From patchwork Sun Mar 31 13:46:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 10878763 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7745D1908 for ; Sun, 31 Mar 2019 13:47:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E0A828649 for ; Sun, 31 Mar 2019 13:47:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 49E7A2893E; Sun, 31 Mar 2019 13:47:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1AB12893F for ; Sun, 31 Mar 2019 13:47:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731196AbfCaNra (ORCPT ); Sun, 31 Mar 2019 09:47:30 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36056 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726863AbfCaNra (ORCPT ); Sun, 31 Mar 2019 09:47:30 -0400 Received: by mail-wr1-f67.google.com with SMTP id y13so8442754wrd.3 for ; Sun, 31 Mar 2019 06:47:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MFk4hnCK550dt86hBGUy/4SxtO34aJvku0xxR2dpxD8=; b=IP58Tu8lMnKHg+F6P9qQ3ZDZGu136ZjPocROB18x3mImIfJnO0KYaoWzVyyvqNGcFH Uke69weIgRvFVN+uamocGqxuWaxNopeoUprYfNzvyRyU37Vv/te4oq480vtWQD5qIkmF ODP1ZDMrpZIL01iYfwt337jZeArCDpCWt2QsNfxhUB/Bo6L+JsaESiND5X6i8bnHmBYq oJw7EBQTDL68eowwSJE9gtFiEgzKS5bFDhF9LQAp5TvvlFR87gp3mbCHv6dN8wz+5v+m q9oz0cqEQwIwirnCn3Sjj+eLhNsGXupRA/J8ZwuvF+9cbsAP//9l5fxFiwxh3+ciD1Ww qDCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MFk4hnCK550dt86hBGUy/4SxtO34aJvku0xxR2dpxD8=; b=N8p1kV/DXmwI8MntONF5fhakNGm1BqnoM18SIzJbwDcCBwc//mUw1ADs0Z+Rh0jY45 7PWQKlNmPxa+OpEmdN3y1DVAZ/YAqsBFy/IfcEnFEki0JLFcDhZvizmKqSF7nKNRo1HJ TUe413/QmBKC4yES/g7M4sXMCppf/rjIjYdqYp/kgOJf4Qn785Wcuro5zIIHaqTvSNkA H1Jddq4F4L5AT3jKchjvMGQj0Zd+vojp+ftylXcevvb2+oOiZA61Zu1vdnXTrAdgPAzM 8yVl8o9mcEtiJxWrwJe59zNGIPzLAGujjvTj/zgNrIvTL4R5E+HhBXqZRRersz+PkVTq EuLg== X-Gm-Message-State: APjAAAW8SdHtEm315RtzbLQ/ymugPhIQpTIlXMY54pguC/CiT6Yd9Rrz 6PBeulCRwxM/nd9D+VFPkXwiOL5B X-Google-Smtp-Source: APXvYqxHwJr/jFPHFAL/83amYl17iD5q2c1RZn/nT1Nc95t4btCEooqlGZZAnSqUiA0hGhb2MCUjOQ== X-Received: by 2002:adf:ef0c:: with SMTP id e12mr37264319wro.170.1554040048076; Sun, 31 Mar 2019 06:47:28 -0700 (PDT) Received: from localhost.localdomain ([2a04:cec0:10ce:4d96:49c5:28f4:744c:fa99]) by smtp.gmail.com with ESMTPSA id o10sm10290490wru.54.2019.03.31.06.47.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 Mar 2019 06:47:27 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Andreas Schwab , Taylor Blau , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= , Christian Couder Subject: [PATCH v2 3/4] replace: fix --graft when passing a tag as parent Date: Sun, 31 Mar 2019 15:46:58 +0200 Message-Id: <20190331134659.28808-4-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.21.0.69.g2d86a08d09 In-Reply-To: <20190331134659.28808-1-chriscool@tuxfamily.org> References: <20190331134659.28808-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When passing a tag as a parent argument to `git replace --graft`, it can be useful to accept it and use the underlying commit as a parent. This already works for lightweight tags, but unfortunately for annotated tags we have been using the hash of the tag object instead of the hash of the underlying commit as a parent in the replacement object we create. This created invalid objects, but the replace succeeded even if it showed an error like: error: object A is a tag, not a commit This patch fixes that by using the hash of the underlying commit when an annotated tag is passed. While at it, let's also update an error message to make it clearer. Reviewed-by: Taylor Blau Signed-off-by: Christian Couder --- builtin/replace.c | 9 ++++++--- t/t6050-replace.sh | 11 +++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/builtin/replace.c b/builtin/replace.c index f5701629a8..b0a9227f9a 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -370,16 +370,19 @@ static int replace_parents(struct strbuf *buf, int argc, const char **argv) /* prepare new parents */ for (i = 0; i < argc; i++) { struct object_id oid; + struct commit *commit; + if (get_oid(argv[i], &oid) < 0) { strbuf_release(&new_parents); return error(_("not a valid object name: '%s'"), argv[i]); } - if (!lookup_commit_reference(the_repository, &oid)) { + commit = lookup_commit_reference(the_repository, &oid); + if (!commit) { strbuf_release(&new_parents); - return error(_("could not parse %s"), argv[i]); + return error(_("could not parse %s as a commit"), argv[i]); } - strbuf_addf(&new_parents, "parent %s\n", oid_to_hex(&oid)); + strbuf_addf(&new_parents, "parent %s\n", oid_to_hex(&commit->object.oid)); } /* replace existing parents with new ones */ diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index 948d278482..2385a60f68 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -406,6 +406,17 @@ test_expect_success '--graft with and without already replaced object' ' git replace -d $HASH5 ' +test_expect_success '--graft using a tag as the new parent' ' + git tag new_parent $HASH5 && + git replace --graft $HASH7 new_parent && + commit_has_parents $HASH7 $HASH5 && + git replace -d $HASH7 && + git tag -a -m "annotated new parent tag" annotated_new_parent $HASH5 && + git replace --graft $HASH7 annotated_new_parent && + commit_has_parents $HASH7 $HASH5 && + git replace -d $HASH7 +' + test_expect_success GPG 'set up a signed commit' ' echo "line 17" >>hello && echo "line 18" >>hello && From patchwork Sun Mar 31 13:46:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 10878765 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7E2B4186D for ; Sun, 31 Mar 2019 13:47:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69D65212E8 for ; Sun, 31 Mar 2019 13:47:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67C3528942; Sun, 31 Mar 2019 13:47:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E2932212E8 for ; Sun, 31 Mar 2019 13:47:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731203AbfCaNrd (ORCPT ); Sun, 31 Mar 2019 09:47:33 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:43998 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726863AbfCaNrc (ORCPT ); Sun, 31 Mar 2019 09:47:32 -0400 Received: by mail-wr1-f66.google.com with SMTP id k17so8393766wrx.10 for ; Sun, 31 Mar 2019 06:47:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YuF7poVuZpGgkVepodOt8kdUjGgzM3PxHwrOPrmsA9A=; b=rQBoXoo1BovO0lHKVHLDBB641yTRf1SBOfxc7FYDFkaqyhCn/hmn6z8XHLPJSabX3H hoqtZOMN/MRBvvRJE2QzRTCS78baq9u8pdCmiuTVSELnDgEK9EATtMS3g8qA3xt5R7cy wyrWlZWmZO/u7oeUTQuLulEZcJPrk1+FEqi5Vf+RcAZtwuOoSP+o+eH6SWSxcZxxdVRp X56n5zLF914vzlCQVU07f/ifEPvgrSKmaiKFWVrKTFsTj5zB4FgRyRr3eFqnTUFxk79x Jr50vs08WeJWN+fRQNR88+eeyuZetDJWDblvqhuNMW6AG4ogAPK2sb/vR/CRckjDZEK2 UzhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YuF7poVuZpGgkVepodOt8kdUjGgzM3PxHwrOPrmsA9A=; b=mDrsQelhwVFXYmc1Ub6eej2GTDBex0SrEhCfn9CTV1P3Kxmi+W5OS8I7HAt0QG94zv iUrRVAnEL/h/Xowz6cD+nfH7iA9jH483BUnzHjMU8tbYPR7wUZSFrD6vsm3B3axPF+eM cUOzJbLQByKTarBhj3LiCTLnRlaTk0neeqx9ksj7uC78OQvthnffPQFaM+O9tNpj+eko nO7CpfAY1qVVVNCXAPh0qByxL4jZ294YT/Cufy2wyO+v/2ivmKXW2+2bh3IdYRd+w1TI 26X1lNIJweEJHWkG1p94tDOxP1PcxiK80IEsGKHXkf4CnaythlGL4S1AegLT80+WznNE ALIg== X-Gm-Message-State: APjAAAVCDYR/lhBwxHNi9OSVH1ZacqTVZK76EGZYM9Mk+e9cqmbejXRc Q7PLj26lM27qN+cwi6Q2ZhiN8g0L X-Google-Smtp-Source: APXvYqzKQWMcsuXbN/3/Wa17w+x2RSKvZR+Z/bzeX49PD7HSteGggdV97aj6kpBolFks1YDF/Bfh7g== X-Received: by 2002:adf:c788:: with SMTP id l8mr28441106wrg.143.1554040050669; Sun, 31 Mar 2019 06:47:30 -0700 (PDT) Received: from localhost.localdomain ([2a04:cec0:10ce:4d96:49c5:28f4:744c:fa99]) by smtp.gmail.com with ESMTPSA id o10sm10290490wru.54.2019.03.31.06.47.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 Mar 2019 06:47:30 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Andreas Schwab , Taylor Blau , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= , Christian Couder Subject: [PATCH v2 4/4] replace: fix --graft when passing a tag first Date: Sun, 31 Mar 2019 15:46:59 +0200 Message-Id: <20190331134659.28808-5-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.21.0.69.g2d86a08d09 In-Reply-To: <20190331134659.28808-1-chriscool@tuxfamily.org> References: <20190331134659.28808-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When passing a tag as the first argument to `git replace --graft`, it can be useful to accept it and use the underlying commit as a the commit that will be replaced. This already works for lightweight tags, but unfortunately for annotated tags we have been using the hash of the tag object instead of the hash of the underlying commit. Especially we would pass the hash of the tag object to replace_object_oid() where we would likely fail with an error like: "error: Objects must be of the same type. 'annotated_replaced_object' points to a replaced object of type 'tag' while 'replacement' points to a replacement object of type 'commit'." This patch fixes that by using the hash of the underlying commit when an annotated tag is passed. Signed-off-by: Christian Couder --- builtin/replace.c | 11 +++++++---- t/t6050-replace.sh | 11 +++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/builtin/replace.c b/builtin/replace.c index b0a9227f9a..644b21ca8d 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -481,15 +481,18 @@ static int create_graft(int argc, const char **argv, int force, int gentle) strbuf_release(&buf); - if (oideq(&old_oid, &new_oid)) { + if (oideq(&commit->object.oid, &new_oid)) { if (gentle) { - warning(_("graft for '%s' unnecessary"), oid_to_hex(&old_oid)); + warning(_("graft for '%s' unnecessary"), + oid_to_hex(&commit->object.oid)); return 0; } - return error(_("new commit is the same as the old one: '%s'"), oid_to_hex(&old_oid)); + return error(_("new commit is the same as the old one: '%s'"), + oid_to_hex(&commit->object.oid)); } - return replace_object_oid(old_ref, &old_oid, "replacement", &new_oid, force); + return replace_object_oid(old_ref, &commit->object.oid, + "replacement", &new_oid, force); } static int convert_graft_file(int force) diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index 2385a60f68..e7e64e085d 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -417,6 +417,17 @@ test_expect_success '--graft using a tag as the new parent' ' git replace -d $HASH7 ' +test_expect_success '--graft using a tag as the replaced object' ' + git tag replaced_object $HASH7 && + git replace --graft replaced_object $HASH5 && + commit_has_parents $HASH7 $HASH5 && + git replace -d $HASH7 && + git tag -a -m "annotated replaced object tag" annotated_replaced_object $HASH7 && + git replace --graft annotated_replaced_object $HASH5 && + commit_has_parents $HASH7 $HASH5 && + git replace -d $HASH7 +' + test_expect_success GPG 'set up a signed commit' ' echo "line 17" >>hello && echo "line 18" >>hello &&