From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.5 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,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id B9DA41F9FC for ; Fri, 26 Mar 2021 02:41:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230370AbhCZClV (ORCPT ); Thu, 25 Mar 2021 22:41:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230391AbhCZCkx (ORCPT ); Thu, 25 Mar 2021 22:40:53 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06208C06174A for ; Thu, 25 Mar 2021 19:40:53 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id y124-20020a1c32820000b029010c93864955so4114324wmy.5 for ; Thu, 25 Mar 2021 19:40:52 -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=rtpZSf9kLrMAxrGnGcXqeP8HmTBX5KVYrwxGNDtBbmc=; b=bbaSLfSd5fAXFB2CQJNvOXTaPv0qGM+qdT8hDsdNkiUQTdRrC2f1DvL0TZIVJLm2CL XO2Rnk3G741ONc/tBmKOc4fpiRstjprQoHmvC/kGpP20AVbEXLRyLIuXVSaSWOoUQbDc ts8V9kxVO5SY6Dt5fxC/KbvK1kDNv2r1UG2eD37HKfTpxFXoPgIcu6nHgNaWZlXDyzyO 7czORnXzEBGovnkAlrMV6aesym61xMONqFveK5kLTNyEBsagsIl0yg2BLQzAtaBvHn7h c3YYxkmJoiVsK3YCfDMBQmA3yuCBkVD0Q0gjFTZ2jg4YzkiQYlmFPTD6N3RHOBP4mup6 F0Qg== 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=rtpZSf9kLrMAxrGnGcXqeP8HmTBX5KVYrwxGNDtBbmc=; b=NvIcWDbWiFfCO6JxRB73Iu9xVKyhIlu5Zj10Y8LV8AXhfUr1VuBjli3U3ndqAbReLf Y9cdeDOzIUba6PthOPvp+PgBLAf2dcs20Ubvf5TUf1p2v9zy81dgkMtB+CdbRRtyFrAD K7T1rLa95SaRscPtqTOiO5e9bNcRkrYnfhoDR/8fXar6lavyL82gwzMRf57E9bpuXDWP HosBtDyOb55Phgvcxfx6XBC5a6NFBlnlCNXuKhjma90W8DguwMTgvUfXh5zWRHMgH4dx ZHBHI/DUsBfx1ZJ6FKyWAjeXBkowuJunLHZ6AwGGDVFUPSjkQSeOGBf9tJQY654+0jk9 cVDw== X-Gm-Message-State: AOAM533WH3vJaX72iBpJWXqPmQoNPN1kXUSNlG/MCLbbjmvvoftR4JgM sJUjOLU9XZH2iR3bJegAhE5+mmmf4brAtbdI/ao= X-Google-Smtp-Source: ABdhPJxmiUEqO9PY3l+Cyvg1UgRIWPUSaZe5lgayKKQRziUJL3+PrhScRbAPUS6oDWarJrhHkyGbnQ== X-Received: by 2002:a1c:771a:: with SMTP id t26mr10818814wmi.60.1616726451352; Thu, 25 Mar 2021 19:40:51 -0700 (PDT) Received: from localhost.localdomain ([2a02:85f:2a0a:9300:501f:ca6d:3b18:1e72]) by smtp.googlemail.com with ESMTPSA id i10sm10020226wrs.11.2021.03.25.19.40.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Mar 2021 19:40:50 -0700 (PDT) From: "=?UTF-8?q?=CE=A3=CF=84=CE=B1=CF=8D=CF=81=CE=BF=CF=82=20=CE=9D=CF=84=CE=AD=CE=BD=CF=84=CE=BF=CF=82?=" X-Google-Original-From: =?UTF-8?q?=CE=A3=CF=84=CE=B1=CF=8D=CF=81=CE=BF=CF=82=20=CE=9D=CF=84=CE=AD=CE=BD=CF=84=CE=BF=CF=82?= To: git Cc: =?UTF-8?q?=CE=A3=CF=84=CE=B1=CF=8D=CF=81=CE=BF=CF=82=20=CE=9D=CF=84=CE=AD=CE=BD=CF=84=CE=BF=CF=82?= , Junio C Hamano , Bagas Sanjaya , Stavros Ntentos <133706+stdedos@users.noreply.github.com> Subject: [RFC PATCH v1 1/2] pathspec: warn: long and short forms are incompatible Date: Fri, 26 Mar 2021 04:40:04 +0200 Message-Id: <20210326024005.26962-2-stdedos+git@gmail.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210326024005.26962-1-stdedos+git@gmail.com> References: <20210326024005.26962-1-stdedos+git@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Stavros Ntentos <133706+stdedos@users.noreply.github.com> Namely, `!` and any other long magic form (e.g. `glob`) cannot be combined to one entry. Issue a warning when such thing happens, and hint to the solution. Signed-off-by: Stavros Ntentos <133706+stdedos@users.noreply.github.com> --- pathspec.c | 19 +++++++++++++++++++ pathspec.h | 1 + t/t6132-pathspec-exclude.sh | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/pathspec.c b/pathspec.c index 7a229d8d22..374c529569 100644 --- a/pathspec.c +++ b/pathspec.c @@ -1,3 +1,5 @@ +#include +#include #include "cache.h" #include "config.h" #include "dir.h" @@ -586,6 +588,8 @@ void parse_pathspec(struct pathspec *pathspec, for (i = 0; i < n; i++) { entry = argv[i]; + check_mishandled_exclude(entry); + init_pathspec_item(item + i, flags, prefix, prefixlen, entry); if (item[i].magic & PATHSPEC_EXCLUDE) @@ -739,3 +743,18 @@ int match_pathspec_attrs(const struct index_state *istate, return 1; } + +void check_mishandled_exclude(const char *entry) { + size_t entry_len = strlen(entry); + char flags[entry_len]; + char path[entry_len]; + + if (sscanf(entry, ":!(%4096[^)])%4096s", &flags, &path) != 2) { + return; + } + if (count_slashes(flags) > 0) { + return; + } + + warning(_("Pathspec provided matches `:!(...)`\n\tDid you mean `:(exclude,...)`?")); +} diff --git a/pathspec.h b/pathspec.h index 454ce364fa..879d4e82c6 100644 --- a/pathspec.h +++ b/pathspec.h @@ -157,5 +157,6 @@ char *find_pathspecs_matching_against_index(const struct pathspec *pathspec, int match_pathspec_attrs(const struct index_state *istate, const char *name, int namelen, const struct pathspec_item *item); +void check_mishandled_exclude(const char* pathspec_entry); #endif /* PATHSPEC_H */ diff --git a/t/t6132-pathspec-exclude.sh b/t/t6132-pathspec-exclude.sh index 30328b87f0..b32ddb2a56 100755 --- a/t/t6132-pathspec-exclude.sh +++ b/t/t6132-pathspec-exclude.sh @@ -244,4 +244,37 @@ test_expect_success 'grep --untracked PATTERN :(exclude)*FILE' ' test_cmp expect-grep actual-grep ' +cat > expected_warn <<"EOF" +Pathspec provided matches `:!(...)` +EOF +test_expect_success 'warn pathspec :!(...) skips the parenthesized magics' ' + git log --oneline --format=%s -- '"'"':!(glob)**/file'"'"' >actual 2>warn && + cat <expect && +sub2/file +sub/sub/sub/file +sub/file2 +sub/sub/file +sub/file +file +EOF + cat actual && + cat warn && + test_cmp expect actual && + grep -Ff expected_warn warn +' + +test_expect_success 'do not warn that pathspec :!(...) skips the parenthesized magics (if parenthesis would not be part of the magic)' ' + git log --oneline --format=%s -- '"'"':!(gl/ob)/file'"'"' >actual 2>warn && + cat <expect && +sub2/file +sub/sub/sub/file +sub/file2 +sub/sub/file +sub/file +file +EOF + test_cmp expect actual && + ! grep -Ff expected_warn warn +' + test_done -- 2.31.0