From patchwork Wed Mar 27 08:46:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13605958 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E60671E869 for ; Wed, 27 Mar 2024 08:46:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529217; cv=none; b=VMP5IiL8qwWBviyft8OVRd6MoBmyAkfYvopPqKM4lCNAec7/xSbp1eAUxaHMlVT94uT/xag8c7/U1fkuZf0d5NWEHiPMtTMjt6LHVrQDJN8lTUMZMPsokORcO84b1WyGfOKcU/ZFwaSRx1bvZ2nDtznIgGfj0OSl6xO/pKG89J0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529217; c=relaxed/simple; bh=Pn3cjL/fHExJa2XZDRCqYm6LqCZBITD6FL+h+avHmig=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OwNN8fjRBSiDDZzBxB3OAUSvdpXkpjd0EST9hhjWL8BFMJNQMhsC9PDJoUroNRIS1g1qQOunSDzBVEAHor+lfXB6ZO1RmwVums0HKoXtMmkEv+7VDlcwGu555BKabO+s134JPcdpLfZf1PCA2LOGI7dTlGnttaAsOp/wXedjjHI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=KGJyzwIa; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bWbvWj2m; arc=none smtp.client-ip=103.168.172.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="KGJyzwIa"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bWbvWj2m" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id F0DBB138015F; Wed, 27 Mar 2024 04:46:54 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 27 Mar 2024 04:46:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1711529214; x=1711615614; bh=JmOtyj9GKM dPQf3jgL3fNBI9u8HjlJb4gaDQwYp11Co=; b=KGJyzwIa+OqP0okxGkiMtxEqog 79MsuKpA8WemKXBntExxymZxAS5Ah5FASmv1B0vP0pJt24Sxa3SF0/Mpv+BVMOdV oiGeQv1MBQ2H7lQLlncPWtpLZuknjtrHxYFt39vr+PMgn0UGx8w85LNiviSLmaHX 1BXxGdrzive9puix5wMgW+KuC6JgPdQ2ocGcSVHrsls2T+8HmR8sEbNOlaSAtVj7 2/0pUcRZGAZXhd1OT0Qcg9BDS50lr36oxl8hvBmZN1D7HuPO151RjK9upbi2X4qc BXKpJ5djyBpxozj4jNvm00VziKlx5Zf2CdZIaTVHyQyTENZ4JoQGBzNLEUVg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1711529214; x=1711615614; bh=JmOtyj9GKMdPQf3jgL3fNBI9u8Hj lJb4gaDQwYp11Co=; b=bWbvWj2mPhI+Xog7IejNszv80B+FtxpL8MrP6Z4VOU4C VjJSjoJsjsqYqOqYWT96B3Jq8oExxWtyxMFzTrNIx4yT2zeNPUnAfpdq5dWoQix/ 5kuUuHJYLU/A33DoM882zC89Zerf6z4bPhE3BvfxwJ7pwwf/I7DjoVSni0QrmGVd irwJ1k7GLatoPyEnFP0H5GW93kdaUY8/c9/bmHOsYzQOt/n0LCqVL1B+ZVh+xZNs pL1m2G0fKbVEf3rVLfhW2kv1iNWDXBEwC6vz5V01Vj3tWjoNtXoCjEJTMcRCGwrs NFaezpjdmj/voX+eQ1HvfF1V/7Y9SWZqeZ6p0wXr4w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddugedguddvgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Mar 2024 04:46:53 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id e3f36a74 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 27 Mar 2024 08:46:39 +0000 (UTC) Date: Wed, 27 Mar 2024 09:46:51 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , Taylor Blau , =?iso-8859-1?q?Jean-No=EBl?= AVILA , Eric Sunshine , Junio C Hamano Subject: [PATCH v3 10/13] builtin/config: introduce "rename-section" subcommand Message-ID: <3e360b1f47864ebe738889fd46ea414829f8daf4.1711527812.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Introduce a new "rename-section" subcommand to git-config(1). Please refer to preceding commits regarding the motivation behind this change. Signed-off-by: Patrick Steinhardt --- Documentation/git-config.txt | 11 +++++++---- builtin/config.c | 32 ++++++++++++++++++++++++++++++++ t/t1300-config.sh | 22 +++++++++++----------- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 4fbc73a19e..0695eeae22 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -13,7 +13,7 @@ SYNOPSIS 'git config get' [] [] [--includes] [--all] [--regexp=] [--value=] [--fixed-value] [--default=] 'git config set' [] [--type=] [--all] [--value=] [--fixed-value] 'git config unset' [] [--all] [--value=] [--fixed-value] -'git config' [] --rename-section +'git config rename-section' [] 'git config' [] --remove-section 'git config' [] --get-colorbool [] 'git config' [] -e | --edit @@ -92,6 +92,9 @@ unset:: multi-valued config options, whereas `--value` will unset all config options whose values match the given pattern. +rename-section:: + Rename the given section to a new name. + [[OPTIONS]] OPTIONS ------- @@ -180,9 +183,6 @@ See also <>. --remove-section:: Remove the given section from the configuration file. ---rename-section:: - Rename the given section to a new name. - --fixed-value:: When used with the `value-pattern` argument, treat `value-pattern` as an exact string instead of a regular expression. This will restrict @@ -318,6 +318,9 @@ recommended to migrate to the new syntax. --unset-all []:: Replaced by `git config unset [--value=] --all `. +--rename-section :: + Replaced by `git config rename-section `. + CONFIGURATION ------------- `pager.config` is only respected when listing configuration, i.e., when diff --git a/builtin/config.c b/builtin/config.c index c53b68887e..99d9ac6341 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -20,6 +20,7 @@ static const char *const builtin_config_usage[] = { N_("git config get [] [] [--includes] [--all] [--regexp=] [--value=] [--fixed-value] [--default=] "), N_("git config set [] [--type=] [--all] [--value=] [--fixed-value] "), N_("git config unset [] [--all] [--value=] [--fixed-value] "), + N_("git config rename-section [] "), NULL }; @@ -43,6 +44,11 @@ static const char *const builtin_config_unset_usage[] = { NULL }; +static const char *const builtin_config_rename_section_usage[] = { + N_("git config rename-section [] "), + NULL +}; + static char *key; static regex_t *key_regexp; static const char *value_pattern; @@ -940,11 +946,37 @@ static int cmd_config_unset(int argc, const char **argv, const char *prefix) return git_config_set_in_file_gently(given_config_source.file, argv[0], NULL); } +static int cmd_config_rename_section(int argc, const char **argv, const char *prefix) +{ + struct option opts[] = { + CONFIG_LOCATION_OPTIONS, + OPT_END(), + }; + int ret; + + argc = parse_options(argc, argv, prefix, opts, builtin_config_rename_section_usage, + PARSE_OPT_STOP_AT_NON_OPTION); + check_write(); + check_argc(argc, 2, 2); + + handle_config_location(prefix); + + ret = git_config_rename_section_in_file(given_config_source.file, + argv[0], argv[1]); + if (ret < 0) + return ret; + else if (!ret) + die(_("no such section: %s"), argv[0]); + + return 0; +} + static struct option builtin_subcommand_options[] = { OPT_SUBCOMMAND("list", &subcommand, cmd_config_list), OPT_SUBCOMMAND("get", &subcommand, cmd_config_get), OPT_SUBCOMMAND("set", &subcommand, cmd_config_set), OPT_SUBCOMMAND("unset", &subcommand, cmd_config_unset), + OPT_SUBCOMMAND("rename-section", &subcommand, cmd_config_rename_section), OPT_END(), }; diff --git a/t/t1300-config.sh b/t/t1300-config.sh index c9610a1f5b..4818c495bd 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -589,7 +589,7 @@ weird EOF test_expect_success 'rename section' ' - git config --rename-section branch.eins branch.zwei + git config ${mode_prefix}rename-section branch.eins branch.zwei ' cat > expect << EOF @@ -608,7 +608,7 @@ test_expect_success 'rename succeeded' ' ' test_expect_success 'rename non-existing section' ' - test_must_fail git config --rename-section \ + test_must_fail git config ${mode_prefix}rename-section \ branch."world domination" branch.drei ' @@ -617,7 +617,7 @@ test_expect_success 'rename succeeded' ' ' test_expect_success 'rename another section' ' - git config --rename-section branch."1 234 blabl/a" branch.drei + git config ${mode_prefix}rename-section branch."1 234 blabl/a" branch.drei ' cat > expect << EOF @@ -640,7 +640,7 @@ cat >> .git/config << EOF EOF test_expect_success 'rename a section with a var on the same line' ' - git config --rename-section branch.vier branch.zwei + git config ${mode_prefix}rename-section branch.vier branch.zwei ' cat > expect << EOF @@ -661,11 +661,11 @@ test_expect_success 'rename succeeded' ' ' test_expect_success 'renaming empty section name is rejected' ' - test_must_fail git config --rename-section branch.zwei "" + test_must_fail git config ${mode_prefix}rename-section branch.zwei "" ' test_expect_success 'renaming to bogus section is rejected' ' - test_must_fail git config --rename-section branch.zwei "bogus name" + test_must_fail git config ${mode_prefix}rename-section branch.zwei "bogus name" ' test_expect_success 'renaming a section with a long line' ' @@ -674,7 +674,7 @@ test_expect_success 'renaming a section with a long line' ' printf " c = d %1024s [a] e = f\\n" " " && printf "[a] g = h\\n" } >y && - git config -f y --rename-section a xyz && + git config ${mode_prefix}rename-section -f y a xyz && test_must_fail git config -f y b.e ' @@ -684,7 +684,7 @@ test_expect_success 'renaming an embedded section with a long line' ' printf " c = d %1024s [a] [foo] e = f\\n" " " && printf "[a] g = h\\n" } >y && - git config -f y --rename-section a xyz && + git config ${mode_prefix}rename-section -f y a xyz && test_must_fail git config -f y foo.e ' @@ -694,7 +694,7 @@ test_expect_success 'renaming a section with an overly-long line' ' printf " c = d %525000s e" " " && printf "[a] g = h\\n" } >y && - test_must_fail git config -f y --rename-section a xyz 2>err && + test_must_fail git config ${mode_prefix}rename-section -f y a xyz 2>err && grep "refusing to work with overly long line in .y. on line 2" err ' @@ -1986,7 +1986,7 @@ test_expect_success POSIXPERM,PERL 'preserves existing permissions' ' git config imap.pass Hunter2 && perl -e \ "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" && - git config --rename-section imap pop && + git config ${mode_prefix}rename-section imap pop && perl -e \ "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600" ' @@ -2475,7 +2475,7 @@ test_expect_success 'refuse --fixed-value for incompatible actions' ' test_must_fail git config --file=config --fixed-value --add dev.null bogus && test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus && test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus && - test_must_fail git config --file=config --fixed-value --rename-section dev null && + test_must_fail git config ${mode_prefix}rename-section --file=config --fixed-value dev null && test_must_fail git config --file=config --fixed-value --remove-section dev && test_must_fail git config ${mode_prefix}list --file=config --fixed-value && test_must_fail git config --file=config --fixed-value --get-color dev.null &&