From patchwork Fri Sep 10 11:28:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12484951 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=-15.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,SPF_HELO_NONE,SPF_PASS,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 D8A53C433FE for ; Fri, 10 Sep 2021 11:30:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C013F6108B for ; Fri, 10 Sep 2021 11:30:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232793AbhIJLb3 (ORCPT ); Fri, 10 Sep 2021 07:31:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232783AbhIJLb2 (ORCPT ); Fri, 10 Sep 2021 07:31:28 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2487CC061574 for ; Fri, 10 Sep 2021 04:30:17 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id i3so972389wmq.3 for ; Fri, 10 Sep 2021 04:30:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3qjkeoBLWZp3W3G37t1lZY6yDIN2SCEN+Ps8suMIGCI=; b=pzCAYJwMexyuplwkoz3Ujc8gnOa001VSbZ2DA0jqLoiRqHoErAyAPa0ePDudnKsSQI eduEQUoM5xBhd4pcDps2z4JeAvn/O4pLjqrIX/EsvZ7DQHRDeLDH1NRRuDUVH5hL2c8f aN7EPqafdiUeBrCB+Auw1A9BEyUTX6TuF/cPAfjWimIzXVtvMC2w4Ce/uJTzRoN5tpfe PXnyok1UJgYkeIV3wKi03obRj8FD4fptQ39ZZE0iMjxrkjzQ2/ic42VJB4fGmvM1ELJH eNhVpQzTWyP2QG6oP/vqo19KzQpigbj8+67/aRFs5AykXTjEzvys1XyDgRcZE3Iy7QBM NGPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3qjkeoBLWZp3W3G37t1lZY6yDIN2SCEN+Ps8suMIGCI=; b=28IPBd+U9Psf+QVDmRCWOkZ2fGp8TmtwiBXBVBJnJWzczshazCTh0FMTqYzvYPSQEa P330SjhYmzNL7yHp8pDpdqX8aMu8SF2uNutbKvIUshXN+G/cLJox+Zro4VLuFNTz2Vdd HGXQDpSRfPsq4L1cHJLZRz6DqD6/AO6J1qYhInt8XChjViXaWAugzjkSylcH01+GrmbI EGyDN84BP5nWr998KKqtlQT4h0h+/oAJ+BOgewM1IYinHf4DDxhFfHZeTPBkpT32OcaE lDXKwrFUiIaDXy575529AdWtGttXZIJc0v2fOrTN9W4GRinLMVENn+v711GAviBrkWrl L4/g== X-Gm-Message-State: AOAM532My/fwNQ3Te6HscfWtHDdHB+vYqHZ7dTG7JebmQltOHuUisl3b ksbYt7RrUd2GhNrjiwoaiX1I+zvsH63qDA== X-Google-Smtp-Source: ABdhPJwoSVCgl66m9AdBVRYZpLoKB7SG2HK9Pk0NwaHN55iDg3aB+dT5TTSbDQMqtaeJnGo5RR6G8g== X-Received: by 2002:a05:600c:3554:: with SMTP id i20mr7755070wmq.164.1631273415449; Fri, 10 Sep 2021 04:30:15 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id z6sm4103278wmp.1.2021.09.10.04.30.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 04:30:14 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Philip Oakley , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?q?SZEDER_G=C3=A1bor?= , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v2 1/5] help: correct the usage string in -h and documentation Date: Fri, 10 Sep 2021 13:28:42 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.873.g125ff7b9940 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Clarify the usage string in the documentation so we group e.g. -i and --info, and add the missing short options to the "-h" output. The alignment of the second line is off now, but will be fixed with another series of mine[1]. In the meantime let's just assume that fix will make it in eventually for the purposes of this patch, if it's misaligned for a bit it doesn't matter much. 1. https://lore.kernel.org/git/cover-0.2-00000000000-20210901T110917Z-avarab@gmail.com Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/git-help.txt | 2 +- builtin/help.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Documentation/git-help.txt b/Documentation/git-help.txt index 44fe8860b3f..568a0b606f3 100644 --- a/Documentation/git-help.txt +++ b/Documentation/git-help.txt @@ -9,7 +9,7 @@ SYNOPSIS -------- [verse] 'git help' [-a|--all [--[no-]verbose]] [-g|--guides] - [-i|--info|-m|--man|-w|--web] [COMMAND|GUIDE] + [[-i|--info] [-m|--man] [-w|--web]] [COMMAND|GUIDE] DESCRIPTION ----------- diff --git a/builtin/help.c b/builtin/help.c index b7eec06c3de..44ea2798cda 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -59,7 +59,8 @@ static struct option builtin_help_options[] = { }; static const char * const builtin_help_usage[] = { - N_("git help [--all] [--guides] [--man | --web | --info] []"), + N_("git help [-a|--all] [-g|--guides] [--[no-]verbose]]\n" + " [[-i|--info] [-m|--man] [-w|--web]] []"), NULL }; From patchwork Fri Sep 10 11:28:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12484953 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=-15.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,SPF_HELO_NONE,SPF_PASS,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 8A13CC4332F for ; Fri, 10 Sep 2021 11:30:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6DB876108B for ; Fri, 10 Sep 2021 11:30:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232803AbhIJLba (ORCPT ); Fri, 10 Sep 2021 07:31:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232537AbhIJLb3 (ORCPT ); Fri, 10 Sep 2021 07:31:29 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07231C061574 for ; Fri, 10 Sep 2021 04:30:18 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id w29so1388187wra.8 for ; Fri, 10 Sep 2021 04:30:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GFHyYbZ4py9YZZE41Kne8WFro2/2GS4PQhfF3G8sCYY=; b=HohC0wWwM6J1APEYsjAjx1pa1oGCKGZ4gkf0XaAZv6vN1agZcflgtFOcwKtdK0smYU nhRnthCxS2/h2475MANpJOBIrMbgmnuUHG9ELp3OWPFffVEt20JViV1GSBjY7a/Ktvs3 flY/KsO41LVoBjaiman0qY0+EZ1+/IO3nU5gBK6kd2tAOHuuWorXIu1Ha+74xMbwplsM BRDFQ2c+q+rWiZQ1JZygnrPZcsr6NKgpy8PR/Pxg6od3NucZk/hr4EC6YjApylb5gUBm i7UlHVw6LbADuYsY8rLnXQwVyUCBKFt0gh09fpMhecF3csUPWCf+KgTULBgTVhCliBH5 xjlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GFHyYbZ4py9YZZE41Kne8WFro2/2GS4PQhfF3G8sCYY=; b=lVhnZjTzd34ULBsNkDfxPpse5FmU2L8HBLZDlU9g+WQE425fnAn4QncnqWmuB6cOI4 SLVISXojaza4FsvgQV47uDFgqDd0N8AUvlpCLG6EnW0gOwj1auN3pifwWjUb2E80e7ey odCPw/d1NxsDr26DGTZNqtQl9k/S6MmbQ9tn6FsSOugtgNztydqTqNkEoMIpmrAfO5BL g6IiW2jUtGbtNFOxKkF+gfiocg1kdbUPyiGv7s6zmBq+2XNWN/2pydOQKpkOTZxXDVzH CrBphHrdTcrS7Q3xWjtr7u0HKKfIWVg8J3ynhXkPJkODoMdJ2Bjhno01WP5Q6o2WQts8 xSTA== X-Gm-Message-State: AOAM530ZJVSzny46I/hifnBR5cZQ1e9GxKOXifSXEPsAyN33ddv2v/vt zQH9ZN116UBkHx+pgZxeoWO8/TVU+kzcEQ== X-Google-Smtp-Source: ABdhPJyObKoEfDvMueCwFTtOn0PTXPnx5Tj0g90q1DK4Mb5o4a/DcKqaOlbFPMr6KUQR2X61ZjLiSQ== X-Received: by 2002:a5d:58c9:: with SMTP id o9mr8610666wrf.279.1631273416316; Fri, 10 Sep 2021 04:30:16 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id z6sm4103278wmp.1.2021.09.10.04.30.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 04:30:15 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Philip Oakley , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?q?SZEDER_G=C3=A1bor?= , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v2 2/5] help: correct usage & behavior of "git help --guides" Date: Fri, 10 Sep 2021 13:28:43 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.873.g125ff7b9940 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As noted in 65f98358c0c (builtin/help.c: add --guide option, 2013-04-02) and a133737b809 (doc: include --guide option description for "git help", 2013-04-02) which introduced the --guide option it cannot be combined with e.g. . Change both the usage string to reflect that, and test and assert for this behavior in the command itself. Now that we assert this in code we don't need to exhaustively describe the previous confusing behavior in the documentation either, instead of silently ignoring the provided argument we'll now error out. The comment being removed was added in 15f7d494380 (builtin/help.c: split "-a" processing into two, 2013-04-02). The "Ignore any remaining args" part of it is now no longer applicable as explained above, let's just remove it entirely, it's rather obvious that if we're returning we're done. Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/git-help.txt | 6 +++--- builtin/help.c | 11 +++++++---- t/t0012-help.sh | 4 ++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Documentation/git-help.txt b/Documentation/git-help.txt index 568a0b606f3..cb8e3d4da9e 100644 --- a/Documentation/git-help.txt +++ b/Documentation/git-help.txt @@ -8,8 +8,9 @@ git-help - Display help information about Git SYNOPSIS -------- [verse] -'git help' [-a|--all [--[no-]verbose]] [-g|--guides] +'git help' [-a|--all [--[no-]verbose]] [[-i|--info] [-m|--man] [-w|--web]] [COMMAND|GUIDE] +'git help' [-g|--guides] DESCRIPTION ----------- @@ -58,8 +59,7 @@ OPTIONS -g:: --guides:: - Prints a list of the Git concept guides on the standard output. This - option overrides any given command or guide name. + Prints a list of the Git concept guides on the standard output. -i:: --info:: diff --git a/builtin/help.c b/builtin/help.c index 44ea2798cda..51b18c291d8 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -59,8 +59,9 @@ static struct option builtin_help_options[] = { }; static const char * const builtin_help_usage[] = { - N_("git help [-a|--all] [-g|--guides] [--[no-]verbose]]\n" + N_("git help [-a|--all] [--[no-]verbose]]\n" " [[-i|--info] [-m|--man] [-w|--web]] []"), + N_("git help [-g|--guides]"), NULL }; @@ -552,6 +553,11 @@ int cmd_help(int argc, const char **argv, const char *prefix) builtin_help_usage, 0); parsed_help_format = help_format; + /* Options that take no further arguments */ + if (argc && show_guides) + usage_msg_opt(_("--guides cannot be combined with other options"), + builtin_help_usage, builtin_help_options); + if (show_all) { git_config(git_help_config, NULL); if (verbose) { @@ -582,9 +588,6 @@ int cmd_help(int argc, const char **argv, const char *prefix) if (show_all || show_guides) { printf("%s\n", _(git_more_info_string)); - /* - * We're done. Ignore any remaining args - */ return 0; } diff --git a/t/t0012-help.sh b/t/t0012-help.sh index 5679e29c624..c3aa016fd30 100755 --- a/t/t0012-help.sh +++ b/t/t0012-help.sh @@ -34,6 +34,10 @@ test_expect_success 'basic help commands' ' git help -a >/dev/null ' +test_expect_success 'invalid usage' ' + test_expect_code 129 git help -g git-add +' + test_expect_success "works for commands and guides by default" ' configure_help && git help status && From patchwork Fri Sep 10 11:28:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12484955 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=-15.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,SPF_HELO_NONE,SPF_PASS,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 2A91AC433F5 for ; Fri, 10 Sep 2021 11:30:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0EA9B61100 for ; Fri, 10 Sep 2021 11:30:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232824AbhIJLbb (ORCPT ); Fri, 10 Sep 2021 07:31:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232796AbhIJLb3 (ORCPT ); Fri, 10 Sep 2021 07:31:29 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9F32C061756 for ; Fri, 10 Sep 2021 04:30:18 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id j17-20020a05600c1c1100b002e754875260so1120475wms.4 for ; Fri, 10 Sep 2021 04:30:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QLj1FaGTL6kqpvAeFqjsjkt45ihlgB05mwo0ufGgBhI=; b=fSMrPIlXA1zQ5DenJQxLoJn8GC3Q/izK/N/DLau8RLwQDwyyCotUPYrAvXgospmlKb ZO+St6r1qIIgF0nKFbq6Mn+CrSNwttt42zLXQLyzIeU/fA32XSO6wx+Amb7XIfiwBJ3Q PVgm/xiGVsccbiay3Mbrohq7SZo2DKJ6+sGTILjEW9s8fCLb4GWOyocAxabSERhp7vbD z5oeraQhqYRSmTfsBxz8Ldc9AyqiTRs8uzAM0Nzl9ZmSML3r2UU2HDQ351HA4FDSoWp3 cKqvG66kjtAPtkC4aM+uOMLROAXNoCrSulELQtNL7tGVcuk2Dk14h3YeUkdznNVWUtYh m8tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QLj1FaGTL6kqpvAeFqjsjkt45ihlgB05mwo0ufGgBhI=; b=Kx0kgHU0eobZbC0NNUmaxffPJZJLmwitK5JmhzHgP1UWmO1QONmYjrYD0EOKwxJsPl FaSAXretHDiNOHs4vsXnYGs2zUOG1iSiNlsK3/KelA9/jVr91oTH8wRmE3xGrldZLgmQ 4nSiuy+HvrEH4jdNundSuVUVyH293iA+85YzcadU1+qAbwffukzJNqB3hsLb82+tnWMe 00BJB/6PAEWP1uz6s5q0F0v4vTxxwIFm32NZKJKag0dizU7omnf1IJ5cCSyK65bcX3Wp zRDmH1mRKnqfupymHXhs0EqY50/uODtQGb+q4V2m+i3oElUV9lFbBGdTpY68LEeACXfL 0jfw== X-Gm-Message-State: AOAM533Zq6cQyp/iPnT19yWlUWQBKUN1IHzJ2+dV0WYo2ZULRg7bzluQ lxPiWCxg1b9PtNRGh6MlNtq78uTFMAdlSg== X-Google-Smtp-Source: ABdhPJwLhL0EtqL/lyoj7/S1fUkXtfxSy+mgZNNs0PGyml9DJqEayuFJV2u3Os3QV0m9Pd1oj7CaNA== X-Received: by 2002:a1c:28a:: with SMTP id 132mr2421221wmc.101.1631273417166; Fri, 10 Sep 2021 04:30:17 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id z6sm4103278wmp.1.2021.09.10.04.30.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 04:30:16 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Philip Oakley , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?q?SZEDER_G=C3=A1bor?= , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v2 3/5] help tests: add test for --config output Date: Fri, 10 Sep 2021 13:28:44 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.873.g125ff7b9940 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a missing test for checking what the --config output added in ac68a93fd2 (help: add --config to list all available config, 2018-05-26) looks like. We should not be emitting anything except config variables and the brief usage information at the end here. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t0012-help.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/t/t0012-help.sh b/t/t0012-help.sh index c3aa016fd30..595bf81f133 100755 --- a/t/t0012-help.sh +++ b/t/t0012-help.sh @@ -77,6 +77,19 @@ test_expect_success 'git help -g' ' test_i18ngrep "^ tutorial " help.output ' +test_expect_success 'git help -c' ' + git help -c >help.output && + cat >expect <<-\EOF && + + '"'"'git help config'"'"' for more information + EOF + grep -v -E \ + -e "^[^.]+\.[^.]+$" \ + -e "^[^.]+\.[^.]+\.[^.]+$" \ + help.output >actual && + test_cmp expect actual +' + test_expect_success 'generate builtin list' ' git --list-cmds=builtins >builtins ' From patchwork Fri Sep 10 11:28:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12484957 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=-15.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,SPF_HELO_NONE,SPF_PASS,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 C3AA1C433EF for ; Fri, 10 Sep 2021 11:30:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A58C761100 for ; Fri, 10 Sep 2021 11:30:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232828AbhIJLbc (ORCPT ); Fri, 10 Sep 2021 07:31:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232817AbhIJLba (ORCPT ); Fri, 10 Sep 2021 07:31:30 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7918C061574 for ; Fri, 10 Sep 2021 04:30:19 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id w29so1388284wra.8 for ; Fri, 10 Sep 2021 04:30:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ptltSDCTtcLfQ+U8xcSudHvONAbaGZzTt/hw9/KbJ+s=; b=XvIsl8SMIA0lnVx/Y8LPtm7nbK+SBGYaU0bpcTmdQ/zZZqgku4pcog/yWRn3FdLae3 tR3H0OPca0KPSggxB28VVLUfAaAiNFWKCWgYnvkg4eMY+bz51LwFW8qdVQ7j+8Aw65dK IP1SAsYvhl2qGmgJPc18eTcUKpDii/mpT353S1b4Fz7b1rB16IUH6SzENz3qx02aCrqR qp1mXHx2OHX6YCP81kzLQdNOMcR0lIruEz241NxYXHdXGCEeBsRYnYKYrvTQj1ex9+9Z sulBtNNh756szAWCvi7BQWFdjVRhWmSbA4k1odcFNN1NwwKUkXdod/Dg17rRaCY9t94/ tDoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ptltSDCTtcLfQ+U8xcSudHvONAbaGZzTt/hw9/KbJ+s=; b=F3UIPABF+ETv7JV+kJhDrLvt4xDPRmOS4ZRshXKbhrIyn1xdtYfKipX3Sqj8JLMD6q xlMBlG+EKu4vXcz0fSAoR7ARFcT7+RfP0hvk6qO6Opsmq2A/2x/JvZYlcjaXViVxzdjo re3UHgTRhGl5eAcVQxtgY6h2ZgYUusChmTmas/2+cJgI/iNM0/6+tFpScrPhnqnUlh0R afpRtEgmcAwSaFMAuxcV5FNpA6qCtw+bEJv8LqbZT2uW0ssPQKOz2ayig7G+g9qwKW6U 17KA6w0Hnb1/6bLaB7MfMSlUB05mxqz3G08fhMLXS/vXh7Y/zrZEeB0X8yyA9ZxzrS4k 7MeA== X-Gm-Message-State: AOAM5331UOZsaQ930D9hW4RkF6lzD2hvraD5kil9CRloi7EbkgKcDj7m cc9kH9CXHkfh8d1SqnIG8gG+avnwlBrTjQ== X-Google-Smtp-Source: ABdhPJx0RCldQvd4QAyejieectHMUzkgLQqYUac9xentRUQrh55ptNz95kjbr+UVc9LuCMLODKtgfg== X-Received: by 2002:adf:906a:: with SMTP id h97mr903250wrh.220.1631273418062; Fri, 10 Sep 2021 04:30:18 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id z6sm4103278wmp.1.2021.09.10.04.30.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 04:30:17 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Philip Oakley , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?q?SZEDER_G=C3=A1bor?= , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v2 4/5] help: correct logic error in combining --all and --config Date: Fri, 10 Sep 2021 13:28:45 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.873.g125ff7b9940 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a bug in the --config option that's been there ever since its introduction in 3ac68a93fd2 (help: add --config to list all available config, 2018-05-26). Die when --all and --config are combined, combining them doesn't make sense. The code for the --config option when combined with an earlier refactoring done to support the --guide option in 65f98358c0c (builtin/help.c: add --guide option, 2013-04-02) would cause us to take the "--all" branch early and ignore the --config option. Let's instead list these as incompatible, both in the synopsis and help output, and enforce it in the code itself. Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/git-help.txt | 1 + builtin/help.c | 37 +++++++++++++++++++++++++++---------- t/t0012-help.sh | 7 ++++++- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Documentation/git-help.txt b/Documentation/git-help.txt index cb8e3d4da9e..96d5f598b4b 100644 --- a/Documentation/git-help.txt +++ b/Documentation/git-help.txt @@ -11,6 +11,7 @@ SYNOPSIS 'git help' [-a|--all [--[no-]verbose]] [[-i|--info] [-m|--man] [-w|--web]] [COMMAND|GUIDE] 'git help' [-g|--guides] +'git help' [-c|--config] DESCRIPTION ----------- diff --git a/builtin/help.c b/builtin/help.c index 51b18c291d8..05ba2cbe380 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -62,6 +62,7 @@ static const char * const builtin_help_usage[] = { N_("git help [-a|--all] [--[no-]verbose]]\n" " [[-i|--info] [-m|--man] [-w|--web]] []"), N_("git help [-g|--guides]"), + N_("git help [-c|--config]"), NULL }; @@ -548,18 +549,34 @@ int cmd_help(int argc, const char **argv, const char *prefix) int nongit; enum help_format parsed_help_format; const char *page; + int need_config = 0; argc = parse_options(argc, argv, prefix, builtin_help_options, builtin_help_usage, 0); parsed_help_format = help_format; + /* Incompatible options */ + if (show_all && show_config) + usage_msg_opt(_("--config and --all cannot be combined"), + builtin_help_usage, builtin_help_options); + + if (show_config && show_guides) + usage_msg_opt(_("--config and --guides cannot be combined"), + builtin_help_usage, builtin_help_options); + /* Options that take no further arguments */ + if (argc && show_config) + usage_msg_opt(_("--config cannot be combined with command or guide names"), + builtin_help_usage, builtin_help_options); if (argc && show_guides) - usage_msg_opt(_("--guides cannot be combined with other options"), + usage_msg_opt(_("--guides cannot be combined with command or guide names"), builtin_help_usage, builtin_help_options); - if (show_all) { + need_config = show_all || show_config; + if (need_config) git_config(git_help_config, NULL); + + if (show_all) { if (verbose) { setup_pager(); list_all_cmds_help(); @@ -570,6 +587,14 @@ int cmd_help(int argc, const char **argv, const char *prefix) list_commands(colopts, &main_cmds, &other_cmds); } + if (show_guides) + list_guides_help(); + + if (show_all || show_guides) { + printf("%s\n", _(git_more_info_string)); + return 0; + } + if (show_config) { int for_human = show_config == 1; @@ -583,14 +608,6 @@ int cmd_help(int argc, const char **argv, const char *prefix) return 0; } - if (show_guides) - list_guides_help(); - - if (show_all || show_guides) { - printf("%s\n", _(git_more_info_string)); - return 0; - } - if (!argv[0]) { printf(_("usage: %s%s"), _(git_usage_string), "\n\n"); list_common_cmds_help(); diff --git a/t/t0012-help.sh b/t/t0012-help.sh index 595bf81f133..cbc9b64f79f 100755 --- a/t/t0012-help.sh +++ b/t/t0012-help.sh @@ -35,7 +35,12 @@ test_expect_success 'basic help commands' ' ' test_expect_success 'invalid usage' ' - test_expect_code 129 git help -g git-add + test_expect_code 129 git help -g git-add && + test_expect_code 129 git help -c git-add && + test_expect_code 129 git help -g git-add && + + test_expect_code 129 git help -a -c && + test_expect_code 129 git help -g -c ' test_expect_success "works for commands and guides by default" ' From patchwork Fri Sep 10 11:28:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12484959 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=-15.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,SPF_HELO_NONE,SPF_PASS,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 43B6AC4332F for ; Fri, 10 Sep 2021 11:30:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 276E96108B for ; Fri, 10 Sep 2021 11:30:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232831AbhIJLbd (ORCPT ); Fri, 10 Sep 2021 07:31:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232825AbhIJLbb (ORCPT ); Fri, 10 Sep 2021 07:31:31 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95460C061574 for ; Fri, 10 Sep 2021 04:30:20 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id q11so2135133wrr.9 for ; Fri, 10 Sep 2021 04:30:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/eY1ueUYdEDuAGdyZGIHZ2CPeL/4O89ymJqXO+cYuZU=; b=dK1205fQsROTsMKl6Zfs4OUh4PDJ7Jz+q+ALHnpR8gU931iwjmTE/JSJfykJrVrfds +IJrRcttIx/Kv7tRM+/0WwgqsbowUO/mO9TIkviYvDGOKnTFbA3A+InZk31SZZKEx1Ov rQE2XLg72DFaBJUSs8bp99mCf3dgoDgOdlLBczLqptwihdb/8eSgmjlcgmUD9s+zm3h3 UVGaGrLeUeTyUrI5Ge09c14f2a4LrTY+IBFDGVnmDMGC8T50tZfwKJ9WIJEd3BejmU2m L/b2Zqso+HjdXAyJlJ8R7TMigvManYJYuGoSyFSpRV9eduIU9WjydBpwTEoXUNm6hZu/ rs7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/eY1ueUYdEDuAGdyZGIHZ2CPeL/4O89ymJqXO+cYuZU=; b=D/b7ISa4JQDybQnLNgs4t2Kv2rjwUTjbpLpJ6fJeLzD8YOTBAcH72VwH4hfw3vYLAd rr2EO87BHMKqUTLtw/IQt3NDmX+6bYBwxSRRoOEDBGWF3v8tMTpLkuHIzvr/QkiazM7U CrVtFeR1AiYCnsdfe05EDu1YXY9FmOWIZ9HHdfjTL8OEOt04/g/zGdhtNUu45m7DBJCJ 4MuH9yPZB2uCs3k7umglMwCN96HWUDhmT+rabCjSkdyeuHI5mQwfUicVGXjSYLIEG1g5 bjVH9lxc22zK/ukvoNfWYBhJnNqBkW+aH+9D8vsKasmdrLGZHivzqe9L/XI2xd5je9/c 5kKQ== X-Gm-Message-State: AOAM531LWKWpFbyqcDcpgwlqI2PxL53Of/88DZ5nVXAU5empYhNOk8Tt scrSr18/7CnexMGOhhCZx/DESBWf14grjQ== X-Google-Smtp-Source: ABdhPJyP8x8JUzyGFH0QtQ9ECgZU2FwWQ+hsW0lY+R7lmscpEiyM+erBVW1kx71K1XL2c3dHL5Gmcw== X-Received: by 2002:a05:6000:1569:: with SMTP id 9mr9165362wrz.343.1631273418818; Fri, 10 Sep 2021 04:30:18 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id z6sm4103278wmp.1.2021.09.10.04.30.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 04:30:18 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Philip Oakley , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmc=?= =?utf-8?b?4buNYyBEdXk=?= , =?utf-8?q?SZEDER_G=C3=A1bor?= , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v2 5/5] help / completion: make "git help" do the hard work Date: Fri, 10 Sep 2021 13:28:46 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.873.g125ff7b9940 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The "help" builtin has been able to emit configuration variables since e17ca926371 (completion: drop the hard coded list of config vars, 2018-05-26), but it hasn't produced exactly the format the completion script wanted. Let's do that. We got partway there in 2675ea1cc0f (completion: use 'sort -u' to deduplicate config variable names, 2019-08-13) and d9438873c4d (completion: deduplicate configuration sections, 2019-08-13), but after both we still needed some sorting, de-duplicating and awk post-processing of the list. We can instead simply do the relevant parsing ourselves (we were doing most of it already), and call string_list_remove_duplicates() after already sorting the list, so the caller doesn't need to invoke "sort -u". This changes the output of the section list to emit lines like "alias" instead of "alias.". The dot suffix is better done as an argument to __gitcomp(). This means that we'll have the list_config_help() function do a bit more work, let's switch its "for_human" to passing a full "show_config", but as an enum type so we can have the compiler check what values we're expecting to get. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/help.c | 67 ++++++++++++++++++-------- contrib/completion/git-completion.bash | 21 ++++---- t/t0012-help.sh | 24 +++++++++ 3 files changed, 81 insertions(+), 31 deletions(-) diff --git a/builtin/help.c b/builtin/help.c index 05ba2cbe380..9eb09d4804e 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -38,7 +38,12 @@ static const char *html_path; static int show_all = 0; static int show_guides = 0; -static int show_config; +enum show_config_type { + SHOW_CONFIG_UNSET = 0, + SHOW_CONFIG_HUMAN, + SHOW_CONFIG_VARS, + SHOW_CONFIG_SECTIONS, +} show_config; static int verbose = 1; static unsigned int colopts; static enum help_format help_format = HELP_FORMAT_NONE; @@ -48,7 +53,10 @@ static struct option builtin_help_options[] = { OPT_HIDDEN_BOOL(0, "exclude-guides", &exclude_guides, N_("exclude guides")), OPT_BOOL('g', "guides", &show_guides, N_("print list of useful guides")), OPT_BOOL('c', "config", &show_config, N_("print all configuration variable names")), - OPT_SET_INT_F(0, "config-for-completion", &show_config, "", 2, PARSE_OPT_HIDDEN), + OPT_SET_INT_F(0, "config-for-completion-vars", &show_config, "", + SHOW_CONFIG_VARS, PARSE_OPT_HIDDEN), + OPT_SET_INT_F(0, "config-for-completion-sections", &show_config, "", + SHOW_CONFIG_SECTIONS, PARSE_OPT_HIDDEN), OPT_SET_INT('m', "man", &help_format, N_("show man page"), HELP_FORMAT_MAN), OPT_SET_INT('w', "web", &help_format, N_("show manual in web browser"), HELP_FORMAT_WEB), @@ -73,7 +81,7 @@ struct slot_expansion { int found; }; -static void list_config_help(int for_human) +static void list_config_help(enum show_config_type type) { struct slot_expansion slot_expansions[] = { { "advice", "*", list_config_advices }, @@ -91,6 +99,8 @@ static void list_config_help(int for_human) const char **p; struct slot_expansion *e; struct string_list keys = STRING_LIST_INIT_DUP; + struct string_list keys_uniq = STRING_LIST_INIT_DUP; + struct string_list_item *item; int i; for (p = config_name_list; *p; p++) { @@ -121,34 +131,48 @@ static void list_config_help(int for_human) for (i = 0; i < keys.nr; i++) { const char *var = keys.items[i].string; const char *wildcard, *tag, *cut; + const char *dot = NULL; + struct strbuf sb = STRBUF_INIT; - if (for_human) { + switch (type) { + case SHOW_CONFIG_HUMAN: puts(var); continue; + case SHOW_CONFIG_SECTIONS: + dot = strchr(var, '.'); + break; + case SHOW_CONFIG_VARS: + break; + case SHOW_CONFIG_UNSET: + BUG("should not get SHOW_CONFIG_UNSET here"); } - wildcard = strchr(var, '*'); tag = strchr(var, '<'); - if (!wildcard && !tag) { - puts(var); + if (!dot && !wildcard && !tag) { + string_list_append(&keys_uniq, var); continue; } - if (wildcard && !tag) + if (dot) + cut = dot; + else if (wildcard && !tag) cut = wildcard; else if (!wildcard && tag) cut = tag; else cut = wildcard < tag ? wildcard : tag; - /* - * We may produce duplicates, but that's up to - * git-completion.bash to handle - */ - printf("%.*s\n", (int)(cut - var), var); + strbuf_add(&sb, var, cut - var); + string_list_append(&keys_uniq, sb.buf); + strbuf_release(&sb); + } string_list_clear(&keys, 0); + string_list_remove_duplicates(&keys_uniq, 0); + for_each_string_list_item(item, &keys_uniq) + puts(item->string); + string_list_clear(&keys_uniq, 0); } static enum help_format parse_help_format(const char *format) @@ -595,16 +619,19 @@ int cmd_help(int argc, const char **argv, const char *prefix) return 0; } - if (show_config) { - int for_human = show_config == 1; + switch (show_config) { + case SHOW_CONFIG_UNSET: + break; + case SHOW_CONFIG_VARS: + case SHOW_CONFIG_SECTIONS: + list_config_help(show_config); - if (!for_human) { - list_config_help(for_human); - return 0; - } + return 0; + case SHOW_CONFIG_HUMAN: setup_pager(); - list_config_help(for_human); + list_config_help(show_config); printf("\n%s\n", _("'git help config' for more information")); + return 0; } diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 8108eda1e86..19b8a172878 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2503,7 +2503,14 @@ __git_config_vars= __git_compute_config_vars () { test -n "$__git_config_vars" || - __git_config_vars="$(git help --config-for-completion | sort -u)" + __git_config_vars="$(git help --config-for-completion-vars)" +} + +__git_config_sections= +__git_compute_config_sections () +{ + test -n "$__git_config_sections" || + __git_config_sections="$(git help --config-for-completion-sections)" } # Completes possible values of various configuration variables. @@ -2717,16 +2724,8 @@ __git_complete_config_variable_name () __gitcomp "$__git_config_vars" "" "$cur_" "$sfx" ;; *) - __git_compute_config_vars - __gitcomp "$(echo "$__git_config_vars" | - awk -F . '{ - sections[$1] = 1 - } - END { - for (s in sections) - print s "." - } - ')" "" "$cur_" + __git_compute_config_sections + __gitcomp "$__git_config_sections" "" "$cur_" "." ;; esac } diff --git a/t/t0012-help.sh b/t/t0012-help.sh index cbc9b64f79f..4405eb6dde5 100755 --- a/t/t0012-help.sh +++ b/t/t0012-help.sh @@ -95,6 +95,30 @@ test_expect_success 'git help -c' ' test_cmp expect actual ' +test_expect_success 'git help --config-for-completion-vars' ' + git help -c >human && + grep -E \ + -e "^[^.]+\.[^.]+$" \ + -e "^[^.]+\.[^.]+\.[^.]+$" human | + sed -e "s/\*.*//" -e "s/<.*//" | + sort -u >human.munged && + + git help --config-for-completion-vars >vars && + test_cmp human.munged vars +' + +test_expect_success 'git help --config-for-completion-sections' ' + git help -c >human && + grep -E \ + -e "^[^.]+\.[^.]+$" \ + -e "^[^.]+\.[^.]+\.[^.]+$" human | + sed -e "s/\..*//" | + sort -u >human.munged && + + git help --config-for-completion-sections >sections && + test_cmp human.munged sections +' + test_expect_success 'generate builtin list' ' git --list-cmds=builtins >builtins '