From patchwork Tue Feb 8 11:21:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12738536 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D7D1C433EF for ; Tue, 8 Feb 2022 11:32:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376465AbiBHLca (ORCPT ); Tue, 8 Feb 2022 06:32:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357050AbiBHLV7 (ORCPT ); Tue, 8 Feb 2022 06:21:59 -0500 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 AC26CC03FEC9 for ; Tue, 8 Feb 2022 03:21:57 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id k3-20020a1ca103000000b0037bdea84f9cso1368525wme.1 for ; Tue, 08 Feb 2022 03:21:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=f4NL/D5bJHBH54sFIOk/5UVjCJf0p+Be5/HI96ORygQ=; b=TUV35y6lLGOylUn73e/ChxgFQYa3Aja7O2T6KHi5SlBb4nVSPcIs23LyFocIHajzN5 mGN2KNFFBCb+b2e4laM6xqPZ73ohQxW9x7V+xdegiyCFwyi5NLrpCNNTdJ5js+LpEOgJ GYoBC3YAdaTzewo+tco2ADleLO50OXidFgs+cSTnlCd/Ln+b64SwZ/NOTgVBC/LolNmR GCDWcJyBhTcGsi6edF1sy9zSDobjdtjq4sAemVTuby6wbGkQG/6KGMK7AFMPY8AMNJft gHyzFN9xk7yMi8EFsK0hq4rMq0mDO2jiXPznPOVeyzzCEqflVka8Z9RaB8payLVUOFbS 6Drw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=f4NL/D5bJHBH54sFIOk/5UVjCJf0p+Be5/HI96ORygQ=; b=D6DxbsbMJ/Uoq4Swchsf1BDtICNplSo7jb6IBTPfFCSjpRzgvGcc2j+AVERI6DA+TY FSai7aRr06WxmhExQ4KzDNgjrgP8xTmAov0JfEgPjco+o9hjSqn8gKV1MLcdBz1JpnSH z3ROql5yi1UHml8bHR2u8K5GQQfRpj+RwiLKb/+zhoaue901jZ3NgDOzMrpw4rNMcNPk HdHltRCU86kqL2EGKl6rXBhevgNyIbUSglFhJOS/ZuWfjN9BOTnR9rFCpUc9z0UBK6es vU9me26AsME1KDsc3o9+24yIewE4wRRt05L95kgFLXTjj5XFIK51BrxE/OlCWEqukUv4 nT1w== X-Gm-Message-State: AOAM530eS2uDM+x0mM3iNjo0fMLPLFHNMdpYNNDASBOvP+jNocn7o7PZ 6FReseqxPapJ5Kl/w+svwVQnEEzGtzY= X-Google-Smtp-Source: ABdhPJw8JPDkK5R++slFCW6uVnG/lA8TK4KX6sRugdCFZ2ZJM+74/8FcLW0wjak2jiv/qiX2DiLJOg== X-Received: by 2002:a05:600c:4e93:: with SMTP id f19mr683010wmq.195.1644319316130; Tue, 08 Feb 2022 03:21:56 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e9sm14339983wrg.60.2022.02.08.03.21.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:21:55 -0800 (PST) Message-Id: <6e9cdd10a70801da5124db1f55770d05c002671d.1644319314.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 08 Feb 2022 11:21:53 +0000 Subject: [PATCH v2 1/2] checkout/fetch/pull/pack-objects: allow `-h` outside a repository Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin When we taught these commands about the sparse index, we did not account for the fact that the `cmd_*()` functions _can_ be called without a gitdir, namely when `-h` is passed to show the usage. A plausible approach to address this is to move the `prepare_repo_settings()` calls right after the `parse_options()` calls: The latter will never return when it handles `-h`, and therefore it is safe to assume that we have a `gitdir` at that point, as long as the built-in is marked with the `RUN_SETUP` flag. However, it is unfortunately not that simple. In `cmd_pack_objects()`, for example, the repo settings need to be fully populated so that the command-line options `--sparse`/`--no-sparse` can override them, not the other way round. Therefore, we choose to imitate the strategy taken in `cmd_diff()`, where we simply do not bother to prepare and initialize the repo settings unless we have a `gitdir`. This fixes https://github.com/git-for-windows/git/issues/3688 Signed-off-by: Johannes Schindelin --- builtin/checkout.c | 7 ++++--- builtin/fetch.c | 6 ++++-- builtin/pack-objects.c | 8 +++++--- builtin/pull.c | 6 ++++-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index cc804ba8e1e..1c13d7fedb3 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1602,9 +1602,10 @@ static int checkout_main(int argc, const char **argv, const char *prefix, opts->show_progress = -1; git_config(git_checkout_config, opts); - - prepare_repo_settings(the_repository); - the_repository->settings.command_requires_full_index = 0; + if (the_repository->gitdir) { + prepare_repo_settings(the_repository); + the_repository->settings.command_requires_full_index = 0; + } opts->track = BRANCH_TRACK_UNSPECIFIED; diff --git a/builtin/fetch.c b/builtin/fetch.c index 5f06b21f8e9..c8ca4262de6 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -2014,8 +2014,10 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) } git_config(git_fetch_config, NULL); - prepare_repo_settings(the_repository); - the_repository->settings.command_requires_full_index = 0; + if (the_repository->gitdir) { + prepare_repo_settings(the_repository); + the_repository->settings.command_requires_full_index = 0; + } argc = parse_options(argc, argv, prefix, builtin_fetch_options, builtin_fetch_usage, 0); diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index ba2006f2212..87cb7b45c37 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3976,9 +3976,11 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) read_replace_refs = 0; sparse = git_env_bool("GIT_TEST_PACK_SPARSE", -1); - prepare_repo_settings(the_repository); - if (sparse < 0) - sparse = the_repository->settings.pack_use_sparse; + if (the_repository->gitdir) { + prepare_repo_settings(the_repository); + if (sparse < 0) + sparse = the_repository->settings.pack_use_sparse; + } reset_pack_idx_option(&pack_idx_opts); git_config(git_pack_config, NULL); diff --git a/builtin/pull.c b/builtin/pull.c index 100cbf9fb85..d15007d93f3 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -994,8 +994,10 @@ int cmd_pull(int argc, const char **argv, const char *prefix) set_reflog_message(argc, argv); git_config(git_pull_config, NULL); - prepare_repo_settings(the_repository); - the_repository->settings.command_requires_full_index = 0; + if (the_repository->gitdir) { + prepare_repo_settings(the_repository); + the_repository->settings.command_requires_full_index = 0; + } argc = parse_options(argc, argv, prefix, pull_options, pull_usage, 0); From patchwork Tue Feb 8 11:21:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12738535 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB885C433F5 for ; Tue, 8 Feb 2022 11:32:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376423AbiBHLcY (ORCPT ); Tue, 8 Feb 2022 06:32:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357061AbiBHLV7 (ORCPT ); Tue, 8 Feb 2022 06:21:59 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80074C03FECA for ; Tue, 8 Feb 2022 03:21:58 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id k18so30076147wrg.11 for ; Tue, 08 Feb 2022 03:21:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=onCw496qxEGIYlKeL4ualhEcXJGdOJoVv6Y9YtBgwOU=; b=gSBJotl09AWyxCtvvt5zVOWQRZEUf4E+7yeP3OgRuqeLKjNHGgaRzNx3lnvrmteWMd k/qtgrls27h01aixEWBOl2FXPwIPQNUWZoqi5z7B3CC/Hh23cq1H7whJic2SgGKymCO8 YgjQUHUt/wZY8EKC2jpTiwWdUrP+bmWpJuOv1MglIha2i2o6T7uhJk2ir0B2fFmpRIrq skjkxkilGdNq26fbQd7p+EONnCspX3OjDta1PTMd9beLcWjoEJEOjAKeBNyNqNly7FRO 3Bw6+z/BmAMttqJnc3isEOlrqPCxY0T1XxiCBCyIwrGDuNzN0msYoxqPM2OWGBZjxOnO efgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=onCw496qxEGIYlKeL4ualhEcXJGdOJoVv6Y9YtBgwOU=; b=0DwRecUfqmq5EQYU8v7ANT4CD4z6i4dxFPPJgJ3k4TsGVXvDA2B7avdYcbkKzChPRa sM7jWD5vrPaO8DksL30QelAsxSAN3LF+yjxZIsZkZhWcrYJYY+zPWiNcdx4+c/BKvmNk F28AfvrgiOyjO5vZxG6V3q+fyebvupFVd8+8YLRQOvKALIfNJPhKotdqpj7zA7YB6OHM pqJnZhyNJvnQXFtpfxtd9K3IQ2cdnRroaUaJGtXbpTr0Bg/d8r4+cEQp07Zzd+N3wrt+ 2WDpfFM5VfpLGpUMD49EEujqw22dmG9rG6LqkZ36IuiGDK8wEVJdkDXPgKxJqpunNwn8 4s6w== X-Gm-Message-State: AOAM531T/VEJXwW6jzrI3iUl7BUym7aPorEiXWJkaXqE6Ygrm1DrcFOo vIX5Rcqe7VuA+STuX97vCZ0DRx6AGT8= X-Google-Smtp-Source: ABdhPJxEsF1XwcltT6NyiXANh/SzoA6hnFYCaG7trt8lw7IODlKNhZyuRDVous1EHvhzh5UhnHvXJg== X-Received: by 2002:a05:6000:3c1:: with SMTP id b1mr3188318wrg.14.1644319316949; Tue, 08 Feb 2022 03:21:56 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j15sm2255158wmq.19.2022.02.08.03.21.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:21:56 -0800 (PST) Message-Id: <93df4a73dab44502eddfffd363622bf7016aaa4d.1644319314.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 08 Feb 2022 11:21:54 +0000 Subject: [PATCH v2 2/2] t0012: verify that built-ins handle `-h` even without gitdir Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin We just fixed a class of recently introduced bugs where calling, say, `git fetch -h` outside a repository would not show the usage but instead show an ugly `BUG` message. Let's verify that this does not regress anymore. Signed-off-by: Johannes Schindelin --- t/t0012-help.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/t/t0012-help.sh b/t/t0012-help.sh index 91b68c74a15..cbd725ccac8 100755 --- a/t/t0012-help.sh +++ b/t/t0012-help.sh @@ -139,13 +139,18 @@ test_expect_success 'git help --config-sections-for-completion' ' ' test_expect_success 'generate builtin list' ' + mkdir -p sub && git --list-cmds=builtins >builtins ' while read builtin do test_expect_success "$builtin can handle -h" ' - test_expect_code 129 git $builtin -h >output 2>&1 && + ( + GIT_CEILING_DIRECTORIES=$(pwd) && + export GIT_CEILING_DIRECTORIES && + test_expect_code 129 git -C sub $builtin -h >output 2>&1 + ) && test_i18ngrep usage output ' done