From patchwork Thu Apr 29 12:55:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 12231265 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,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 56BB6C43461 for ; Thu, 29 Apr 2021 12:53:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 20B5361423 for ; Thu, 29 Apr 2021 12:53:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237279AbhD2Myj (ORCPT ); Thu, 29 Apr 2021 08:54:39 -0400 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]:59997 "EHLO wout5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237260AbhD2Myh (ORCPT ); Thu, 29 Apr 2021 08:54:37 -0400 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 06C78167F; Thu, 29 Apr 2021 08:53:50 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 29 Apr 2021 08:53:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=g+dBJuXNgpnRiy3+xQWlDuNgQHX SgE7PqkDp9/gNfII=; b=UyZrtbpwk7w2x6K+5WNDyC/2r2GU3JS4z+X/8HlmthI z3g2nOvZu28y90MhbZ0yx+F2D/RBMImjhCn3rsaaMcHVrF7r92rkx6kXYf1TTOVg LbLLDlHCe2qOhdt6tWUjNSMvqHULBDdwpa6QMUZVY0PyDGI7N+04mOBN0SijTCxq 27c4Vn1KP06xFPQlt0nAWLOTuFqbeMNZk3UK57hWguDuUI7GMKRW5x4WLdDyUJBy 0iXW4ON8Mj9Vtu4Ime1LJ64eju9ZdeW0ueJh4JtdISIXcVJTfLj4OvLwAUJJtUmJ 7/aE71CIOsh7qS8H9yfP6NQ64QoQVJJvkTqzI+bkEPA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=g+dBJu XNgpnRiy3+xQWlDuNgQHXSgE7PqkDp9/gNfII=; b=TMjxlT7TbJb6kUz3JlN27X p1UeWQGj7exqPKfKKRUp6dmARw4IGUfgRIuWmDuE3A99kvg9Lb8C/yGqjeYD5Nqb 36C+A15XbYE1pN2uG0H/PMJP/CJtVlftZho9OsHOrbkf6GHaGhifhlqZVV8Dm7wX /yM9xqZe3cEp7lItj0aLz6C+JIWwYJXKhIhJiuRjOtjSy/K9KoukX/etADG11p/V o4GKwhTcu5MzsWeztrrwSgvvBY+njH8IR7Jc3lSQNikLRvRqcxXFvdn1jPZbFZOJ Sa4+2ebQXeDXMal1MO/ZpzzeYG+3DjaZe7If1jCzozDRB3R6kWXkP32e1+x7PIRA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvddvgedgheelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecukfhppeejkedrheehrdefgedrkeejnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrd himh X-ME-Proxy: Received: from vm-mail.pks.im (dynamic-078-055-034-087.78.55.pool.telefonica.de [78.55.34.87]) by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Apr 2021 08:53:49 -0400 (EDT) Received: from localhost (tanuki [10.192.0.23]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 2e9a5f11 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Apr 2021 12:53:49 +0000 (UTC) Date: Thu, 29 Apr 2021 14:55:34 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: =?iso-8859-1?q?=C6var_Arnfj=F6r=F0?= Bjarmason , Jeff King Subject: [PATCH v2 2/2] git: support separate arg for `--config-env`'s value Message-ID: <5264fb6fa7e05b55ab48d02265d8611536dc93f1.1619700731.git.ps@pks.im> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org While not documented as such, many of the top-level options like `--git-dir` and `--work-tree` support two syntaxes: they accept both an equals sign between option and its value, and they do support option and value as two separate arguments. The recently added `--config-env` option only supports the syntax with an equals sign. Mitigate this inconsistency by accepting both syntaxes and add tests to verify both work. Signed-off-by: Patrick Steinhardt --- git.c | 8 ++++++++ t/t1300-config.sh | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/git.c b/git.c index b53e665671..ad365c05c7 100644 --- a/git.c +++ b/git.c @@ -255,6 +255,14 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) git_config_push_parameter((*argv)[1]); (*argv)++; (*argc)--; + } else if (!strcmp(cmd, "--config-env")) { + if (*argc < 2) { + fprintf(stderr, _("no config key given for --config-env\n" )); + usage(git_usage_string); + } + git_config_push_env((*argv)[1]); + (*argv)++; + (*argc)--; } else if (skip_prefix(cmd, "--config-env=", &cmd)) { git_config_push_env(cmd); } else if (!strcmp(cmd, "--literal-pathspecs")) { diff --git a/t/t1300-config.sh b/t/t1300-config.sh index e0dd5d65ce..ad4e6d0cfc 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -1374,16 +1374,29 @@ test_expect_success 'git --config-env=key=envvar support' ' cat >expect <<-\EOF && value value + value + value + false false EOF { ENVVAR=value git --config-env=core.name=ENVVAR config core.name && + ENVVAR=value git --config-env core.name=ENVVAR config core.name && ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase && - ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag + ENVVAR=value git --config-env foo.CamelCase=ENVVAR config foo.camelcase && + ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag && + ENVVAR= git --config-env foo.flag=ENVVAR config --bool foo.flag } >actual && test_cmp expect actual ' +test_expect_success 'git --config-env with missing value' ' + test_must_fail env ENVVAR=value git --config-env 2>error && + grep "no config key given for --config-env" error && + test_must_fail env ENVVAR=value git --config-env config core.name 2>error && + grep "invalid config format: config" error +' + test_expect_success 'git --config-env fails with invalid parameters' ' test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error && test_i18ngrep "invalid config format: foo.flag" error &&