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=-6.4 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD 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 76DFD20ABE for ; Sat, 21 Jan 2017 01:08:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752590AbdAUBIi (ORCPT ); Fri, 20 Jan 2017 20:08:38 -0500 Received: from 89-28-117-31.starnet.md ([89.28.117.31]:54132 "EHLO home.thecybershadow.net" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752537AbdAUBIh (ORCPT ); Fri, 20 Jan 2017 20:08:37 -0500 Received: by home.thecybershadow.net (Postfix, from userid 1000) id D228555BDEE; Sat, 21 Jan 2017 01:08:32 +0000 (UTC) From: Vladimir Panteleev To: git@vger.kernel.org Cc: Vladimir Panteleev Subject: [PATCH v2 1/4] show-ref: Allow --head to work with --verify Date: Sat, 21 Jan 2017 01:08:18 +0000 Message-Id: <20170121010821.25046-2-git@thecybershadow.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170121010821.25046-1-git@thecybershadow.net> References: <20170121010821.25046-1-git@thecybershadow.net> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Previously, when --verify was specified, show-ref would use a separate code path which ignored --head. Thus, "git show-ref HEAD" used with "--verify" (because the user is not interested in seeing refs/remotes/origin/HEAD), and used with "--head" (because the user does not want HEAD to be filtered out), i.e. "git show-ref --head --verify HEAD", did not work as expected. Instead of insisting that the input begins with "refs/", allow "HEAD" when "--head" is given in the codepath that handles "--verify", so that all valid full refnames including HEAD are passed to the same output machinery. Signed-off-by: Vladimir Panteleev --- builtin/show-ref.c | 3 ++- t/t1403-show-ref.sh | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/builtin/show-ref.c b/builtin/show-ref.c index 6d4e66900..945a483e3 100644 --- a/builtin/show-ref.c +++ b/builtin/show-ref.c @@ -202,7 +202,8 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix) while (*pattern) { struct object_id oid; - if (starts_with(*pattern, "refs/") && + if ((starts_with(*pattern, "refs/") || + (show_head && !strcmp(*pattern, "HEAD"))) && !read_ref(*pattern, oid.hash)) { if (!quiet) show_one(*pattern, &oid); diff --git a/t/t1403-show-ref.sh b/t/t1403-show-ref.sh index 7e10bcfe3..2fb5dc879 100755 --- a/t/t1403-show-ref.sh +++ b/t/t1403-show-ref.sh @@ -164,4 +164,18 @@ test_expect_success 'show-ref --heads, --tags, --head, pattern' ' test_cmp expect actual ' +test_expect_success 'show-ref --verify --head' ' + echo $(git rev-parse HEAD) HEAD >expect && + git show-ref --verify --head HEAD >actual && + test_cmp expect actual && + + >expect && + + git show-ref --verify --head -q HEAD >actual && + test_cmp expect actual && + + test_must_fail git show-ref --verify --head -q A >actual && + test_cmp expect actual +' + test_done -- 2.11.0