From patchwork Fri Mar 26 15:48:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?zqPPhM6xz43Pgc6/z4Igzp3PhM6tzr3PhM6/z4I=?= X-Patchwork-Id: 12167043 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF874C433C1 for ; Fri, 26 Mar 2021 15:50:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C7EE961A24 for ; Fri, 26 Mar 2021 15:50:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230221AbhCZPt3 (ORCPT ); Fri, 26 Mar 2021 11:49:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230209AbhCZPt0 (ORCPT ); Fri, 26 Mar 2021 11:49:26 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2339C0613AA for ; Fri, 26 Mar 2021 08:49:25 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id n11-20020a05600c4f8bb029010e5cf86347so6129252wmq.1 for ; Fri, 26 Mar 2021 08:49:25 -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=4ziVTcd6aN+EKrntv+C0fV9UfAUf6iQOIwwxAqJHZig=; b=U1tSx/Z60MMVKg0dAMg3p88sdcoRcY6sgkUqYIrQ5RN2gnV8G6vu213UqGn3ZGUZ2M oCQ9IxPAZGB0h7zyd78yxPBr47HqjGiFND8pFX5D9pHLtAx9TXOBNpwaUMX7CB5Ob0jq dqHnZVHAzn/0ndvJ1aD9btW7whyZt/sw5oIqLroEhf0vJQiENwPrR7H6Uhzmfr7U7cBo 3nLQuBxa0L88ZH+GiXQkTJgTqqV603R29cmSOPi7qbMwukbZuBPQ4dOmQJNuzmtvplKB UC44lZekVqaTL3NeRdXvsX2eL5YfcNmtoYFuTug55VQ4Ibf7LPv1rVM/MCuLP/YYMur/ dMAQ== 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=4ziVTcd6aN+EKrntv+C0fV9UfAUf6iQOIwwxAqJHZig=; b=CiNJMrRufQHsWoM/R9DiKGsoN9++1a1L8CivjYX9f4MYS7hfaS4QDEO5BNbMS1+8Yc q6Sar8WjYKNC/lQkYV/C2OfI++4BAiF2ixdZpISbXhWEurpBiWcwERA62n7n/gnPpvuj xL8GQRVerkIBpvjyyHe3cWWuVAC28w6qZdiwhiIxnhS/FmAFgxRS09Pa7fm8OW0rrQmg W//FLeslyzXx7qdSPZP5DxtRCdKgQcQB6UsSPQQtvVgcQwhXLFwOBrhca/Nrt6jxarPF MXnGfQGepan7RqmnwUh4yhxfTSij2E2Uo7fHVEB0B3I4sXDCSsUb8jUE4tYHYIt6XxPn dljg== X-Gm-Message-State: AOAM531yv9Aq9+hicnrr5vDGAvP1YQq/gS6G24sCg0FrEie+QNZOAtCF 9GFlj7p7zl6spGGg9iQUgIGt5a7MgMcxPvOs/X4= X-Google-Smtp-Source: ABdhPJw2lRtL68E4e8p+LF1Fy46oPSRclcscqMIbTDUk2mIH3e160lhGowkFzCBltK59Ejo/u3c9lg== X-Received: by 2002:a1c:1d14:: with SMTP id d20mr13599103wmd.36.1616773764135; Fri, 26 Mar 2021 08:49:24 -0700 (PDT) Received: from localhost.localdomain ([2a02:85f:2a0a:9300:501f:ca6d:3b18:1e72]) by smtp.googlemail.com with ESMTPSA id s3sm11380132wmd.21.2021.03.26.08.49.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 08:49:23 -0700 (PDT) From: Stavros Ntentos X-Google-Original-From: Stavros Ntentos <133706+stdedos@users.noreply.github.com> To: git@vger.kernel.org Cc: stdedos+git@gmail.com, peff@peff.net, bagasdotme@gmail.com, gitster@pobox.com, pclouds@gmail.com, sunshine@sunshineco.com, Stavros Ntentos <133706+stdedos@users.noreply.github.com> Subject: [PATCH v3 1/2] pathspec: warn for a no-glob entry that contains `**` Date: Fri, 26 Mar 2021 17:48:54 +0200 Message-Id: <20210326154855.19528-1-133706+stdedos@users.noreply.github.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210325233648.31162-2-stdedos+git@gmail.com> References: <20210325233648.31162-2-stdedos+git@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org If a pathspec given that contains `**`, chances are that someone is naively expecting that it will do what the manual has told him (i.e. that `**` will match 0-or-more directories). When `**` appears in the pathspec, the user may be expecting that it would be matched using the "wildmatch" semantics, matching 0 or more directories. That is not what happens without ":(glob)" magic. Teach the pathspec parser to emit an advice message when a substring `**` appears in a pathspec element that does not have a `:(glob)` magic. Make sure we don't disturb users who use ":(literal)" magic with such a substring, as it is clear they want to find these strings literally. Signed-off-by: Stavros Ntentos <133706+stdedos@users.noreply.github.com> --- pathspec.c | 13 +++++++++++++ pathspec.h | 1 + t/t6130-pathspec-noglob.sh | 13 +++++++++++++ 3 files changed, 27 insertions(+) diff --git a/pathspec.c b/pathspec.c index 7a229d8d22..d5b9c0d792 100644 --- a/pathspec.c +++ b/pathspec.c @@ -1,3 +1,4 @@ +#include #include "cache.h" #include "config.h" #include "dir.h" @@ -588,6 +589,8 @@ void parse_pathspec(struct pathspec *pathspec, init_pathspec_item(item + i, flags, prefix, prefixlen, entry); + check_missing_glob(entry, item[i].magic); + if (item[i].magic & PATHSPEC_EXCLUDE) nr_exclude++; if (item[i].magic & magic_mask) @@ -739,3 +742,13 @@ int match_pathspec_attrs(const struct index_state *istate, return 1; } + +void check_missing_glob(const char *pathspec_entry, int flags) { + if (flags & (PATHSPEC_GLOB | PATHSPEC_LITERAL)) { + return; + } + + if (strstr(pathspec_entry, "**")) { + warning(_("Pathspec provided contains `**`, but no :(glob) magic.\nIt will not match 0 or more directories!")); + } +} diff --git a/pathspec.h b/pathspec.h index 454ce364fa..913518ebd3 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_missing_glob(const char* pathspec_entry, int flags); #endif /* PATHSPEC_H */ diff --git a/t/t6130-pathspec-noglob.sh b/t/t6130-pathspec-noglob.sh index ba7902c9cd..af6cd16f76 100755 --- a/t/t6130-pathspec-noglob.sh +++ b/t/t6130-pathspec-noglob.sh @@ -157,4 +157,17 @@ test_expect_success '**/ does not work with :(literal) and --glob-pathspecs' ' test_must_be_empty actual ' +cat > expected <<"EOF" +warning: Pathspec provided contains `**`, but no :(glob) magic. +EOF +test_expect_success '** without :(glob) warns of lacking glob magic' ' + test_might_fail git stash -- "**/bar" 2>warns && + grep -Ff expected warns +' + +test_expect_success '** with :(literal) does not warn of lacking glob magic' ' + test_might_fail git stash -- ":(literal)**/bar" 2>warns && + ! grep -Ff expected warns +' + test_done From patchwork Fri Mar 26 15:48:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?zqPPhM6xz43Pgc6/z4Igzp3PhM6tzr3PhM6/z4I=?= X-Patchwork-Id: 12167045 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BA7FC433DB for ; Fri, 26 Mar 2021 15:50:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2906661A21 for ; Fri, 26 Mar 2021 15:50:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230139AbhCZPuB (ORCPT ); Fri, 26 Mar 2021 11:50:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230259AbhCZPt2 (ORCPT ); Fri, 26 Mar 2021 11:49:28 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C81B2C0613AA for ; Fri, 26 Mar 2021 08:49:27 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id z6-20020a1c4c060000b029010f13694ba2so3229074wmf.5 for ; Fri, 26 Mar 2021 08:49:27 -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=whQBRnFM8DAxGlmBYCu3ty8XE120ZOVcbxvGYQ5u7LM=; b=KKvPUTM9DEFXw3VXgIYLNxKjD1g7HdZc51RavLfzo1k6Mbz2BI3FzcQ+0m6kkq2/d7 6ozGCnGCR7kg6bQaWHLwphWXickD4OIi9kaZ0EhmZXmvLXzdqBDtPZQipkgw6oFDw5qM x56EhYwvKWUY/SFa2npAkHs7vLxcxXD1AytDoyBqJGFhch443X6cKjkOcoMPUpGnDUyt 4KtKtMBrkjvZb+H6eBmIeea/xoSL+qO2nE7OXgT16gCxVSibXo90TwaQ9f9abO/10IcV r7RKjHsoZLuXOuLsdsbJRAFSozKWQy4FjMmVegtvOMYfLugx9ePQ+tmCFzrPuoglnNwC 7k4w== 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=whQBRnFM8DAxGlmBYCu3ty8XE120ZOVcbxvGYQ5u7LM=; b=lXxSZ4dwR2Vkhs+ZoR8z4yIP4OrQT+J36nJTX1OTO4H8As24JAlRYT0C61XA6nHwM9 CK7qPx99NCaDhvk/3frG6R/DkBTPVuVRW+DZ4tnwvS4IZ2PBfK1M/9T3x5DG6w3+bcwl DlIx0uvfBGkoMiqiI7dtR+HGCfQ88e9r34w1WoZWr/UcjxQzSeNJhgHsl5E/NqC/34ie HHfrsr5QcMGZXLNdrDKzYVVlIwkP2LHLhJV8mVdcrXoduC8ZPCVVwbGZxzlE5ZqaV81w aB8LBq8TQgkyRRpvfbtGAFg+nhS3nbH2egY9HvUfci1+JXtnHJIMNS4FsheyFVlmbgQz 5jqw== X-Gm-Message-State: AOAM5337Byi+1+Wq4fc7pLQfoQ+fgWyd2sz2WpG2qTlNCjXSlJqGh+nx HVGM+xjdoaB16I/BqjI5/EDPvVbdqgFi6XMplTo= X-Google-Smtp-Source: ABdhPJzO8cotoS3BHOeQj5vODkfxd/ScxJzWDV5qKSwJngyL0Xu/xzkdWvfHv1NMgnC/jgYfxxB0Tg== X-Received: by 2002:a7b:cb99:: with SMTP id m25mr13941317wmi.64.1616773765937; Fri, 26 Mar 2021 08:49:25 -0700 (PDT) Received: from localhost.localdomain ([2a02:85f:2a0a:9300:501f:ca6d:3b18:1e72]) by smtp.googlemail.com with ESMTPSA id s3sm11380132wmd.21.2021.03.26.08.49.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Mar 2021 08:49:25 -0700 (PDT) From: Stavros Ntentos X-Google-Original-From: Stavros Ntentos <133706+stdedos@users.noreply.github.com> To: git@vger.kernel.org Cc: stdedos+git@gmail.com, peff@peff.net, bagasdotme@gmail.com, gitster@pobox.com, pclouds@gmail.com, sunshine@sunshineco.com, Stavros Ntentos <133706+stdedos@users.noreply.github.com> Subject: [PATCH v3 2/2] pathspec: convert no-glob warn to advice Date: Fri, 26 Mar 2021 17:48:55 +0200 Message-Id: <20210326154855.19528-2-133706+stdedos@users.noreply.github.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210326154855.19528-1-133706+stdedos@users.noreply.github.com> References: <20210325233648.31162-2-stdedos+git@gmail.com> <20210326154855.19528-1-133706+stdedos@users.noreply.github.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Teach git that, if anyone wants to squelch such warning, can do so via `git config advice.starStarNoGlobPathspec false` --- Documentation/config/advice.txt | 4 ++++ advice.c | 3 +++ advice.h | 2 ++ pathspec.c | 6 ++++-- t/t6130-pathspec-noglob.sh | 4 +++- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Documentation/config/advice.txt b/Documentation/config/advice.txt index acbd0c09aa..35aa36cfa1 100644 --- a/Documentation/config/advice.txt +++ b/Documentation/config/advice.txt @@ -119,4 +119,8 @@ advice.*:: addEmptyPathspec:: Advice shown if a user runs the add command without providing the pathspec parameter. + starStarNoGlobPathspec:: + Advice shown if a user provides a pathspec via the terminal + that contains `**`, anticipating that the pattern will be + matched using wildmatch (aka `:(glob)` magic). -- diff --git a/advice.c b/advice.c index 164742305f..5703bfba86 100644 --- a/advice.c +++ b/advice.c @@ -33,6 +33,7 @@ int advice_checkout_ambiguous_remote_branch_name = 1; int advice_submodule_alternate_error_strategy_die = 1; int advice_add_ignored_file = 1; int advice_add_empty_pathspec = 1; +int advice_star_star_no_glob_pathspec = 1; static int advice_use_color = -1; static char advice_colors[][COLOR_MAXLEN] = { @@ -95,6 +96,7 @@ static struct { { "submoduleAlternateErrorStrategyDie", &advice_submodule_alternate_error_strategy_die }, { "addIgnoredFile", &advice_add_ignored_file }, { "addEmptyPathspec", &advice_add_empty_pathspec }, + { "starStarNoGlobPathspec", &advice_star_star_no_glob_pathspec }, /* make this an alias for backward compatibility */ { "pushNonFastForward", &advice_push_update_rejected } @@ -137,6 +139,7 @@ static struct { [ADVICE_STATUS_U_OPTION] = { "statusUoption", 1 }, [ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE] = { "submoduleAlternateErrorStrategyDie", 1 }, [ADVICE_WAITING_FOR_EDITOR] = { "waitingForEditor", 1 }, + [ADVICE_STAR_STAR_NO_GLOB_PATHSPEC] = { "starStarNoGlobPathspec", 1 }, }; static const char turn_off_instructions[] = diff --git a/advice.h b/advice.h index bc2432980a..c62fb47434 100644 --- a/advice.h +++ b/advice.h @@ -33,6 +33,7 @@ extern int advice_checkout_ambiguous_remote_branch_name; extern int advice_submodule_alternate_error_strategy_die; extern int advice_add_ignored_file; extern int advice_add_empty_pathspec; +extern int advice_star_star_no_glob_pathspec; /* * To add a new advice, you need to: @@ -72,6 +73,7 @@ extern int advice_add_empty_pathspec; ADVICE_STATUS_U_OPTION, ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE, ADVICE_WAITING_FOR_EDITOR, + ADVICE_STAR_STAR_NO_GLOB_PATHSPEC, }; int git_default_advice_config(const char *var, const char *value); diff --git a/pathspec.c b/pathspec.c index d5b9c0d792..879d87260d 100644 --- a/pathspec.c +++ b/pathspec.c @@ -1,4 +1,4 @@ -#include +#include "git-compat-util.h" #include "cache.h" #include "config.h" #include "dir.h" @@ -744,11 +744,13 @@ int match_pathspec_attrs(const struct index_state *istate, } void check_missing_glob(const char *pathspec_entry, int flags) { + const char *advice = NULL; if (flags & (PATHSPEC_GLOB | PATHSPEC_LITERAL)) { return; } + advice = _("Pathspec provided contains `**`, but no :(glob) magic.\nIt will not match 0 or more directories!"); if (strstr(pathspec_entry, "**")) { - warning(_("Pathspec provided contains `**`, but no :(glob) magic.\nIt will not match 0 or more directories!")); + advise_if_enabled(ADVICE_STAR_STAR_NO_GLOB_PATHSPEC, advice); } } diff --git a/t/t6130-pathspec-noglob.sh b/t/t6130-pathspec-noglob.sh index af6cd16f76..0482030243 100755 --- a/t/t6130-pathspec-noglob.sh +++ b/t/t6130-pathspec-noglob.sh @@ -158,7 +158,9 @@ test_expect_success '**/ does not work with :(literal) and --glob-pathspecs' ' ' cat > expected <<"EOF" -warning: Pathspec provided contains `**`, but no :(glob) magic. +hint: Pathspec provided contains `**`, but no :(glob) magic. +hint: It will not match 0 or more directories! +hint: Disable this message with "git config advice.starStarNoGlobPathspec false" EOF test_expect_success '** without :(glob) warns of lacking glob magic' ' test_might_fail git stash -- "**/bar" 2>warns &&