From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-3.3 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id E4B2C215F4 for ; Tue, 1 May 2018 12:07:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755180AbeEAMHr (ORCPT ); Tue, 1 May 2018 08:07:47 -0400 Received: from mail-wm0-f50.google.com ([74.125.82.50]:35302 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755149AbeEAMHp (ORCPT ); Tue, 1 May 2018 08:07:45 -0400 Received: by mail-wm0-f50.google.com with SMTP id o78so18795623wmg.0 for ; Tue, 01 May 2018 05:07:44 -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 :in-reply-to:references:mime-version:content-transfer-encoding; bh=kmD7MXxBCcVHXpa3214z3qUcEA1ETIFMyrBx0VmYYdc=; b=X2nNi8fGPoLgPo25b5W1XxuHNC8NLfpBAeqMe7zaHFHWENxvexMiw1aOGsn5shhvWq tqaHbKtaIjNVWY6t2DmFAdsDW7kEHK61wl6cFGVB2LAdwY5LVVJp1lVAaOiepjvTKfr/ z2xQ8QvvNMsoA1cUfCM1Vc31C5J/ev502oTyzbX6Y4GXpHml9PakfTzKvjpWfrmVu802 CMRppTaw2dfvt4c2uL6eh3lGfC2rioln3FtLAH4owruCAb1D9Vf5tVoGOzWvoDLqgpUi H3nm49sgT6+TMW7S2V6yOGQilAmt9L+6DA9NjJ9dxIl8GM0EyN0TNWa6cKcrLqJTlwjr cdJg== 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:in-reply-to:references:mime-version :content-transfer-encoding; bh=kmD7MXxBCcVHXpa3214z3qUcEA1ETIFMyrBx0VmYYdc=; b=q8Zga7Lmw0CH5IuLTQ1EoIjNnX4G1C1c+2H5n23NaHidhOTb3+IllO+Xt9ADGuhLR7 t27Q760GgcCwpkD62CA0Zxb4iCfBz2PKTMyqT96p3yH0DaRhr4cNalNGIYsZyLb8VbXd mvsYMWfJmcSxImiiyS/tv87AlL8weVWxIrpVsWlmYCfmOJ+18mnbvA+G3Sf2MpCbOULt GbQeSqaBZdiEkgxq4ZWuB1zSD/fqri9cFc9STRCb7YbFqbJuU9iMw9ju5cu3T8kQF1cA x5VrDztHa/dlXnhvBfhEZR+QSOtr5Raem0k1Oew/Lk7M+n/gAGEpT6HFvbUKK4UbIfo+ 8vBA== X-Gm-Message-State: ALQs6tB7XPFZuzcOylw7xYst1hyUyWWKkNS1fSEgZKRNaGBZpU59LH8j fZdS/uUl+N1LNS9KjKKK6X8owNns X-Google-Smtp-Source: AB8JxZqRrmVRlGEr57kMph08FFrBbUXeHXJBo3RRINblLL9nAmjT6/c9Qcuua0lyFAC9+cJ3BBHwyA== X-Received: by 10.28.232.84 with SMTP id f81mr9451495wmh.134.1525176463390; Tue, 01 May 2018 05:07:43 -0700 (PDT) Received: from u.nix.is ([2a01:4f8:190:5095::2]) by smtp.gmail.com with ESMTPSA id m134sm11738710wmg.4.2018.05.01.05.07.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 May 2018 05:07:42 -0700 (PDT) From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , "brian m . carlson" , Derrick Stolee , Stefan Beller , Eric Sunshine , =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Subject: [PATCH v2 12/12] get_short_oid: document & warn if we ignore the type selector Date: Tue, 1 May 2018 12:06:51 +0000 Message-Id: <20180501120651.15886-13-avarab@gmail.com> X-Mailer: git-send-email 2.17.0.290.gded63e768a In-Reply-To: <20180501120651.15886-1-avarab@gmail.com> References: <20180501120651.15886-1-avarab@gmail.com> In-Reply-To: <20180430220734.30133-1-avarab@gmail.com> References: <20180430220734.30133-1-avarab@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The SHA1 prefix 06fa currently matches no blobs in git.git. When disambiguating short SHA1s we've been quietly ignoring the user's type selector as a fallback mechanism, this was intentionally added in 1ffa26c461 ("get_short_sha1: list ambiguous objects on error", 2016-09-26). I think that behavior makes sense, it's not very useful to just show nothing because a preference has been expressed via core.disambiguate, but it's bad that we're quietly doing this. The user might thing that we just didn't understand what e.g 06fa^{blob} meant. Now we'll instead print a warning if no objects of the requested type were found: $ git rev-parse 06fa^{blob} error: short SHA1 06fa is ambiguous hint: The candidates are: [... no blobs listed ...] warning: Your hint (via core.disambiguate or peel syntax) was ignored, we fell back to showing all object types since no object of the requested type matched the provide short SHA1 06fa Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/config.txt | 4 ++++ sha1-name.c | 11 ++++++++++- t/t1512-rev-parse-disambiguation.sh | 5 ++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 14a3d57e77..e14f2c0492 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -922,6 +922,10 @@ Is set to `none` by default to show all object types. Can also be tags), `tree` (peel: `$sha1^{tree}`), `treeish` (everything except blobs, peel syntax: `$sha1:`), `blob` (peel: `$sha1^{blob}`) or `tag` (peel: `$sha1^{tag}`). The peel syntax will override any config value. ++ +If no objects of the selected type exist the disambiguation will fall +back to `none` and print a warning indicating no objects of the +selected type could be found for that prefix. add.ignoreErrors:: add.ignore-errors (deprecated):: diff --git a/sha1-name.c b/sha1-name.c index 1d2a74a29c..9789764a38 100644 --- a/sha1-name.c +++ b/sha1-name.c @@ -447,6 +447,7 @@ static int get_short_oid(const char *name, int len, struct object_id *oid, if (!quietly && (status == SHORT_NAME_AMBIGUOUS)) { struct oid_array collect = OID_ARRAY_INIT; + int ignored_hint = 0; error(_("short SHA1 %s is ambiguous"), ds.hex_pfx); @@ -456,8 +457,10 @@ static int get_short_oid(const char *name, int len, struct object_id *oid, * that case, we still want to show them, so disable the hint * function entirely. */ - if (!ds.ambiguous) + if (!ds.ambiguous) { ds.fn = NULL; + ignored_hint = 1; + } advise(_("The candidates are:")); for_each_abbrev(ds.hex_pfx, collect_ambiguous, &collect); @@ -466,6 +469,12 @@ static int get_short_oid(const char *name, int len, struct object_id *oid, if (oid_array_for_each(&collect, show_ambiguous_object, &ds)) BUG("show_ambiguous_object shouldn't return non-zero"); oid_array_clear(&collect); + + if (ignored_hint) { + warning(_("Your hint (via core.disambiguate or peel syntax) was ignored, we fell\n" + "back to showing all object types since no object of the requested type\n" + "matched the provide short SHA1 %s"), ds.hex_pfx); + } } return status; diff --git a/t/t1512-rev-parse-disambiguation.sh b/t/t1512-rev-parse-disambiguation.sh index b17973a266..940f323ee9 100755 --- a/t/t1512-rev-parse-disambiguation.sh +++ b/t/t1512-rev-parse-disambiguation.sh @@ -359,7 +359,10 @@ test_expect_success C_LOCALE_OUTPUT 'failed type-selector still shows hint' ' echo 872 | git hash-object --stdin -w && test_must_fail git rev-parse ee3d^{commit} 2>stderr && grep ^hint: stderr >hints && - test_line_count = 3 hints + test_line_count = 3 hints && + grep ^warning stderr >warnings && + grep -q "Your hint.*was ignored" warnings && + grep -q "the provide short SHA1 ee3d" stderr ' test_expect_success 'core.disambiguate config can prefer types' ' -- 2.17.0.290.gded63e768a